zoukankan      html  css  js  c++  java
  • c#游戏 剪刀石头

    电脑
    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace shitou { class diannao { public int chuanquan() { Random rd = new Random(); int num=rd.Next(1, 4); return num; } } }

      

    人
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace shitou
    {
        class ren
        {
            public int chuquan(string quanfa) 
            {
                switch (quanfa) 
                {
                    case "石头":
                        return 1;
                     
                    case "剪刀":
                        return 2;
                     
                    case "布":
                        return 3;
                        
                    default:
                        return 0;
    
                }
            }
        }
    }
    

      

    裁判
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace shitou
    {
        enum win
        {
            ren,diannao,ping
        }
        class caipan
        {
            /// <summary>
            /// 判断谁赢
            /// </summary>
            /// <param name="num1"></param>
            /// <param name="num2"></param>
            /// <param name="num3"></param>
            /// <returns></returns>
            public win judge(int num1, int num2) 
            {
                //switch (num1 - num2) 
                //{
                //    case -1:
                //        return win.ren;
                //        break;
                //    case 2:
                //        return win.ren;
                //        break;
                //}
                if (num1 - num2 == -1 || num1 - num2 == 2) 
                {
                    return win.ren;
                }
                else if (num1 == num2)
                {
                    return win.ping;
                }
                else {
                    return win.diannao;
                }
                
            }
        }
    }
    

      

    主代码
    
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace shitou
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string px = "石头";
                play(px);
                
                
                
                
            }
    
            private void play(string px)
            {
                
                ren p = new ren();
                int num1 = p.chuquan(px);
                diannao d = new diannao();
                int num2 = d.chuanquan();
                caipan a = new caipan();
                win re = a.judge(num1, num2);
                this.caipan1.Text = re.ToString();
                this.ren1.Text = px;
                if (num2 == 1)
                {
                    this.diannao1.Text = "石头";
                }
                else if (num2 == 2)
                {
                    this.diannao1.Text = "剪刀";
                }
                else
                {
                    this.diannao1.Text = "布";
                }
            }
    
           
        }
    }
    

      

  • 相关阅读:
    Rainmeter 雨滴桌面 主题分享
    行人检測之HOG特征(Histograms of Oriented Gradients)
    const和readonly差别
    ADB命令解析
    Java实现 蓝桥杯VIP 算法训练 接水问题
    Java实现 蓝桥杯VIP 算法训练 星际交流
    Java实现 蓝桥杯VIP 算法训练 星际交流
    Java实现 蓝桥杯VIP 算法训练 星际交流
    Java实现 蓝桥杯VIP 算法训练 星际交流
    Java实现 蓝桥杯VIP 算法训练 星际交流
  • 原文地址:https://www.cnblogs.com/mengluo/p/5473227.html
Copyright © 2011-2022 走看看