zoukankan      html  css  js  c++  java
  • 再练一遍猜拳

    namespace 再练一遍猜拳2
    {
        class Program
        {
            static void Main(string[] args)

    //首先先随机生成三个数,然后将0,1,2变成剪刀石头布,利用switch case达到,在比较的时候注意当x为0,y为2的时候,出x的获胜。即先判断这一句   x == 0 && y == 2 ,这句成立直接输出,因为后面的是||或者的意思;y获胜也一样,即先判断x == 2 && y == 0这一句,如果不成立再判断下一句。

    {
                Console.ForegroundColor = ConsoleColor.Green;            
                while (true)
                {
                    int x, y; string a,b;
                    Random r = new Random();
                    x = r.Next(0, 3);
                    y = r.Next(0, 3);
                    switch (x)
                    {
                        case 0:
                            a = "剪刀";
                            break;
                        case 1:
                            a = "石头";
                            break;
                        case 2:
                            a = "布";
                            break;
                        default:
                            a = "傻叉";
                            break;
                    }
                    switch (y)
                    {
                        case 0:
                            b = "剪刀";
                            break;
                        case 1:
                            b = "石头";
                            break;
                        case 2:
                            b = "布";
                            break;
                        default:
                            b = "傻叉";
                            break;
                    }
                    Console.WriteLine(a);
                    Console.WriteLine(b);
                    if (x > y)
                    {
                        if (x== 2 && y == 0)
                        {
                            Console.WriteLine("出" + b + "的获胜");
                        }
                        else
                        {
                            Console.WriteLine("出" + a + "的获胜");
                        }
                    }
                    else if (x < y)
                    {
                        if (x == 0 && y == 2)
                        {
                            Console.WriteLine("出" + a + "的获胜");
                        }
                        else
                        {
                            Console.WriteLine("出" + b + "的获胜");
                        }

                    }
                    else
                    {
                        Console.WriteLine("平局");
                    }
                    Console.ReadLine();
                }
            }
        }
    }


                 

  • 相关阅读:
    vimrc 配置 史上最牛
    nmap 黑客 端口扫描(转)
    linux export 命令(转)
    【引用】linux下编译静态库ranlib有什么用
    vim map nmap(转)
    vim 自定义命令 自定义快捷键(转)
    vimrc初学 vim 快捷键 map(转)
    vim 取消 查找 高亮
    Java内存模型(JMM)学习总结
    Struts2和Spring整合
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4372856.html
Copyright © 2011-2022 走看看