//项目为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;}
}
}
}
[
本帖最后由 icedkl 于 2012-9-24 00:54 编辑 ]