第1个回答 推荐于2018-05-13
using System;
namespace W23
{
class begin1 //定义一个begin1的类;//
{
public static void Main() //主函数//
{
int rock1=3; //rock代表石头//
int jian1=2; //jian 代表剪子//
int bu1=1; //bu代表布//
System.Random rnd=new System.Random();
string aj=Console.ReadLine();
int nbr=(int) rnd.Next(1,3); //随机数//
string rnd1=Convert.ToString(nbr); //将rnd的int转化为string//
string rock=Convert.ToString(rock1); //同上//
string jian=Convert.ToString(jian1); //同上//
string bu=Convert.ToString(bu1);
if ((rnd1==rock)&&(aj==bu)||(rnd1==jian)&&(aj==rock)||(rnd1==bu)&&(aj==jian))
{
Console.WriteLine("你胜利了!");
}
if ((rnd1==rock)&&(aj==jian)||(rnd1==jian)&&(aj==bu)||(rnd1==bu)&&(aj==rock))
{
Console.WriteLine("我出局了!");
}
if ((rnd1==rock)&&(aj==rock)||(rnd1==jian)&&(aj==jian)||(rnd1==bu)&&(aj==bu))
{
Console.WriteLine("我的我是平手!");
}
}
}
}本回答被提问者和网友采纳
第3个回答 2007-11-06
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = genBox();
if (label1.Text == "fist")
{
MessageBox.Show("you lose");
}
else if (label1.Text == "scissor")
{
MessageBox.Show("you draw");
}
else
{
MessageBox.Show("you win");
}
}
public string genBox()
{
string[] str ={ "fist", "scissor", "cloth" };
Random rnd = new Random();
int i = rnd.Next(0, 2);
return str[i];
}
private void fist_Click(object sender, EventArgs e)
{
label1.Text = genBox();
if (label1.Text == "fist")
{
MessageBox.Show("you draw");
}
else if (label1.Text == "scissor")
{
MessageBox.Show("you win");
}
else
{
MessageBox.Show("you lose");
}
}
private void cloth_Click(object sender, EventArgs e)
{
label1.Text = genBox();
if (label1.Text == "fist")
{
MessageBox.Show("you win");
}
else if (label1.Text == "scissor")
{
MessageBox.Show("you lose");
}
else
{
MessageBox.Show("you draw");
}
}
}
}