猜拳(石头剪刀布)

今天用winform做了个猜拳游戏。

拖完控件的摸样:

刚打开是的摸样:

 

 

随便选个出拳之后:

 

平的时候:

 

具体的代码:

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 练习3_猜拳
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /*************************系统出拳**********************************/

        private void textBox1_TextChanged(object sender, EventArgs e)
        {  
            string[] chuquanzhonglei = new string[3] { "石头", "剪刀", "布" };
            Random Roll = new Random();
            int roll = Roll.Next(0, 3);
            textBox2.Text = chuquanzhonglei[roll];
        }
        /*************************自己出拳**********************************/
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null) {
                textBox1.Clear();  
            }
            textBox1.Text = "石头";
            puanduan();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
            {
                textBox1.Clear();
            }
            textBox1.Text = "剪刀";
            puanduan();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
            {
                textBox1.Clear();
            }
            textBox1.Text = "布";
            puanduan();
        }

        /*************************判断胜负**********************************/
        public void puanduan() {
            if (textBox1.Text == "石头" && textBox2.Text == "剪刀")
            {
                pictureBox1.Image = Image.FromFile("胜.jpg");
                pictureBox2.Image = Image.FromFile("负.jpg");
            }
            else if (textBox1.Text == "剪刀" && textBox2.Text == "布")
            {
                pictureBox1.Image = Image.FromFile("胜.jpg");
                pictureBox2.Image = Image.FromFile("负.jpg");
            }
            else if (textBox1.Text == "布" && textBox2.Text == "石头")
            {
                pictureBox1.Image = Image.FromFile("胜.jpg");
                pictureBox2.Image = Image.FromFile("负.jpg");
            }
            else if (textBox1.Text == "布" && textBox2.Text == "布")
            {
                pictureBox1.Image = Image.FromFile("平.jpg");
                pictureBox2.Image = Image.FromFile("平.jpg");
            }
            else if (textBox1.Text == "石头" && textBox2.Text == "石头")
            {
                pictureBox1.Image = Image.FromFile("平.jpg");
                pictureBox2.Image = Image.FromFile("平.jpg");
            }
            else if (textBox1.Text == "剪刀" && textBox2.Text == "剪刀")
            {
                pictureBox1.Image = Image.FromFile("平.jpg");
                pictureBox2.Image = Image.FromFile("平.jpg");
            }
            else
            {
                pictureBox1.Image = Image.FromFile("负.jpg");
                pictureBox2.Image = Image.FromFile("胜.jpg");
            }
        }
    }
}

 

posted on 2012-09-10 17:19  gongth_12  阅读(180)  评论(0编辑  收藏  举报

导航