C# 面向过程 猜拳游戏

最近很爱学习,加上很早之前就想看看asp,因此去黑马去课堂看了下视频。
无聊的时候恰好看到老师在讲一个猜拳游戏,只是他用的是面向对象的思想,但是我以为面向对象那个有点麻烦了,因而下来本身写了记录一下。用的工具就是visual studio 2015html

1.新建一个项目 CaiQuanGame

选择windows窗体应用程序,把解决方案以及保存的位置这些都填好。web

2.设计界面

这里写图片描述

3.写按钮的点击事件要作的事情

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CaiQuanGame
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //1.随机生成computer的出拳,1-剪刀;2-石头;3-布
            Random random = new Random();
            int cNum = random.Next(1, 4);
            String cName="";
            switch (cNum) {
                case 1:
                    cName = "剪刀";
                    break;
                case 2:
                    cName = "石头";
                    break;
                case 3:
                    cName = "布";
                    break;
            }
            computer.Text = cName;


            //2.显示用户的出拳,1-剪刀;2-石头;3-布
            Button button = (Button)sender;
            int uNum=0;
            switch (button.Text){
                case "剪刀":
                    uNum = 1;
                    user.Text = "剪刀";
                    break;
                case "石头":
                    uNum = 2;
                    user.Text = "石头";
                    break;
                case "布":
                    uNum = 3;
                    user.Text = "布";
                    break;
            }

            //3.比较computer和用户的出拳并显示结果
            if ((cNum - uNum) == 1 || (cNum - uNum) == -2) {
                winresult.Text = "You Lose!";

            } else {
                winresult.Text = "You Win!";
            }         

        }

    }
}

备注:若是想学的话C#,黑马云课堂http://yun.itheima.com/map/52.html

免费还比较系统,绝对不是推荐,真心推荐!!!