// Start is called before the first frame update void Start() { tiles = new GameObject[hight, width]; reveald = new bool[hight, width]; flags = new bool[hight, width]; Vector3 pos = Vector3.zero; for (int i = 0; i < hight; i++) { for (int j = 0; j < width; j++) { pos.x = pos.x + size; tiles[i, j] = factory.MakeBlank(pos); tiles[i, j].name = "Tile_" + i + "_" + j; tiles[i, j].transform.SetParent(transform); } pos.y = pos.y - size; pos.x = pos.x - size * width; } pos.z = -5; pos.x = size * (width + 1) / 2; pos.y = -size * hight / 2; Camera.main.transform.position = pos; Camera.main.orthographicSize = (hight / 5) * cameraSizeIndex; mines = new Mines(width, hight, Mathf.FloorToInt(width * hight * minePercent)); OnFlagsCountChanged?.Invoke(flagCount); }
public void Restart() { reveald = new bool[hight, width]; flags = new bool[hight, width]; for (int i = 0; i < hight; i++) { for (int j = 0; j < width; j++) { factory.SetNormal(tiles[i, j].GetComponent <SpriteRenderer>()); } } mines = new Mines(width, hight, Mathf.FloorToInt(width * hight * 0.25f)); OnFlagsCountChanged?.Invoke(flagCount); }
public void SetFlag(int y, int x) { if (!reveald[y, x]) { if (flags[y, x]) { factory.SetNormal(tiles[y, x].GetComponent <SpriteRenderer>()); } else { factory.SetFlag(tiles[y, x].GetComponent <SpriteRenderer>()); } flagCount += flags[y, x] ? -1 : 1; flags[y, x] = !flags[y, x]; OnFlagsCountChanged?.Invoke(flagCount); } }