用C#编写一个猜拳的小游戏
4个回答
展开全部
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("我的我是平手!");
}
}
}
}
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("我的我是平手!");
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用个随机函数,然后判断一下,就完了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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");
}
}
}
}
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");
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是石头剪子布?
你得说清楚点儿,需要什么功能
你得说清楚点儿,需要什么功能
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询