Lights Out on a Pentagon Cairo Grid (Monster in the Closet)
This is a version of Lights Out on a Cairo Grid.
Note: You need the Unity Web Plugin to play this example.
PLAY GAME
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
public class LightsOutCairo: GLMonoBehaviour, IResetable { public SplicedCell cellPrefab; public GameObject root; private Vector2 cellDimensions = new Vector2(128+4, 128+4); private CairoGrid grid; private IMap3D map; private Color offColor = ExampleUtils.colors[4]; private Color onColor = ExampleUtils.colors[6]; public void Start() { Reset(); } public void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 worldPosition = ExampleUtils.ScreenToWorld_NGUI(root, Input.mousePosition); var gridPoint = map[worldPosition]; if (grid.Contains(gridPoint)) { ToggleCellAt(gridPoint); } } } public void Reset() { root.transform.DestroyChildren(); BuildGrid(); InitGame(); } private void BuildGrid() { grid = CairoGrid.Default(4, 6); map = new CairoMap(cellDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddelCenter(grid) .AnchorCellMiddelCenter() .To3DXY(); foreach (var point in grid) { SplicedCell cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.SetColor(offColor); cell.SetText(""); cell.SetOrientation(point.I); grid[point] = cell; } } private void InitGame() { //Initialiase with random pattern grid.SampleRandom(9).ForEach(ToggleCellAt); } private void ToggleCellAt(CairoPoint gridPoint) { foreach (var point in grid.GetNeighbors(gridPoint)) { grid[point].HighlightOn = !grid[point].HighlightOn; grid[point].SetColor(grid[point].HighlightOn ? onColor : offColor); } } } |