扫雷小游戏难点总结:
1 布雷的生成算法
2 难易度调节,离散空间数据靠近程度 <- 这部分基本没做
3 空白区域的递归算法(或队列的搜索)
4 输赢的判断
u3d上, ui为NGUI
代码 部分 ,写得比较乱 也懒得整理了
using UnityEngine;
using System.Collections;
using System;
public class SaoLei2 : MonoBehaviour
{
public GameObject gamePanel;
public GameObject ShowLable;
public GameObject _Qizi;
public GameObject _Chacha;
public GameObject ScoreLabel;
public int BoxWidth = 10;
public int BoxHeight = 10;
public int TwohengWidth = 50;
private int[,] BoxMatrix;
private Vector3 OriginPoint;//左下角原点
public GameObject[,] mQizi;
private int WinnerPlayer = 0;//1圈赢 -1叉赢
private int TotleBlock;//现在下的步骤0,0
private int TotleLandmine;//现在下的步骤0,0
private string scoreStr;
enum GameState
{
MyStep = 0,
ChaCha = 1,
GameOver,
}
GameState gameState = GameState.MyStep;
public int landmine = 10;
void Start()
{
TotleBlock = BoxHeight * BoxWidth ; //剩余的格子
TotleLandmine = landmine;//剩余的旗子
scoreStr = "left : " + TotleBlock + " landmine : " + TotleLandmine;
_Chacha.transform.localPosition = new Vector3(420,192,0);//new Vector3(Screen.width/2 +50 ,Screen.height/2 ,0);
//左上角为原点
OriginPoint = new Vector3(-(BoxWidth - 1) * 0.5f * TwohengWidth, -(BoxHeight - 1) * 0.5f * TwohengWidth, 0);
//儿子
BoxMatrix = new int[BoxHeight,BoxWidth];//0 表示空,1表示圈,-1表示叉
mQizi = new GameObject[BoxHeight,BoxWidth];
for (int i = 0; i < BoxHeight; i++)
{
for (int j = 0; j < BoxWidth; j++)
{
BoxMatrix[i, j] = 0;
mQizi[i, j] = Instantiate(_Qizi) as GameObject;
mQizi[i, j].name = "qizi_" + i + "_" + j;
mQizi[i, j].transform.parent = _Qizi.transform.parent;
mQizi[i, j].transform.localPosition = new Vector3(OriginPoint.x + (j) * TwohengWidth, OriginPoint.y + (i) * TwohengWidth, 0);
mQizi[i, j].transform.localScale = new Vector3(1, 1, 1);
}
}
_Qizi.transform.localPosition = new Vector3(-1000, 0, 0);
//构建一个雷区
//取得10个不重复的随机数
//landmine = 10;
//将2维展开成1维,
int[] ran