标签:
1.
int p = 1; int s1 = 0, shu1 = 0; while (true) { Random r = new Random(); int shu = r.Next(3); Console.WriteLine("0-包袱,1-剪刀,2-锤头"); Console.WriteLine("请输入0,1,2三个数中的任意一个数:"); int s = int.Parse(Console.ReadLine()); if (s == 0) { Console.WriteLine("你出包袱"); } if (s == 1) { Console.WriteLine("你出剪刀"); } if (s == 2) { Console.WriteLine("你出锤头"); } if (shu == 0) { Console.WriteLine("电脑出包袱"); } if (shu == 1) { Console.WriteLine("电脑出剪刀"); } if (shu == 2) { Console.WriteLine("电脑出锤头"); } if (s == shu) { Console.WriteLine("本局是平局"); } if ((s == 0 && shu == 2) || (s == 1 && shu == 0) || (s == 2 && shu == 1)) { Console.WriteLine("本局你赢了"); s1 = s1 + 1; } if ((shu == 0 && s == 2) || (shu == 1 && s == 0) || (shu == 2 && s == 1)) { Console.WriteLine("本局电脑赢了"); shu1 = shu1 + 1; } Console.WriteLine("比赛局数:" + p + "局"); p += 1; if (p == 4) { break; } Console.ReadLine(); } Console.ReadLine(); if (s1> shu1) { Console.WriteLine("恭喜你3局"+s1+"胜获得胜利"); } if (s1 <shu1) { Console.WriteLine("很遗憾你3局"+shu1+"败输给了电脑"); } if (s1== shu1) { Console.WriteLine("平局"); }
2.
int fenshu1=0,fenshu2=0; for (int i = 1; i <= 3; i++) { Random r = new Random(); int shu = r.Next(3); Console.WriteLine("0-包袱,1-剪刀,2-锤头"); Console.WriteLine("请输入0,1,2三个数中的任意一个数:"); int s = int.Parse(Console.ReadLine()); if (s == 0) { Console.WriteLine("你出包袱"); } if (s == 1) { Console.WriteLine("你出剪刀"); } if (s == 2) { Console.WriteLine("你出锤头"); } if (shu == 0) { Console.WriteLine("电脑出包袱"); } if (shu == 1) { Console.WriteLine("电脑出剪刀"); } if (shu == 2) { Console.WriteLine("电脑出锤头"); } if (s == shu) { Console.WriteLine("本局是平局"); } if ((s == 0 && shu == 2) || (s == 1 && shu == 0) || (s == 2 && shu == 1)) { Console.WriteLine("本局你赢了"); fenshu1 = fenshu1 + 1; } if ((shu == 0 && s == 2) || (shu == 1 && s == 0) || (shu == 2 && s == 1)) { Console.WriteLine("本局电脑赢了"); fenshu2 = fenshu2 + 1; } Console.ReadLine(); } if (fenshu1 > fenshu2) { Console.WriteLine("恭喜您获得胜利!"); } if (fenshu1 < fenshu2) { Console.WriteLine("很遗憾您输了!"); } if (fenshu1 == fenshu2) { Console.WriteLine("平局"); }
标签:
原文地址:http://www.cnblogs.com/wenwen123/p/5343082.html