void Start() { Transform newCell; CellScript myCellScript; myBoard = new GameOfLifeBoard(boardSize); timeForNextBoard = 0.25F; gamePlaying = true; for (int i = 0; i < boardSize; i++) // starts in bottom left corner goes right to left { for (int j = 0; j < boardSize; j++) // starts in bottom left corner goes bottom to top { // Create a new instance of the prefab. This creates a Transform, not a GameObject newCell = Instantiate(masterCell, new Vector3(i * 1.5F, j * 1.5F, 0.0F), Quaternion.identity) as Transform; // You get to a GameObject by accessing the Transform's GameObject property. // Once we have a GameObject, can call GetComponent to retrieve the CellScript component on it. // CellScript is the name of the class defined on the prefab. // This is how we get access to the script defined on the prefab. myCellScript = newCell.gameObject.GetComponent <CellScript>(); // Now that we have a reference to the script on the prefab (an instance of type of CellScript) // it is possible to call methods or directly set public variables. This is how we pass data // from the master initialization script into each grid cell's GameObject. myCellScript.SetRowCol(i, j); myCellScript.SetGameOfLifeBoard(myBoard); } } }
public void ShouldThrowIfBoardIsBelowMinimumSize() { gameOfLifeRuleMock.Setup(x => x.LifeStatusForNextTick(It.IsAny <DeadOrAliveNeighboursCount>(), It.IsAny <LifeStatus>())).Returns(LifeStatus.Alive); var gol = new GameOfLifeBoard(gameOfLifeRuleMock.Object); Assert.Throws <InvalidBoardSizeException>(() => gol.CreateNewBoard(2, 2)); }
public void ShouldThrowIfPlayIsCalledBeforeBoardCreated() { gameOfLifeRuleMock.Setup(x => x.LifeStatusForNextTick(It.IsAny <DeadOrAliveNeighboursCount>(), It.IsAny <LifeStatus>())).Returns(LifeStatus.Alive); var gol = new GameOfLifeBoard(gameOfLifeRuleMock.Object); Assert.Throws <BoardNotCreatedException>(() => gol.PlayGame(1, It.IsAny <Action <LifeStatus[, ]> >())); }
public void ShouldThrowIfSeedIsCalledBeforeBoardCreated() { gameOfLifeRuleMock.Setup(x => x.LifeStatusForNextTick(It.IsAny <DeadOrAliveNeighboursCount>(), It.IsAny <LifeStatus>())).Returns(LifeStatus.Alive); var gol = new GameOfLifeBoard(gameOfLifeRuleMock.Object); Assert.Throws <BoardNotCreatedException>(() => gol.Seed(new List <RowColumnLifeStatus>() { new RowColumnLifeStatus(-4, 4, LifeStatus.Alive) })); }
public void ShouldThrowErrorForInvalidSeedValues() { gameOfLifeRuleMock.Setup(x => x.LifeStatusForNextTick(It.IsAny <DeadOrAliveNeighboursCount>(), It.IsAny <LifeStatus>())).Returns(LifeStatus.Alive); var gol = new GameOfLifeBoard(gameOfLifeRuleMock.Object); gol.CreateNewBoard(4, 4); Assert.Throws <InvalidSeedException>(() => gol.Seed(new List <RowColumnLifeStatus>() { new RowColumnLifeStatus(-4, 4, LifeStatus.Alive) })); }
static void Main(string[] args) { random = new Random(); var gol = new GameOfLifeBoard(new GameOfLifeRules()); string[] rowsAndColumnsArray = GetRowsAndColumnsFromConsole(); int tickGenerations = GeTickGenerations(); List <RowColumnLifeStatus> seedList = GetSeed(RowFrom(rowsAndColumnsArray), ColumnFrom(rowsAndColumnsArray)); SetupAndPlayGameOfLife(gol, RowFrom(rowsAndColumnsArray), ColumnFrom(rowsAndColumnsArray), tickGenerations, seedList); }
private static void SetupAndPlayGameOfLife(GameOfLifeBoard gol, int rows, int columns, int tickGenerations, List <RowColumnLifeStatus> seedList) { var boardVisualizer = new ConsoleBoardOutput(); gol.CreateNewBoard(rows, columns); if (seedList.Any()) { gol.Seed(seedList); } gol.PlayGame(tickGenerations, boardVisualizer.Output); }
void InitializeBoard() { myBoard = new GameOfLifeBoard(boardSize); Transform newCell; CellScript myCellScript; for (int i = 0; i < boardSize; i++) // starts in bottom left corner goes right to left { for (int j = 0; j < boardSize; j++) // starts in bottom left corner goes bottom to top { // Create a new instance of the cell prefab newCell = Instantiate(masterCell, new Vector3(i * 1.5F, j * 1.5F, 0.0F), Quaternion.identity) as Transform; // Get a reference to the cells script myCellScript = newCell.gameObject.GetComponent <CellScript>(); // Set the row and col value for the cell myCellScript.SetRowCol(i, j); // Create the intitial board myCellScript.SetGameOfLifeBoard(myBoard); } } }
public void SetGameOfLifeBoard(GameOfLifeBoard myBoard) { this.myBoard = myBoard; }