| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 522 人关注过本帖
标题:C#问题,猜拳游戏。如何不经过按钮直接调用resul方法
只看楼主 加入收藏
A392502826
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-18
收藏
 问题点数:0 回复次数:0 
C#问题,猜拳游戏。如何不经过按钮直接调用resul方法
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Geam
{
    public partial class Game : Form
    {
        public Game()
        {
            InitializeComponent();
            
        }
        int sum;
        int shu;
        
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确定要退出?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
             {
                 this.Close();
             }
            
           
        }
        private void label1_Click(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            label6.Text = "石头";
            this.resul();
            if (label7.Text == "石头")
            {
                label5.Text = "平局";
            
            }
            else if (label7.Text == "剪刀")
            {
                label5.Text = "赢";
                sum += 1;
                label10.Text =""+sum;
            }
            else
            {
                label5.Text = "输";
                shu += 1;
                label9.Text = "" + shu;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
           
            label6.Text = "剪刀";
            this.resul();
            if (label7.Text == "石头")
            {
                label5.Text = "输";
                shu += 1;
                label9.Text = "" + shu;
            }
            else if (label7.Text == "剪刀")
            {
                label5.Text = "平局";
            }
            else
            {
                label5.Text = "赢";
                sum += 1;
                label10.Text = "" + sum;
                 
            }
            
            
           
        }
        private void button3_Click(object sender, EventArgs e)
        {
            
            label6.Text = "布";
            this.resul();
            if (label7.Text == "石头")
            {
                label5.Text = "赢";
                sum += 1;
                label10.Text = "" + sum;
            }
            else if (label7.Text == "剪刀")
            {
                label5.Text = "输";
                shu += 1;
                label9.Text = "" +shu;
            }
            else
            {
                label5.Text = "平局";
            }
        }
        private void resul()
        {
            if (sum + shu == 5)
            {
                if (sum > shu)
                {
                    MessageBox.Show("恭喜你,你赢了!", "提示", MessageBoxButtons.OK);
                    sum =0;
                    shu =0;
                    label9.Text = "";
                    label10.Text="";
                }
                else
                {
                    MessageBox.Show("很遗憾,你输了!", "提示", MessageBoxButtons.OK);
                    sum = 0;
                    shu =0;
                    label9.Text = "";
                    label10.Text = "";
   
                    
                }
            }

            int j;
            Random ran = new Random();
            j = ran.Next(3) + 1;
      
            if (j == 1)
            {
                label7.Text="石头";
            }
            else if(j==2)
            {
                label7.Text = "剪刀";
            }
            else
            {
         
               label7.Text = "布";
            }

        }
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f.Show();
        }
        private void label5_Click(object sender, EventArgs e)
        {
        }
        private void label10_Click(object sender, EventArgs e)
        {
        }

    }
}

搜索更多相关主题的帖子: 游戏 
2011-03-18 02:02
快速回复:C#问题,猜拳游戏。如何不经过按钮直接调用resul方法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016664 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved