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 = "布";
            }
        }

       
    }
}

  

转载于:https://www.cnblogs.com/mengluo/p/5473227.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值