最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實現(xiàn)石頭剪刀布游戲

 更新時間:2020年10月11日 17:05:37   作者:Handsome Wong  
這篇文章主要為大家詳細(xì)介紹了C#實現(xiàn)石頭剪刀布游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#實現(xiàn)石頭剪刀布的具體代碼,供大家參考,具體內(nèi)容如下

代碼

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 石頭剪刀布
{
 public partial class Form1 : Form
 {
  int computer_sorce = 0;
  int user_sorce = 0;
  int i=0,j = 0;
  int last_step = -1;//0表示平局,1為電腦上步加一,2為用戶上步加一
  public Form1()
  {
   InitializeComponent();
   this.Text = "石頭剪刀布";
   label3.Text = ":";
   label1.Visible = false;
   label2.Visible = false;
   label3.Visible = false;
   label4.Visible = false;
   button1.Text = "開始游戲";
   button2.Text = "重新開始";
   button3.Text = "悔棋";
   button4.Text = "退出";
   button2.Visible = false;
   button3.Visible = false; 
   button4.Visible = false;
   pictureBox2.Visible = false;
   pictureBox3.Visible = false;
   pictureBox3.Visible = false;
   pictureBox4.Visible = false;
   pictureBox5.Visible = false;
   pictureBox6.Visible = false;
   pictureBox7.Visible = false;
   pictureBox8.Visible = false;
   pictureBox9.Visible = false;
   pictureBox10.Visible =false;
   pictureBox11.Visible = false;
  }
  private void Form1_Load(object sender, EventArgs e)
  {

  }
  private void button1_Click(object sender, EventArgs e)
  {
   pictureBox1.Visible = false;
   button1.Visible = false;
   button1.Enabled = false;
   pictureBox2.Visible = true;
   pictureBox3.Visible = true;
   pictureBox4.Visible = true;
   pictureBox5.Visible = true;
   pictureBox6.Visible = true;
   pictureBox7.Visible = true;
   pictureBox8.Visible = true;
   pictureBox9.Visible = true;
   pictureBox10.Visible = true;
   pictureBox11.Visible = true;
   button2.Visible = true;
   button3.Visible = true;
   button4.Visible = true;
   
  }
  private void game_computer()
  {
   Random rand = new Random();
   i = rand.Next(4);
   if (i == 1)
   {
    pictureBox10.Load("..\\..\\picture\\1.jpg");
   }
   else if (i == 2)
   {
    pictureBox10.Load("..\\..\\picture\\2.jpg");
   }
   else if(i == 3)
   {
    pictureBox10.Load("..\\..\\picture\\3.jpg");
   }
  }
  private void game_judgment()
  {
   if (i == 1)//電腦出石頭
   {
    if (j == 1)
    {
     last_step = 0;
    }
    else if (j == 2)//用戶出剪刀
    {
     computer_sorce++;
     last_step = 1;
    }
    else if (j == 3)//用戶出布
    {
     user_sorce++;
     last_step = 2;
    }
   }
   else if (i == 2)//電腦出剪刀
   {
    if (j == 1)//用戶出石頭
    {
     user_sorce++;
     last_step = 2;
    }
    else if (j == 2)
    {
     last_step = 0;
    }
    else if (j == 3)//用戶出布
    {
     computer_sorce++;
     last_step = 1;
    }
   }
   else if (i == 3)//電腦出布
   {
    if (j == 1)//用戶出石頭
    {
     computer_sorce++;
     last_step = 1;
    }
    else if (j == 2)//用戶出剪刀
    {
     user_sorce++;
     last_step = 2;
    }
    else if (j == 3)
    {
     last_step = 0;
    }
   }
   if (computer_sorce == 2)//當(dāng)電腦分?jǐn)?shù)到2時,顯示you lose
   {
    label1.Visible = true;
    pictureBox7.Enabled = false;//結(jié)果出來后三個圖片按鈕失效
    pictureBox8.Enabled = false;
    pictureBox9.Enabled = false;
    label1.Text = "YOU LOSE!";
   }
   else if (user_sorce == 2)//當(dāng)用戶分?jǐn)?shù)到2時,顯示you win
   {
    label1.Visible = true;
    pictureBox7.Enabled = false;
    pictureBox8.Enabled = false;
    pictureBox9.Enabled = false;
    label1.Text = "YOU WIN!";
   }
  }
  private void button4_Click(object sender, EventArgs e)//退出按鈕
  {
   this.Close();
  }
  private void pictureBox7_Click(object sender, EventArgs e)//用戶石頭圖片
  {
   j = 1;
   pictureBox10.Visible = true;//劃拳圖片顯示正常
   pictureBox11.Visible = true;
   label2.Visible = true;//計分器三個label顯示
   label3.Visible = true;
   label4.Visible = true;
   game_computer();
   game_judgment();
   label2.Text = computer_sorce.ToString();
   label4.Text = user_sorce.ToString();
   pictureBox11.Load("D:\\newdesktop\\1.jpg");
  }
  private void pictureBox8_Click(object sender, EventArgs e)//用戶剪刀圖片
  {
   j = 2;
   pictureBox10.Visible = true;//劃拳圖片顯示正常
   pictureBox11.Visible = true;
   label2.Visible = true;//計分器三個label顯示
   label3.Visible = true;
   label4.Visible = true;
   game_computer();
   game_judgment();
   label2.Text = computer_sorce.ToString();
   label4.Text = user_sorce.ToString();
   pictureBox11.Load("D:\\newdesktop\\2.jpg");
  }
  private void pictureBox9_Click(object sender, EventArgs e)//用戶布圖片
  {
   j = 3;
   pictureBox10.Visible = true;//劃拳圖片顯示正常
   pictureBox11.Visible = true;
   label2.Visible = true;//計分器三個label顯示
   label3.Visible = true;
   label4.Visible = true;
   game_computer();
   game_judgment();
   label2.Text = computer_sorce.ToString();
   label4.Text = user_sorce.ToString();
   pictureBox11.Load("D:\\newdesktop\\3.jpg");
  }
  private void button2_Click(object sender, EventArgs e)
  {
   pictureBox7.Enabled = true;//重新開始后三個圖片按鈕生效
   pictureBox8.Enabled = true;
   pictureBox9.Enabled = true;
   i = 0;
   j = 0;
   computer_sorce = 0;
   user_sorce = 0;
   label2.Text = computer_sorce.ToString();
   label4.Text = user_sorce.ToString();
   pictureBox10.Visible = false;
   pictureBox11.Visible = false;
   label1.Visible = false;
   label2.Visible = false;
   label3.Visible = false;
   label4.Visible = false;
  }
  private void button3_Click(object sender, EventArgs e)
  {
   label1.Visible = false;
   pictureBox7.Enabled = true;
   pictureBox8.Enabled = true;
   pictureBox9.Enabled = true;
   pictureBox10.Visible = false;
   pictureBox11.Visible = false;
   if (last_step == 0)
   {
   }
   else if (last_step == 1)
   {
    computer_sorce--;
    label2.Text = computer_sorce.ToString();
    label4.Text = user_sorce.ToString();
   }
   else if (last_step == 2)
   {
    user_sorce--;
    label2.Text = computer_sorce.ToString();
    label4.Text = user_sorce.ToString();
   }
   last_step = -1;
  }
 }
}

效果圖

開始游戲

點擊開始

劃拳

判定勝敗


重新開始

悔棋


退出

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 在C#中發(fā)送自定義HTML格式郵件的示例詳解

    在C#中發(fā)送自定義HTML格式郵件的示例詳解

    在C#中發(fā)送自定義HTML格式郵件是一項常見的任務(wù),這在開發(fā)電子郵件營銷系統(tǒng)或任何需要通過電子郵件與用戶溝通的應(yīng)用程序中都非常重要,以下是如何在C#中發(fā)送自定義HTML格式郵件的詳解與示例,需要的朋友可以參考下
    2024-07-07
  • C#開發(fā)簡易winform計算器程序

    C#開發(fā)簡易winform計算器程序

    這篇文章主要為大家詳細(xì)介紹了C#開發(fā)簡易winform計算器程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • C#實現(xiàn)加密bat文件的示例詳解

    C#實現(xiàn)加密bat文件的示例詳解

    這篇文章主要為大家詳細(xì)介紹了C#如何實現(xiàn)加密bat文件的功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-01-01
  • c# xml API操作的小例子

    c# xml API操作的小例子

    這篇文章主要介紹了c# xml API操作的小例子,有需要的朋友可以參考一下
    2013-12-12
  • c#中單例類與靜態(tài)類的區(qū)別以及使用場景

    c#中單例類與靜態(tài)類的區(qū)別以及使用場景

    這篇文章主要給大家介紹了關(guān)于c#中單例類與靜態(tài)類的區(qū)別以及使用場景的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • C# 使用SHA1算法對密碼進(jìn)行加密

    C# 使用SHA1算法對密碼進(jìn)行加密

    這篇文章主要介紹了C# 使用SHA1算法對密碼進(jìn)行加密,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C#調(diào)用C類型dll入?yún)閟truct的問題詳解

    C#調(diào)用C類型dll入?yún)閟truct的問題詳解

    這篇文章主要給大家介紹了關(guān)于C#調(diào)用C類型dll入?yún)閟truct問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • c# this關(guān)鍵字用法代碼詳解

    c# this關(guān)鍵字用法代碼詳解

    在本篇文章里小編給大家整理的是關(guān)于c# this關(guān)鍵字用法以及相關(guān)實例代碼,有興趣的朋友們可以學(xué)習(xí)下。
    2020-02-02
  • C#設(shè)計模式實現(xiàn)之迭代器模式

    C#設(shè)計模式實現(xiàn)之迭代器模式

    迭代器模式把對象的職責(zé)分離,職責(zé)分離可以最大限度減少彼此之間的耦合程度,從而建立一個松耦合的對象,這篇文章主要給大家介紹了關(guān)于C#設(shè)計模式實現(xiàn)之迭代器模式的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • DevExpress實現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點

    DevExpress實現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點

    這篇文章主要介紹了DevExpress實現(xiàn)TreeList向上遞歸獲取符合條件的父節(jié)點,需要的朋友可以參考下
    2014-08-08

最新評論

台北县| 博湖县| 怀宁县| 界首市| 安溪县| 鹤壁市| 五莲县| 泰兴市| 夏邑县| 栾城县| 阿合奇县| 邵阳县| 石狮市| 唐海县| 西峡县| 凉山| 尚志市| 清苑县| 河津市| 阿图什市| 平武县| 邹城市| 平陆县| 合川市| 大同县| 射洪县| 翁源县| 铜川市| 安义县| 墨脱县| 姜堰市| 曲阜市| 双桥区| 阿合奇县| 法库县| 西平县| 凭祥市| 鹤壁市| 鄂尔多斯市| 瑞昌市| 玉田县|