精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網站建設資訊

NEWS

網站建設資訊

C#使用Unity實現剪刀石頭布游戲的方法

這篇文章主要講解了C#使用Unity實現剪刀石頭布游戲的方法,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。

站在用戶的角度思考問題,與客戶深入溝通,找到奇臺網站設計與奇臺網站推廣的解決方案,憑借多年的經驗,讓設計與互聯網技術結合,創造個性化、用戶體驗好的作品,建站類型包括:成都網站制作、網站建設、企業官網、英文網站、手機端網站、網站推廣、域名申請網站空間、企業郵箱。業務覆蓋奇臺地區。

游戲:剪刀石頭布

實現功能:

1、電腦隨機出牌(剪刀石頭布)

2、玩家選擇出牌(剪刀石頭布)

3、玩家沒有出牌時,電腦變幻牌面;

      玩家出牌后,電腦出牌,并停止變幻牌面3秒,期間玩家無法選擇出牌

4、玩家和電腦出牌后,電腦自動計分。

using UnityEngine;
using System.Collections;
 
public class hw0310a : MonoBehaviour {
 //
 public Rect windows1;
 public Rect windows2;
 public Rect btn1;
 public Rect btn2;
 public Rect btn3;
 public Rect box1;
 public Rect box2;
 public Rect label1;
 public Rect label2;
 public string str1;
 public string str2;
 public int score1;
 public int score2;
 public Texture[] texture;
 public int ComputerCp;
 public int PlayerCp;
 public GUISkin myskin;
 public bool notShowTime;
 public float MaxTime=3;
 void Start () {
 windows1=new Rect(100,240,400,120);
 windows2=new Rect(100,0,400,195);
 btn1=new Rect(40,20,80,80);
 btn2=new Rect(160,20,80,80);
 btn3=new Rect(280,20,80,80);
 box1=new Rect(50,30,100,100);
 box2=new Rect(250,30,100,100);
 label1 = new Rect (95, 150, 50, 50);
 label2 = new Rect (295, 150, 50, 50);
 score1 = 0;
 score2 = 0;
 str1 = score1.ToString ();//將int類型轉換為string類型,方便計分
 str2 = score2.ToString ();
 PlayerCp = 4;
 notShowTime = false;
 }
 
 // Update is called once per frame
 void Update () {
 str1 = score1.ToString ();
 str2 = score2.ToString ();

//控制電腦牌面的變幻條件和時間
 if (notShowTime==false) 
 {
 computerShow ();
 } 
 else 
 {
 MaxTime -= Time.deltaTime;
 if (MaxTime < 0)
 {
 notShowTime = false;
 MaxTime=3;
 }
 }
 }
 
 void computerShow(){
 if (ComputerCp < 2) {
 ComputerCp++;
 } else {
 ComputerCp = 0;
 }
 }
 void OnGUI()
 {
 windows1=GUI.Window (1, windows1, windowFun1, "Game");
 windows2=GUI.Window (2, windows2, windowFun2, "Computer VS Player");
 }
 
 void windowFun1(int Id)
 { //電腦牌面停止變幻時,玩家不能出牌
 if (GUI.Button (btn1, texture [0])) 
 {
 if(notShowTime==false)
 {
 PlayerCp=0;
 ComputerOut();//根據玩家的牌,電腦出牌,電腦永遠贏
 gameLogic();//判斷輸贏并計分
 }
 }
 
 if (GUI.Button (btn2, texture [1])) 
 {
 if(notShowTime==false)
 {
 PlayerCp=1;
 ComputerOut();
 gameLogic();
 }
 }
 
 if (GUI.Button (btn3, texture [2])) 
 {
 if(notShowTime==false)
 {
 PlayerCp=2;
 ComputerOut();
 gameLogic();
 }
 }
 
 
 GUI.DragWindow (new Rect(0,0,400,120));//括號內的矩形是可界面拖拽范圍
 }
 
 void windowFun2(int Id)
 {
// GUI.Button (b4, t4);
// GUI.Button (b5, t5);
 GUI.DragWindow (new Rect(0,0,400,195));
 
 GUI.Box (box1,texture[ComputerCp]);
 GUI.Box (box2,texture[PlayerCp]);
 
 GUI.Label (label1, str1);
 GUI.Label (label2, str2);
 }
 
 void ComputerOut()
 {
 notShowTime = true;
 int a=PlayerCp;
 int b = PlayerCp - 2;
 int c = PlayerCp + 1;
 if (PlayerCp == 2) 
 { //在確定的兩個數中選取隨機數的方法
 int[] Cp1 = new int[]{a,b};
 int i = Random.Range (0, 2);
 ComputerCp = Cp1[i];
 } 
 else 
 {
 int[] Cp2= new int[]{a,c};
 int i = Random.Range (0, 2);
 ComputerCp = Cp2[i];
 }
 // ComputerCp = Random.Range (0, 3);
 
 }
 
 
 void gameLogic()
 {
 int a = ComputerCp - PlayerCp;
 switch (a) 
 {
 case 0:Debug.Log ("pingju");break;
 case 1:
 case -2:
 {
 Debug.Log ("Player Lose");
 score1=score1+1;
 break;
 }
 case 2:
 case -1:
 {
 Debug.Log ("Player Win");
 score2=score2+1;
 break;
 }
 default:break;
 }
 
 }
}

C#使用Unity實現剪刀石頭布游戲的方法

看完上述內容,是不是對C#使用Unity實現剪刀石頭布游戲的方法有進一步的了解,如果還想學習更多內容,歡迎關注創新互聯行業資訊頻道。


新聞名稱:C#使用Unity實現剪刀石頭布游戲的方法
URL鏈接:http://m.jcarcd.cn/article/jhecjh.html
主站蜘蛛池模板: 青青在线国产精品 | 九色蝌蚪91| www黄在线观看 | 国产做爰一区二区 | 国产拍拍亚洲精品 | 福利国产精品 | 日本午夜专区一 | 日韩欧美激情 | 国产日韩影院在线 | 日韩v片在线 | 国产精品欧美中文 | 成人免费观看视频 | 成人午夜在线 | 日本在线成人 | 国产欧洲在线播放 | 国产视频网站在线 | 91免费短| 欧洲无线一线 | 成人黄人一级 | 国产日韩欧美大片 | 国产伦精品 | 国产精品高清尿小 | 国产主播剧情在线 | 欧洲一卡2 | 日韩一级视频免费 | 日韩高清电影 | 92在线精品 | 蜜桃91| 91综合在线 | 波多野结衣福利在线 | 日本高清无卡 | 日韩精品色色色色 | 精品国产高清自在 | 岛国岛国免费ⅴ片 | 麻花传剧mv在线看 | 精品动漫一区 | 国产凸凹视频熟女a | 国产福利观| 欧美一区三区 | 国产v综合v | 欧美性精品日韩在线 |