N是胜利局数
以下是引用icedkl在2012-9-24 00:51:48的发言:
//项目为window应用程序,添加控件主要有 textbox,label,button,代码如下:(好好学习!)
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
int x,y,n;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "石头")
{ y = 1; }
else
{
if (textBox1.Text.Trim() == "剪刀")
{y=2; }
else
{
if (textBox1.Text.Trim() == "步")
{ y = 3; }
else { MessageBox.Show("输入错误!"); }
}
}
Random m = new Random();
x = m.Next(3);
if (x == 1) { label1.Text = "石头"; }
else { if (x == 2) { label1.Text = "剪刀"; } else { label1.Text = "布"; } }
if(x==1&&y==1||x==2&&y==2||x==3&&y==3){MessageBox.Show("平局!");}
else
{
if(x==1&&y==2||x==2&&y==3||x==3&&y==1){MessageBox.Show("您输了!");}
else{MessageBox.Show("您赢了!");n++;}
}
if(n==3){MessageBox.Show("本局您获胜!");n=0;}
}
}
}
好像没考虑到电脑赢三局(你五局中输了三局),呵呵,这样大的BUG,电脑根本就赢了你!这样猜下去,即使运气再差,一万次不相信你赢不了三次!//项目为window应用程序,添加控件主要有 textbox,label,button,代码如下:(好好学习!)
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
int x,y,n;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "石头")
{ y = 1; }
else
{
if (textBox1.Text.Trim() == "剪刀")
{y=2; }
else
{
if (textBox1.Text.Trim() == "步")
{ y = 3; }
else { MessageBox.Show("输入错误!"); }
}
}
Random m = new Random();
x = m.Next(3);
if (x == 1) { label1.Text = "石头"; }
else { if (x == 2) { label1.Text = "剪刀"; } else { label1.Text = "布"; } }
if(x==1&&y==1||x==2&&y==2||x==3&&y==3){MessageBox.Show("平局!");}
else
{
if(x==1&&y==2||x==2&&y==3||x==3&&y==1){MessageBox.Show("您输了!");}
else{MessageBox.Show("您赢了!");n++;}
}
if(n==3){MessageBox.Show("本局您获胜!");n=0;}
}
}
}
[ 本帖最后由 smart0721 于 2012-10-19 17:46 编辑 ]