public GameBoardState Clone() { GameBoardState newGbs = new GameBoardState(this.levels, this.rows, this.cols); IGameBoardState igbs = this; for (int lvl = 0; lvl < (igbs.GetNumLevels()); lvl++) { for (int row = 0; row < (igbs.GetNumRows()); row++) { for (int col = 0; col < (igbs.GetNumCols()); col++) { ISpaceState iss = igbs.GetSpaceState(lvl, row, col); newGbs.spaces[lvl][row][col].occupied = iss.IsOccupied(); IPieceState ips = iss.Occupier(); if (ips != null) { PieceState ps = ips.CreatePieceState(); newGbs.spaces[lvl][row][col].occupier = ps; newGbs.AlivePieces.Add(ps); ps.space = newGbs.spaces[lvl][row][col]; } } } } foreach (IPieceState piece in DeadPieces) { newGbs.DeadPieces.Add(piece.CreatePieceState()); } return(newGbs); }
public void RenderBoard(IGameBoardState gameBoard) { int levels = gameBoard.GetNumLevels(); int rows = gameBoard.GetNumRows(); int cols = gameBoard.GetNumCols(); for (int i = 0; i < levels; i++) { for (int j = 0; j < rows; j++) { for (int k = 0; k < cols; k++) { Image img = squareLookup[i][j][k]; if (img != null) { if (gameBoard.GetSpaceState(i, j, k).IsOccupied()) { Piece.PieceType pieceType = gameBoard.GetSpaceState(i, j, k).Occupier().GetPieceType(); img.sprite = PieceSprites[pieceType]; img.color = gameBoard.GetSpaceState(i, j, k).Occupier().GetPieceTint(); img.Desaturate(); } else { img.sprite = BlankSprite; img.color = Color.white; } } else { Debug.Log("Error: image not found at index " + i + " " + j + " " + k); } } } } }