Exemplo n.º 1
0
        static void Score(game game, string input) // to score points for the round
        {
            UI.showUI(game);
            if (input == null)
            {
                input = UI.prompt("Select a category to score in: ");
            }
            var submitted = (from ctg in game.Score where ctg.name == input.Trim().ToLower() select ctg).ToList();

            while (submitted.Count == 0 || submitted.First().used)
            {
                if (submitted.Count != 0)
                {
                    Console.Write("Category Already Used... please choose another: ");
                }
                if (submitted.Count == 0)
                {
                    Console.Write("Invalid input, choose a valid category: ");
                }
                input     = Console.ReadLine();
                submitted = (from ctg in game.Score where ctg.name == input.Trim().ToLower() select ctg).ToList();
            }
            submitted.First().assignPoints(game.currentRound.calcPoints(input.Trim().ToLower()));
            UI.showCard(game);
            UI.prompt("Press any key To continue...");
            game.newRound();
        }
Exemplo n.º 2
0
        static void Main(string[] args) // entry....
        {
            game game           = new game();
            bool erroneousInput = false;

            Console.WriteLine("Welcome to Yahtzee!");

            while (game.gameOver == false)//move this into ui loop...make const for red writing...
            {
                if (game.currentRound.roundRolls > 2)
                {
                    Score(game, null);
                }
                if (erroneousInput == false)
                {
                    UI.showUI(game);
                }
                erroneousInput = false;
                string input     = UI.prompt("Select a category, pick the dice to re-roll (Ex. 1,2,3) or \"show\" for score-cardChoice(< category >/#,#,#/show):");
                var    submitted = (from ctg in game.Score where ctg.name == input.Trim().ToLower() select ctg).ToList();


                if (input.ToLower().Trim() == "show") // selected show
                {
                    UI.showCard(game);
                    Console.WriteLine("Press any key to Continue...");
                    Console.ReadKey();
                }

                else if (submitted.Count > 0) // to score
                {
                    Score(game, input);
                }

                else
                {
                    try
                    {
                        game.currentRound.reRoll(input, game);
                    }

                    catch { Console.WriteLine("Error, Invalid Input..."); erroneousInput = true; }
                }
            }


            Console.WriteLine("Game Over! Here Are your results: ");
            UI.showCard(game);
            Console.WriteLine("Press any Key to Exit...");
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public void reRoll(string dieToReRollString, game game)  // rerolling the die and advancing the "rolls in current round, and rolling selected dice"
        {
            if (this.roundRolls > 2)
            {
                return;
            }
            var dieToReRollStringArray = dieToReRollString.Split(',');

            foreach (var dieNumber in dieToReRollStringArray)
            {
                int n = Convert.ToInt32(dieNumber.Trim()) - 1;
                dice[Convert.ToInt32(dieNumber.Trim()) - 1].roll();
            }
            this.roundRolls++;
        }
Exemplo n.º 4
0
        public static void showUI(game game)// shows main interface
        {
            string output = string.Empty;

            output += "--- Round " + game.rounds.Count.ToString() + " ---" + Environment.NewLine;
            output += "Rolling Dice...(" + "rolls for round: " + game.currentRound.roundRolls + ")" + Environment.NewLine;
            output += "You rolled the following: " + Environment.NewLine;
            output += getRollDisplay(game.currentRound.dice) + Environment.NewLine;
            output += "Category" + replicate(" ", 20 - "Category".Length) + "Points" + Environment.NewLine;
            //output = attachScore(output, game, false);
            foreach (var ctg in game.Score)
            {
                output += ctg.name + replicate(" ", 20 - ctg.name.Length) + game.currentRound.calcPoints(ctg.name) + Environment.NewLine;
            }

            Console.WriteLine(output);
        }
Exemplo n.º 5
0
        public static void showCard(game game) // shows the score card
        {
            string output = string.Empty;

            output += "-------";
            output += "|    Score Card     |";
            output += "-------";
            output += Environment.NewLine + "Category" + replicate(" ", 20 - "Category".Length) + "Points" + Environment.NewLine;

            foreach (var ctg in game.Score)
            {
                output += ctg.name + replicate(" ", 20 - ctg.name.Length) + ctg.points + Environment.NewLine;
            }
            output += "-------------" + Environment.NewLine;
            output += "Total" + replicate(" ", 20 - "Total".Length) + game.Score.Sum(x => x.points) + Environment.NewLine;
            Console.WriteLine(output);
        }