Пример #1
0
 // Shuffle the deck, deal two move cards to each player, and one to the board
 private void DealMoveCards()
 {
     this.deck.Shuffle();
     this.p1.GetCards().Add(this.deck.Deal());
     this.p1.GetCards().Add(this.deck.Deal());
     this.p2.GetCards().Add(this.deck.Deal());
     this.p2.GetCards().Add(this.deck.Deal());
     this.boardCard = this.deck.Deal();
 }
Пример #2
0
        // Main game logic flow - each loop represents one turn
        private void GameLoop(Player playerToMove, Player playerToMoveNext)
        {
            string winMessage = "";

            while (winMessage == "")
            {
                // Show current state of the game
                PrintGameState();
                Console.WriteLine(playerToMove.GetName() + " (" + playerToMove.GetSymbol().ToUpper() + ") to move");

                Pawn       pawnToMove        = null;
                MoveCard   moveCardToUse     = null;
                List <int> validDestinations = null;

                // Get from acting player: pawn to move, move card, move destination
                bool needInput = true;
                while (needInput)
                {
                    pawnToMove    = playerToMove.GetPawnToMove(this);
                    moveCardToUse = playerToMove.GetMoveCardToUse(this, playerToMove);

                    validDestinations = GetValidMoveDestinations(playerToMove, pawnToMove, moveCardToUse);
                    if (validDestinations.Count > 0)
                    {
                        needInput = false;
                    }
                    else
                    {
                        Console.WriteLine("Selected Pawn & Move Card combo has no valid moves!");
                    }
                }
                int pawnToMoveDestination = playerToMove.GetPawnToMoveDestination(this, validDestinations);

                Console.Write(playerToMove.GetName() + " (" + playerToMove.GetSymbol().ToUpper() + ") played " + moveCardToUse.GetName() + " - moved from " + pawnToMove.GetPos() + " to " + pawnToMoveDestination);

                // Update the position of the pawn being moved
                pawnToMove.SetPos(pawnToMoveDestination);

                // If a master pawn has been moved to the opponent's temple square, end the game (Way Of The Stream)
                if ((this.isP1Turn && pawnToMove.GetIsMaster() && pawnToMove.GetPos() == 2) || (!this.isP1Turn && pawnToMove.GetIsMaster() && pawnToMove.GetPos() == 22))
                {
                    winMessage = "Game Over! " + playerToMove.GetName() + " (" + playerToMove.GetSymbol().ToUpper() + ") wins by Way Of The Stream!";
                }

                // If an opponent pawn occupies the destination position, capture it
                foreach (Pawn pawn in playerToMoveNext.GetPawns())
                {
                    if (pawn.GetPos() == pawnToMove.GetPos())
                    {
                        pawn.SetIsCaptured(true);
                        Console.Write(" (captured pawn)");

                        // If the opponent's master pawn was captured, end the game (Way Of The Stone)
                        if (pawn.GetIsMaster())
                        {
                            winMessage = "Game Over! " + playerToMove.GetName() + " (" + playerToMove.GetSymbol().ToUpper() + ") wins by Way Of The Stone!";
                        }
                    }
                }
                Console.WriteLine();

                // Exchange used move card with board card
                MoveCard tempCard = moveCardToUse;
                playerToMove.GetCards().Remove(moveCardToUse);
                playerToMove.GetCards().Add(this.boardCard);
                this.boardCard = tempCard;

                // Swap player variables for next turn
                Player tempPlayer = playerToMoveNext;
                playerToMoveNext = playerToMove;
                playerToMove     = tempPlayer;
                this.isP1Turn    = !this.isP1Turn;
            }

            // Game Over
            PrintGameState();
            Console.WriteLine(winMessage);
        }
Пример #3
0
        // Return a list of valid move destinations based on the given player, pawn, and move card
        private List <int> GetValidMoveDestinations(Player playerToMove, Pawn pawnToMove, MoveCard moveCardToUse)
        {
            int        pawnInitialPos        = pawnToMove.GetPos();
            List <int> candidateDestinations = new List <int>();
            int        yFlip = this.isP1Turn ? -1 : 1;

            // Populate destinations list based on the selected move card
            for (int i = 0; i < moveCardToUse.GetMoveDeltas().Count; i++)
            {
                candidateDestinations.Add(pawnInitialPos + moveCardToUse.GetMoveDeltas()[i].GetDeltaX() + ((moveCardToUse.GetMoveDeltas()[i].GetDeltaY() * 5) * yFlip));
            }

            // Remove destinations that contain a friendly pawn
            for (int i = 0; i < playerToMove.GetPawns().Count; i++)
            {
                if (candidateDestinations.Contains(playerToMove.GetPawns()[i].GetPos()) && !playerToMove.GetPawns()[i].GetIsCaptured())
                {
                    candidateDestinations.Remove(playerToMove.GetPawns()[i].GetPos());
                }
            }

            // Remove destinations that are out of bounds
            List <int> validDestinations = ValidDestinationLookup(pawnInitialPos);
            List <int> finalDestinations = new List <int>();

            foreach (int dest in candidateDestinations)
            {
                if (validDestinations.Contains(dest))
                {
                    finalDestinations.Add(dest);
                }
            }

            return(finalDestinations);
        }