コード例 #1
0
ファイル: Program.cs プロジェクト: kpartezana/projects
        private static List <Card> DealHand(Deck p1Deck,
                                            Deck p2Deck,
                                            List <Card> tableCards,
                                            WinningPlayer winningPlayer,
                                            string player1Name,
                                            string player2Name)
        {
            if (p1Deck.Count() > 0)
            {
                tableCards.Add(p1Deck.DealOne());
            }
            else
            {
                winningPlayer.Name = player2Name;
            }

            if (p2Deck.Count() > 0)
            {
                tableCards.Add(p2Deck.DealOne());
            }
            else
            {
                winningPlayer.Name = player1Name;
            }

            if ((p1Deck.Count() == 0) && (p2Deck.Count() == 0))
            {
                winningPlayer.Name = "Draw";
            }

            return(tableCards);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kpartezana/projects
        private static void GameIsOver(WinningPlayer winningPlayer)
        {
            Console.WriteLine();

            if (winningPlayer.Name != "Draw")
            {
                Console.WriteLine($"*** {winningPlayer.Name} Wins the game!");
            }
            else
            {
                Console.WriteLine($"*** This game is a Draw!");
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: kpartezana/projects
        private static List <Card> DealWar(Deck p1Deck,
                                           Deck p2Deck,
                                           List <Card> tableCards,
                                           int warDownCardCount,
                                           WinningPlayer winningPlayer,
                                           string player1Name,
                                           string player2Name)
        {
            for (int i = 1; i <= warDownCardCount + 1; i++)
            {
                if (p1Deck.Count() > 0)
                {
                    tableCards.Add(p1Deck.DealOne());
                }
                else
                {
                    winningPlayer.Name = player2Name;
                }

                if (p2Deck.Count() > 0)
                {
                    tableCards.Add(p2Deck.DealOne());
                }
                else
                {
                    winningPlayer.Name = player1Name;
                }

                if ((p1Deck.Count() == 0) && (p2Deck.Count() == 0))
                {
                    winningPlayer.Name = "Draw";
                }

                if (winningPlayer.Name != "")
                {
                    break;
                }
            }
            return(tableCards);
        }
コード例 #4
0
ファイル: Patchwork.cs プロジェクト: danzel/PatchworkSim
    public override int GetHashCode()
    {
        int hash = 1;

        if (GameHasEnded != false)
        {
            hash ^= GameHasEnded.GetHashCode();
        }
        if (WinningPlayer != 0)
        {
            hash ^= WinningPlayer.GetHashCode();
        }
        if (observation_ != null)
        {
            hash ^= Observation.GetHashCode();
        }
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
コード例 #5
0
        /// <summary>
        /// Runs the game set up.
        /// </summary>
        /// <param name="displayGame">Print the game board after each players move.</param>
        public void PlayGame(bool displayGame = false)
        {
            bool gameOver = false;

            while (!gameOver)
            {
                // Console.Clear();
                PlayNextMove();

                if (Board.IsFull())
                {
                    gameOver = true;
                    if (displayGame)
                    {
                        Console.WriteLine("Board is full");
                    }
                }
                else if (Board.HasConnectFour(_lastMove))
                {
                    gameOver = true;
                    Winner   = _playerOneNext ? WinningPlayer.PlayerTwoWins : WinningPlayer.PlayerOneWins;

                    if (displayGame)
                    {
                        var winningPlayer = Winner == WinningPlayer.PlayerOneWins ? "Player One" : "Player Two";
                        Console.WriteLine($"{winningPlayer} wins");
                    }
                }

                if (displayGame)
                {
                    Console.WriteLine(GetPrintedBoard());
                    Thread.Sleep(500);
                }
            }
        }
コード例 #6
0
 public void RaisePlayerWonPot(WinningPlayer player, MoneyPot pot, int amntWon)
 {
     PlayerWonPot(m_Game, new PotWonEventArgs(player, pot, amntWon));
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: kpartezana/projects
        static void Main(string[] args)
        {
            string    gameType;
            string    gameTypeTitle;
            string    player1Name;
            string    player2Name;
            int       warDownCardCount;
            int       rankDownCardCount;
            int       p1HandsWon    = 0;
            int       p1WarsWon     = 0;
            int       p2HandsWon    = 0;
            int       p2WarsWon     = 0;
            int       handsPlayed   = 0;
            bool      isGameOver    = false;
            const int startingCards = 26;

            WinningPlayer winningPlayer = new WinningPlayer();

            while (true) // Game loop
            {
                // Print title screen
                PrintTitleScreen();

                // Print instruction screen 1 then 2 and get game type
                PrintInstructions1();
                const string validGameTypes = "123q";
                gameType = PrintInstructions2();
                while (!validGameTypes.Contains(gameType))
                {
                    gameType = PrintInstructions2();
                }
                if (gameType == "q")
                {
                    break;
                }
                gameTypeTitle     = GetGameTypeTitle(gameType);
                warDownCardCount  = GetWarCount(gameType);
                rankDownCardCount = warDownCardCount;

                // Get player names
                string[] bothPlayers = PlayerInput().Split(",");
                player1Name = bothPlayers[0];
                player2Name = bothPlayers[1];
                int namePad = Math.Max(player1Name.Length, player2Name.Length) + 1;

                // Create and shuffle deck
                Deck fullDeck = new Deck("full");
                fullDeck.Shuffle();

                // Deal the starting cards
                Deck p1Deck = new Deck("");
                Deck p2Deck = new Deck("");

                for (int i = 1; i <= startingCards; i++)
                {
                    p1Deck.AddOne(fullDeck.DealOne());
                    p2Deck.AddOne(fullDeck.DealOne());
                }

                // Play game till it's over or they ask to quit
                string eachHandEntry = "";
                while ((eachHandEntry != "q") && (isGameOver == false)) // Deal Loop
                {
                    PrintTitleLine(gameTypeTitle);
                    DisplayGameStats(player1Name,
                                     p1Deck.Count(),
                                     p1HandsWon,
                                     p1WarsWon,
                                     player2Name,
                                     p2Deck.Count(),
                                     p2HandsWon,
                                     p2WarsWon,
                                     handsPlayed,
                                     namePad);

                    // Play hand / ask for deal count
                    eachHandEntry = GetDealCount();

                    List <Card> tableCards = new List <Card>();           // List to hold cards on table
                    int         compareIndex;                             // Index of first card to compare in List of tableCards

                    if (Int32.TryParse(eachHandEntry, out int dealCount)) // Play dealCount number of hands if not 'q'
                    {
                        for (int i = 1; i <= dealCount; i++)              // Hand loop
                        {
                            // Play a number of hands
                            tableCards = DealHand(p1Deck, p2Deck, tableCards, winningPlayer, player1Name, player2Name);
                            if (winningPlayer.Name != "")
                            {
                                isGameOver = true;
                                break;
                            }
                            // handsPlayed++; // Used here, will count Wars as hands
                            compareIndex = 0;
                            PrintTitleLine(gameTypeTitle); // Print title
                            DisplayGameStats(player1Name,
                                             p1Deck.Count(),
                                             p1HandsWon,
                                             p1WarsWon,
                                             player2Name,
                                             p2Deck.Count(),
                                             p2HandsWon,
                                             p2WarsWon,
                                             handsPlayed,
                                             namePad);                                               // Print game stats
                            DisplayHand(tableCards, handsPlayed, player1Name, player2Name, namePad); // Display the hand in progress


                            int compareResult = CardCompare(tableCards, compareIndex);
                            if (compareResult > 0) // Player 1 win
                            {
                                PlayerWin(p1Deck, tableCards);
                                p1HandsWon++;
                                // Console.WriteLine();
                                Console.WriteLine($"{player1Name} Wins the hand!");
                                System.Threading.Thread.Sleep(2000);
                            }
                            else if (compareResult < 0) // Player 2 win
                            {
                                PlayerWin(p2Deck, tableCards);
                                p2HandsWon++;
                                // Console.WriteLine();
                                Console.WriteLine($"{player2Name} Wins the hand!");
                                System.Threading.Thread.Sleep(2000);
                            }
                            else // War
                            {
                                int warCount = 0;
                                compareIndex = 0;
                                while (true) // War loop
                                {
                                    if (warDownCardCount == 0)
                                    {
                                        rankDownCardCount = Math.Min(tableCards[compareIndex].Rank, 10);
                                        if (tableCards[compareIndex].Rank == 14)
                                        {
                                            rankDownCardCount = 1; // Make Ace as a 1 rank for rank card war
                                        }
                                    }

                                    tableCards = DealWar(p1Deck, p2Deck, tableCards, rankDownCardCount, winningPlayer, player1Name, player2Name);
                                    warCount++;
                                    if (winningPlayer.Name != "")
                                    {
                                        isGameOver = true;
                                        break;
                                    }

                                    compareIndex += (rankDownCardCount + 1) * 2;
                                    DisplayWar(tableCards, compareIndex, rankDownCardCount, player1Name, player2Name, namePad, warCount);
                                    compareResult = CardCompare(tableCards, compareIndex);
                                    if (compareResult > 0) // Player 1 win
                                    {
                                        PlayerWin(p1Deck, tableCards);
                                        p1WarsWon++;
                                        Console.WriteLine();
                                        Console.WriteLine($"{player1Name} Wins the War!");
                                        System.Threading.Thread.Sleep(4000);
                                        Console.WriteLine("Temp Entry Required"); Console.ReadKey();
                                        break;
                                    }
                                    else if (compareResult < 0) // Player 2 win
                                    {
                                        PlayerWin(p2Deck, tableCards);
                                        p2WarsWon++;
                                        Console.WriteLine();
                                        Console.WriteLine($"{player2Name} Wins the War!");
                                        System.Threading.Thread.Sleep(4000);
                                        Console.WriteLine("Temp Entry Required"); Console.ReadKey();

                                        break;
                                    }

                                    if (isGameOver == true)
                                    {
                                        break;
                                    }
                                } // War loop End

                                if (isGameOver == true)
                                {
                                    break;
                                }
                            }

                            handsPlayed++; // Used here will not count Wars as hands
                        } // Hand loop End
                    }
                    if (isGameOver == true)
                    {
                        break;
                    }
                } // Deal loop End

                if (winningPlayer.Name != "")
                {
                    GameIsOver(winningPlayer);
                }
                break; // Program exit
            } // Game loop End
        }
コード例 #8
0
    private void HandleEndGame(SocketIOEvent obj)
    {
        var winningPlayer = WinningPlayer.CreateFromJSON(obj.data.ToString());

        EndGameEvent(winningPlayer);
    }
コード例 #9
0
 public PotWonEventArgs(WinningPlayer player, MoneyPot pot, int amountwon)
 {
     Player = player;
     Pot = pot;
     AmountWon = amountwon;
 }