public Piece GetPiece(BoardGames.Players player) { switch (player) { case BoardGames.Players.One: return(piece1); case BoardGames.Players.Two: return(piece2); default: throw new NotImplementedException(player.ToString()); } }
public static BoardGames.Players Switched(this BoardGames.Players p) { switch (p) { case BoardGames.Players.One: return(BoardGames.Players.Two); case BoardGames.Players.Two: return(BoardGames.Players.One); default: throw new System.NotImplementedException(p.ToString()); } }
public override System.Collections.IEnumerator RunLogicCoroutine() { //Keep executing turns until the game ends. while (true) { //Update the UI based on whose turn it is. for (int i = 0; i < Consts.TextsForPlayers.Length; ++i) { foreach (SpriteRenderer sr in Consts.TextsForPlayers[i].Texts) { if ((int)CurrentPlayer == i) sr.color = Consts.TextsForPlayers[i].NormalColor; else sr.color = Consts.TextsForPlayers[i].NotMyTurnColor; } } //If there is no move for this player, he lost. List<Movement> moves = new List<Movement>(Board.Instance.GetMoves(Brd.GetPiece(CurrentPlayer))); if (moves.Count == 0) { StateMachine.Instance.CurrentState = new State_EndGame(NextPlayer); yield break; } //Wait until a move is queued up. Brd.GetPiece(NextPlayer).MyCollider.enabled = false; Brd.GetPiece(CurrentPlayer).MyCollider.enabled = true; while (toExecute == null) yield return null; //Execute the movement and switch turns. Board.Instance.ApplyMove(toExecute); CurrentPlayer = NextPlayer; toExecute = null; yield return new WaitForSeconds(Consts.MovePieceTime); } }
public State_PlayTurns(BoardGames.Players currentPlayer) { CurrentPlayer = currentPlayer; }
public State_EndGame(BoardGames.Players winner) { Winner = winner; }
public Piece(bool isKing, Vector2i pos, BoardGames.Players owner, Board theBoard) : base(pos, owner, theBoard) { IsKing = isKing; }
public Piece(Vector2i pos, BoardGames.Players owner, Board theBoard) : base(pos, owner, theBoard) { }
public override System.Collections.IEnumerator RunLogicCoroutine() { //Keep executing turns until the game ends. while (true) { //Update the UI based on whose turn it is. foreach (SpriteRenderer sr in Consts.AttackerTexts) sr.color = Consts.InitialAttackerTextColor; foreach (SpriteRenderer sr in Consts.DefenderTexts) sr.color = Consts.InitialDefenderTextColor; if (CurrentPlayer == Piece.Attackers) { foreach (SpriteRenderer sr in Consts.DefenderTexts) sr.color *= Consts.TurnColorMultiplier; } else { foreach (SpriteRenderer sr in Consts.AttackerTexts) sr.color *= Consts.TurnColorMultiplier; } //Wait until a move is queued up. while (moveToExecute == null) yield return null; //See if this move will end the game. bool endsGame = false; if (CurrentPlayer == Piece.Attackers) { //The attackers win if the king is captured. for (int i = 0; i < moveToExecute.Captures.Count; ++i) { if (moveToExecute.Captures[i].IsKing) { endsGame = true; break; } } } else { //The defenders win if the king escapes, or if not enough attackers will be left. if (moveToExecute.IsMoving.IsKing && (moveToExecute.Pos.x == 0 || moveToExecute.Pos.x == Board.BoardSize - 1 || moveToExecute.Pos.y == 0 || moveToExecute.Pos.y == Board.BoardSize - 1)) { endsGame = true; } else if (Brd.NAttackerPieces - moveToExecute.Captures.Count < 3) { endsGame = true; } } //Execute the movement and switch turns. Board.Instance.ApplyMove(moveToExecute); CurrentPlayer = (CurrentPlayer == Piece.Attackers ? Piece.Defenders : Piece.Attackers); moveToExecute = null; yield return new WaitForSeconds(Consts.MovePieceTime); //If that move won the game, then end the game. if (endsGame) { StateMachine.Instance.CurrentState = new State_EndGame(CurrentPlayer == Piece.Attackers ? Piece.Defenders : Piece.Attackers); yield break; } } }