Beispiel #1
0
        private static void PlayGame(List <string> AllowedWords, Dictionary <char, int> TileDictionary, bool RandomStart, int StartHandSize, int MaxHandSize, int MaxTilesPlayed, int NoOfEndOfTurnTiles)
        {
            int          PlayerOneScore       = 50;
            int          PlayerTwoScore       = 50;
            int          PlayerOneTilesPlayed = 0;
            int          PlayerTwoTilesPlayed = 0;
            string       PlayerOneTiles       = "";
            string       PlayerTwoTiles       = "";
            QueueOfTiles TileQueue            = new QueueOfTiles(20);

            if (RandomStart)
            {
                PlayerOneTiles = GetStartingHand(TileQueue, StartHandSize);
                PlayerTwoTiles = GetStartingHand(TileQueue, StartHandSize);
            }
            else
            {
                PlayerOneTiles = "BTAHANDENONSARJ";
                PlayerTwoTiles = "CELZXIOTNESMUAA";
            }
            while (PlayerOneTilesPlayed <= MaxTilesPlayed && PlayerTwoTilesPlayed <= MaxTilesPlayed && PlayerOneTiles.Length < MaxHandSize && PlayerTwoTiles.Length < MaxHandSize)
            {
                HaveTurn("Player One", ref PlayerOneTiles, ref PlayerOneTilesPlayed, ref PlayerOneScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles);
                Console.WriteLine();
                Console.WriteLine("Press Enter to continue");
                Console.ReadLine();
                Console.WriteLine();
                HaveTurn("Player Two", ref PlayerTwoTiles, ref PlayerTwoTilesPlayed, ref PlayerTwoScore, TileDictionary, ref TileQueue, AllowedWords, MaxHandSize, NoOfEndOfTurnTiles);
            }
            UpdateScoreWithPenalty(ref PlayerOneScore, PlayerOneTiles, TileDictionary);
            UpdateScoreWithPenalty(ref PlayerTwoScore, PlayerTwoTiles, TileDictionary);
            DisplayWinner(PlayerOneScore, PlayerTwoScore);
        }
Beispiel #2
0
 private static void FillHandWithTiles(ref QueueOfTiles TileQueue, ref string PlayerTiles, int MaxHandSize)
 {
     while (PlayerTiles.Length <= MaxHandSize)
     {
         PlayerTiles = PlayerTiles + TileQueue.Remove();
         TileQueue.Add();
     }
 }
Beispiel #3
0
        private static string GetStartingHand(QueueOfTiles TileQueue, int StartHandSize)
        {
            string Hand = "";

            for (int Count = 0; Count < StartHandSize; Count++)
            {
                Hand = Hand + TileQueue.Remove();
                TileQueue.Add();
            }
            return(Hand);
        }
Beispiel #4
0
        private static void AddEndOfTurnTiles(ref QueueOfTiles TileQueue, ref string PlayerTiles, string NewTileChoice, string Choice)
        {
            int NoOfEndOfTurnTiles = 0;

            if (NewTileChoice == "1")
            {
                NoOfEndOfTurnTiles = Choice.Length;
            }
            else if (NewTileChoice == "2")
            {
                NoOfEndOfTurnTiles = 3;
            }
            else
            {
                NoOfEndOfTurnTiles = Choice.Length + 3;
            }
            for (int Count = 0; Count < NoOfEndOfTurnTiles; Count++)
            {
                PlayerTiles = PlayerTiles + TileQueue.Remove();
                TileQueue.Add();
            }
        }
Beispiel #5
0
        private static void HaveTurn(string PlayerName, ref string PlayerTiles, ref int PlayerTilesPlayed, ref int PlayerScore, Dictionary <char, int> TileDictionary, ref QueueOfTiles TileQueue, List <string> AllowedWords, int MaxHandSize, int NoOfEndOfTurnTiles)
        {
            Console.WriteLine();
            Console.WriteLine(PlayerName + " it is your turn.");
            DisplayTilesInHand(PlayerTiles);
            string NewTileChoice = "2";
            bool   ValidChoice   = false;
            bool   ValidWord     = false;
            string Choice        = "";

            while (!ValidChoice)
            {
                Choice = GetChoice();
                if (Choice == "1")
                {
                    DisplayTileValues(TileDictionary, AllowedWords);
                }
                else if (Choice == "4")
                {
                    TileQueue.Show();
                }
                else if (Choice == "7")
                {
                    DisplayTilesInHand(PlayerTiles);
                }
                else if (Choice == "0")
                {
                    ValidChoice = true;
                    FillHandWithTiles(ref TileQueue, ref PlayerTiles, MaxHandSize);
                }
                else
                {
                    ValidChoice = true;
                    if (Choice.Length == 0)
                    {
                        ValidWord = false;
                    }
                    else
                    {
                        ValidWord = CheckWordIsInTiles(Choice, PlayerTiles);
                    }
                    if (ValidWord)
                    {
                        ValidWord = CheckWordIsValid(Choice, AllowedWords);
                        if (ValidWord)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Valid word");
                            Console.WriteLine();
                            UpdateAfterAllowedWord(Choice, ref PlayerTiles, ref PlayerScore, ref PlayerTilesPlayed, TileDictionary, AllowedWords);
                            NewTileChoice = GetNewTileChoice();
                        }
                    }
                    if (!ValidWord)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Not a valid attempt, you lose your turn.");
                        Console.WriteLine();
                    }
                    if (NewTileChoice != "4")
                    {
                        AddEndOfTurnTiles(ref TileQueue, ref PlayerTiles, NewTileChoice, Choice);
                    }
                    Console.WriteLine();
                    Console.WriteLine("Your word was:" + Choice);
                    Console.WriteLine("Your new score is:" + PlayerScore);
                    Console.WriteLine("You have played " + PlayerTilesPlayed + " tiles so far in this game.");
                }
            }
        }