private void UpdateState() { BoardSpaceState boardSpaceState = GameStateManager.Singleton.BoardSpaceStates[boardSpaceNumber]; foreach (Penguin penguin in _penguins) { penguin.gameObject.SetActive(false); } for (int i = 0; i < boardSpaceState.numberOfPenguins; i++) { _penguins[i].gameObject.SetActive(true); _penguins[i].transform.localPosition = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)); _penguins[i].transform.localRotation = Quaternion.Euler(0, Random.Range(0, 360), 0); } antarcticBase.SetActive(boardSpaceState.IsAntarcticBase); }
public static bool IsOpponent(BoardSpaceState piece) { return piece == BoardSpaceState.OpponentPieceShort || piece == BoardSpaceState.OpponentPieceTall; }
private async void updateCapturedPieces(StackPanel container, BoardSpaceState piece) { foreach (var _ in Enumerable.Range(0, game.GetCapturedCount(piece))) { container.Children.Add(new BoardSpace() { SpaceState = GameController.BoardSpaceStateFor(await getUser(), game, piece), Width = BOARD_GRID_SIDE_LENGTH, Height = BOARD_GRID_SIDE_LENGTH }); } }
// can these be defined on the enum itself? public static bool IsFriendly(BoardSpaceState piece) { return piece == BoardSpaceState.FriendlyPieceTall || piece == BoardSpaceState.FriendlyPieceShort; }
bool PlayerHasWon(BoardSpaceState playerMarker) { if (playerMarker == BoardSpaceState.None) { throw new Exception("This is not a player"); } for (int r = 0; r < BoardState.GetLength(0); r++) { bool victoryOnRow = true; for (int c = 0; c < BoardState.GetLength(1); c++) { if (BoardState[r, c] != playerMarker) { victoryOnRow = false; } } if (victoryOnRow) { return(true); } } for (int c = 0; c < BoardState.GetLength(0); c++) { bool victoryOnColumn = true; for (int r = 0; r < BoardState.GetLength(1); r++) { if (BoardState[r, c] != playerMarker) { victoryOnColumn = false; } } if (victoryOnColumn) { return(true); } } bool victoryOnDiagonalLR = true; for (int r = 0; r < BoardState.GetLength(0); r++) { if (BoardState[r, r] != playerMarker) { victoryOnDiagonalLR = false; } } if (victoryOnDiagonalLR) { return(true); } bool victoryOnDiagonalRL = true; for (int r = BoardState.GetLength(0) - 1; r >= 0; r--) { if (BoardState[r, BoardState.GetLength(0) - r - 1] != playerMarker) { victoryOnDiagonalRL = false; } } if (victoryOnDiagonalRL) { return(true); } return(false); }
public static BoardSpaceState BoardSpaceStateFor(User user, Game game, BoardSpaceState boardSpaceState) { return user.Email == game.InitiatingPlayerEmail ? boardSpaceState : boardSpaceState.TogglePlayer(); }
private static void fillTeam(Game game, int startRow, int nextRowOffset, BoardSpaceState shortPiece, BoardSpaceState tallPiece) { int nextRow = startRow + nextRowOffset; game.SetPieceLocation(new Coord() { Row = startRow, Col = 2 }, tallPiece); game.SetPieceLocation(new Coord() { Row = nextRow, Col = 3 }, tallPiece); game.SetPieceLocation(new Coord() { Row = startRow, Col = 9 }, tallPiece); game.SetPieceLocation(new Coord() { Row = nextRow, Col = 8 }, tallPiece); fillRow(game, shortPiece, startRow, 3, 8); fillRow(game, shortPiece, nextRow, 4, 7); }
private static void fillRow(Game game, BoardSpaceState toFill, int row, int lowerColBoundInclusive, int upperColBoundInclusive) { foreach (int col in Enumerable.Range(lowerColBoundInclusive, upperColBoundInclusive - lowerColBoundInclusive + 1)) { game.SetPieceLocation(new Coord() { Row = row, Col = col }, toFill); } }