最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Unity掃雷代碼存檔

2021-03-17 20:35 作者:劍士_尤吉歐  | 我要投稿


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;


public class Game_Mannage : MonoBehaviour

{

? ? //保存場景 雷 旗子 數(shù)字

? ? public List<GameObject> QiziObj;


? ? //位置 12*16 192--------------------------------

? ? public int[,] map_position_target; //map_position_target記錄map狀態(tài)? 0表示空 1表示雷? 2有數(shù)字

? ? public GameObject[] map_position_all;


? ? //遮罩?jǐn)?shù)組 12*16 192----------------------------------------

? ? public GameObject[,] mask_all;

? ? public GameObject mask;


? ? //旗子-----------------------------------------------

? ? public GameObject QiZi;

? ? public int QiZi_num=0;//插旗數(shù)==雷的數(shù)量時判斷輸贏

? ? public int[,] Qizi_table;//1已插旗?


? ? //雷-------------------------------------

? ? public GameObject lei;

? ? public int lei_number = 0;

? ? //雷概率 10-0

? ? public int gailv = 3;


? ? //數(shù)字-----------------------

? ? public GameObject[] number;

? ??

? ? //鼠標(biāo)射線點擊----------------------

? ? private RaycastHit2D rayhit;

? ? private double timeval = 0;


? ? //游戲狀態(tài)

? ? public bool gameover = false;

? ? public Text text_lei;

? ? public Text text_flag;

? ? public Text text_level;

? ? public GameObject winer;

? ? public GameObject loser;

? ? public GameObject gaming;


? ? // Start is called before the first frame update? 初始化

? ? void Start()

? ? {

? ? ? ? if(QiziObj!=null)

? ? ? ? ? ? ClearFlag();

? ? ? ? if(mask_all!=null)

? ? ? ? ? ? ClearMask();

? ? ? ? //初始化數(shù)據(jù)

? ? ? ? gaming.SetActive(true);

? ? ? ? winer.SetActive(false);

? ? ? ? loser.SetActive(false);

? ? ? ? gameover = false;

? ? ? ? QiZi_num = 0;

? ? ? ? lei_number = 0;

? ? ? ? map_position_target = new int[12, 16];

? ? ? ? mask_all = new GameObject[12, 16];

? ? ? ? Qizi_table= new int[12, 16];

? ? ? ? QiziObj = new List<GameObject>();

? ? ? ? //生成雷區(qū)/遮罩---------------用map_position_target記錄map狀態(tài)

? ? ? ? ReSetMap();


? ? ? ? //生成數(shù)字 標(biāo)記有數(shù)字 2

? ? ? ? ReSetNum();


? ? ? ? //生成遮罩 12*16

? ? ? ? ReSetMask();

? ? ? ? //雷u(yù)i數(shù)量初始化

? ? ? ? text_lei.text = lei_number.ToString();

? ? }


? ? private void FixedUpdate()

? ? {

? ? ? ? text_level.text = gailv.ToString();

? ? ? ? if (!gameover)

? ? ? ? {

? ? ? ? ? ? text_flag.text = QiZi_num.ToString();

? ? ? ? ? ? //排雷

? ? ? ? ? ? MouseHit();

? ? ? ? ? ? //用旗子標(biāo)記雷

? ? ? ? ? ? if (timeval < 0.5)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? TargetLei();

? ? ? ? ? ? }

? ? ? ? ? ? timeval -= Time.deltaTime;

? ? ? ? }

? ? }




? ? //生成雷區(qū)/map_position_target狀態(tài)--方法

? ? public void ReSetMap()

? ? {

? ? ? ? lei_number = 0;

? ? ? ? int hang = 0;

? ? ? ? int lie = 0;

? ? ? ? //遍歷所有位置

? ? ? ? for (int j = 0; j < 192; j++)

? ? ? ? {

? ? ? ? ? ? //概率生成雷不超過雷數(shù)量 圖層1

? ? ? ? ? ? if (Random.Range(0, 10) > 10 - gailv)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? //雷++生成雷

? ? ? ? ? ? ? ? lei_number++;

? ? ? ? ? ? ? ? QiziObj.Add(Instantiate(lei, map_position_all[j].transform.position, Quaternion.identity));

? ? ? ? ? ? ? ? //標(biāo)記1 有雷

? ? ? ? ? ? ? ? map_position_target[hang, lie] = 1;

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? //標(biāo)記0 無雷

? ? ? ? ? ? ? ? map_position_target[hang, lie] = 0;

? ? ? ? ? ? }

? ? ? ? ? ? //列大于15 歸0 行++

? ? ? ? ? ? if (lie >= 15)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? hang++;

? ? ? ? ? ? ? ? lie = 0;

? ? ? ? ? ? }

? ? ? ? ? ? //map列++

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? lie++;

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //生成數(shù)字方法 標(biāo)記有數(shù)字 2

? ? public void ReSetNum()

? ? {

? ? ? ? //遍歷所有target 位置 0 無雷 1有雷 二維? ? 2有數(shù)字

? ? ? ? int position_lei = 0;//obj雷 位置 一維數(shù)組

? ? ? ? for(int i = 0; i < 12; i++)

? ? ? ? {

? ? ? ? ? ? for(int j = 0; j < 16; j++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 0)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? //尋找周圍雷

? ? ? ? ? ? ? ? ? ? int num = SeachLei(i, j);

? ? ? ? ? ? ? ? ? ? if (num > 0)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? //生成數(shù)字

? ? ? ? ? ? ? ? ? ? ? ? QiziObj.Add(Instantiate(number[num - 1], map_position_all[position_lei].transform.position, Quaternion.identity));

? ? ? ? ? ? ? ? ? ? ? ? //標(biāo)記數(shù)字 2

? ? ? ? ? ? ? ? ? ? ? ? map_position_target[i, j] = 2;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? position_lei++;

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //在map position上生成 mask遮罩 編入 mask_all[12,16]

? ? public void ReSetMask()

? ? {

? ? ? ? int position=0;

? ? ? ? for(int i=0; i < 12; i++)

? ? ? ? {

? ? ? ? ? ? for(int j = 0; j < 16; j++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? mask_all[i,j]=Instantiate(mask, map_position_all[position].transform.position, Quaternion.identity);

? ? ? ? ? ? ? ? position++;

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //查詢周圍雷數(shù)量 1有雷,0無雷

? ? public int SeachLei(int x,int y)

? ? {

? ? ? ? int num=0;//雷數(shù)量

? ? ? ? int i, j;

? ? ? ? //水平方向-----------------

? ? ? ? {

? ? ? ? ? ? //向左

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i <= 0)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? i--;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? //向右

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i >= 11)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? i++;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? //垂直方向-----------------

? ? ? ? {

? ? ? ? ? ? //向上

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (j <= 0)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j--;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? //向下

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (j >= 15)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j++;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? //斜上方向-----------------

? ? ? ? {

? ? ? ? ? ? //i-? j+

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i <= 0 || j >= 15)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j++;

? ? ? ? ? ? ? ? i--;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? //i+? j-

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i >= 11 || j <= 0)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j--;

? ? ? ? ? ? ? ? i++;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? //斜下方向-----------------

? ? ? ? {

? ? ? ? ? ? //--

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i <= 0 || j<=0)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j--;

? ? ? ? ? ? ? ? i--;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? //++

? ? ? ? ? ? i = x;

? ? ? ? ? ? j = y;

? ? ? ? ? ? while (true)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (i >= 11 || j>=15)

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? j++;

? ? ? ? ? ? ? ? i++;

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? ? ? num++;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return num;

? ? }


? ? //點擊摧毀

? ? public void MouseHit()

? ? {

? ? ? ? if (Input.GetKey(KeyCode.Mouse0))//鼠標(biāo)左鍵點擊

? ? ? ? {

? ? ? ? ? ? rayhit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

? ? ? ? ? ? if (rayhit.collider != null)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (rayhit.collider.tag == "mask")

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Mask m = rayhit.collider.GetComponent<Mask>();

? ? ? ? ? ? ? ? ? ? //被點擊位置

? ? ? ? ? ? ? ? ? ? int x=-1, y=-1;

? ? ? ? ? ? ? ? ? ? for (int i = 0; i < 12; i++)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? for (int j = 0; j < 16; j++)

? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果找到被點擊的mask位置,進(jìn)行判斷是否需要展開空白區(qū)域

? ? ? ? ? ? ? ? ? ? ? ? ? ? if (mask_all[i, j] != null)

? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (mask_all[i, j].transform.position == m.transform.position)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x = i;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? y = j;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? if (x != -1 && y != -1)

? ? ? ? ? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? //摧毀

? ? ? ? ? ? ? ? ? ? m.Die();

? ? ? ? ? ? ? ? ? ? mask_all[x, y] = null;

? ? ? ? ? ? ? ? ? ? //如果點擊雷 游戲結(jié)束

? ? ? ? ? ? ? ? ? ? if (map_position_target[x, y] == 1)

? ? ? ? ? ? ? ? ? ? ? ? GameOver();

? ? ? ? ? ? ? ? ? ? //展開空白區(qū)域

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(x,y);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //展開空白區(qū)域 遞歸

? ? public void FindMapTarg_0(int x,int y)

? ? {

? ? ? ? //0為無雷空白? 向周圍展開

? ? ? ? if (map_position_target[x, y] == 0)

? ? ? ? {

? ? ? ? ? ? int up = x + 1;

? ? ? ? ? ? int down = x - 1;

? ? ? ? ? ? int right = y + 1;

? ? ? ? ? ? int left = y - 1;

? ? ? ? ? ? //摧毀垂直 水平

? ? ? ? ? ? if(up < 12)

? ? ? ? ? ? ? ? if (mask_all[up, y] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[up, y]);

? ? ? ? ? ? ? ? ? ? mask_all[up, y] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(up, y);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if(down >= 0)

? ? ? ? ? ? ? ? if (mask_all[down, y] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[down, y]);

? ? ? ? ? ? ? ? ? ? mask_all[down, y] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(down, y);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if (right < 16)

? ? ? ? ? ? ? ? if (mask_all[x, right] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[x, right]);

? ? ? ? ? ? ? ? ? ? mask_all[x, right] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(x, right);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if (left >= 0)

? ? ? ? ? ? ? ? if (mask_all[x, left] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[x, left]);

? ? ? ? ? ? ? ? ? ? mask_all[x, left] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(x, left);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? //摧毀斜方向

? ? ? ? ? ? if (up < 12 && right < 16)

? ? ? ? ? ? ? ? if (mask_all[up, right] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[up, right]);

? ? ? ? ? ? ? ? ? ? mask_all[up, right] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(up, right);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if (down >= 0 && right < 16)

? ? ? ? ? ? ? ? if (mask_all[down, right] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[down, right]);

? ? ? ? ? ? ? ? ? ? mask_all[down, right] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(down, right);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if (up < 12 && left >= 0)

? ? ? ? ? ? ? ? if (mask_all[up, left] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[up, left]);

? ? ? ? ? ? ? ? ? ? mask_all[up, left] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(up, left);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? if (down >= 0 && left >= 0)

? ? ? ? ? ? ? ? if (mask_all[down, left] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[down, left]);

? ? ? ? ? ? ? ? ? ? mask_all[down, left] = null;

? ? ? ? ? ? ? ? ? ? FindMapTarg_0(down, left);

? ? ? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //標(biāo)記雷/取消標(biāo)記

? ? public void TargetLei()

? ? {

? ? ? ? if (Input.GetKey(KeyCode.Mouse1))//鼠標(biāo)右鍵點擊 標(biāo)記雷

? ? ? ? {

? ? ? ? ? ? rayhit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

? ? ? ? ? ? if (rayhit.collider != null)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (rayhit.collider.tag == "mask")

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Mask m = rayhit.collider.GetComponent<Mask>();

? ? ? ? ? ? ? ? ? ? //生成旗子

? ? ? ? ? ? ? ? ? ? for (int i = 0; i < 12; i++)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? for (int j = 0; j < 16; j++)

? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果找到被點擊的mask位置,在此位置上插旗 無旗子

? ? ? ? ? ? ? ? ? ? ? ? ? ? if (mask_all[i, j] != null && Qizi_table[i, j] != 1)

? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (mask_all[i, j].transform.position == m.transform.position)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //插旗

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QiziObj.Add(Instantiate(QiZi, m.transform.position, Quaternion.identity));

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Qizi_table[i, j] = 1;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //旗子數(shù)++

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QiZi_num++;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //旗子數(shù)量是否達(dá)到雷的數(shù)量

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (QiZi_num >= lei_number)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? WinerOrLoser();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? //有旗子 取消插旗

? ? ? ? ? ? ? ? ? ? ? ? ? ? else if(mask_all[i, j] != null && Qizi_table[i, j] == 1)

? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (mask_all[i, j].transform.position == m.transform.position)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //取消插旗

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for(int index = 0; index < QiziObj.Count; index++)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (QiziObj[index].transform.position == mask_all[i, j].transform.position)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Destroy(QiziObj[index]);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QiziObj.Remove(QiziObj[index]);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Qizi_table[i, j] = 0;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //旗子數(shù)--

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QiZi_num--;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? timeval = 1;?

? ? ? ? }

? ? }


? ? //判斷掃雷是否正確

? ? public void WinerOrLoser()

? ? {

? ? ? ? //遍歷地圖狀態(tài)

? ? ? ? int flag = 0;

? ? ? ? for (int i = 0; i < 12; i++)

? ? ? ? {

? ? ? ? ? ? for (int j = 0; j < 16; j++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? //地圖標(biāo)記有雷

? ? ? ? ? ? ? ? if (map_position_target[i, j] == 1)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? //有旗子

? ? ? ? ? ? ? ? ? ? if (Qizi_table[i, j] == 1)

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? flag++;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? if(flag>=lei_number)

? ? ? ? ? ? GameWin();

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? GameOver();

? ? ? ? }

? ? }


? ? //除去全圖遮罩

? ? public void ClearMask()

? ? {

? ? ? ? for (int i = 0; i < 12; i++)

? ? ? ? {

? ? ? ? ? ? for (int j = 0; j < 16; j++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (mask_all[i, j] != null)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Destroy(mask_all[i, j]);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? }


? ? //清除 flag number lei

? ? public void ClearFlag()

? ? {

? ? ? ? for(int i = 0; i < QiziObj.Count; i++)

? ? ? ? {

? ? ? ? ? ? Destroy(QiziObj[i]);

? ? ? ? }

? ? }


? ? //結(jié)束方法

? ? public void GameOver()

? ? {

? ? ? ? ClearMask();

? ? ? ? print("Loser");

? ? ? ? gameover = true;

? ? ? ? gaming.SetActive(false);

? ? ? ? loser.SetActive(true);

? ? }


? ? //贏方法

? ? public void GameWin()

? ? {

? ? ? ? ClearMask();

? ? ? ? print("Winer");

? ? ? ? gameover = true;

? ? ? ? gaming.SetActive(false);

? ? ? ? winer.SetActive(true);

? ? }


? ? //重新開始游戲

? ? public void RestartGame()

? ? {

? ? ? ? Start();

? ? }


? ? //難度+

? ? public void Levelup()

? ? {

? ? ? ? if (gailv < 4)

? ? ? ? ? ? gailv += 1;

? ? }

? ? //難度-

? ? public void Leveldown()

? ? {

? ? ? ? if (gailv > 2)

? ? ? ? ? ? gailv -= 1;

? ? }

}


Unity掃雷代碼存檔的評論 (共 條)

分享到微博請遵守國家法律
泾川县| 涿州市| 库尔勒市| 陕西省| 信丰县| 姚安县| 东丽区| 勃利县| 修武县| 射洪县| 舟山市| 叙永县| 黔江区| 天全县| 江北区| 布拖县| 永新县| 沅江市| 苍梧县| 肃宁县| 桑日县| 万全县| 通州市| 如皋市| 樟树市| 郸城县| 五寨县| 雅安市| 大田县| 青浦区| 金昌市| 镇雄县| 红桥区| 马山县| 白沙| 鹤岗市| 明溪县| 玉树县| 辛集市| 台北县| 富平县|