示例#1
0
        internal void PrintScoreboard(Yatzy spil)
        {
            PossibleOutcomes.Clear();
            Dictionary <string, int> tempdict = Scores;
            int upperScore  = 0;
            int upperBonus  = 0;
            int totalScore  = 0;
            int loopCounter = 0;

            foreach (KeyValuePair <string, int> kvp in tempdict)
            {
                WriteToScoreboard(kvp.Key, spil, true); //tanker possibleOutcomes op.
                if (loopCounter < 6)
                {
                    upperScore += kvp.Value;
                }
                else if (loopCounter == 6)
                {
                    Console.WriteLine($"\tSum: {upperScore}");
                    if (upperScore > 62)
                    {
                        upperBonus  = 50;
                        totalScore += upperBonus;
                    }
                    Console.WriteLine($"\tBonus: {upperBonus}");
                }


                totalScore += kvp.Value;
                string scoreboardText;

                if (RemovedOutcomes.Contains(kvp.Key))
                {
                    scoreboardText = $"\t{kvp.Key}: X";
                }
                else
                {
                    scoreboardText = $"\t{kvp.Key}: {kvp.Value}";
                }


                if ((PossibleOutcomes.Contains(kvp.Key)) && (kvp.Value == 0) && (!(RemovedOutcomes.Contains(kvp.Key))))
                {
                    scoreboardText += " <--";
                }

                Console.WriteLine(scoreboardText);
                loopCounter++;
            }
            Console.WriteLine($"\tSum: {totalScore}");
            Console.WriteLine("-------------------------------------\n");
        }
示例#2
0
        internal void WriteToScoreboard(string userInput, Yatzy spil, bool AddToPossibleOutcomesInstead = false)
        {
            int[] countOfEachDice = spil.CountOfEachDice();

            if (spil.RoundCounter < 6) //altså når man spiller i upper section.
            {
                if (SingleNumberNumeric.ContainsKey(userInput))
                {
                    AddUpperToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }
            }

            else //lower section
            {//ikke et switch statement fordi fx addPairToScoreboard er nemmere at samle som enkelt i stedet for flere forskellige cases i et swtich.
             //man kan nemlig ikke sige  case 1,2,3:    man kan kun sige case 1:    case 2:   osv.       Så det er for at undgå at gentage kode.
                if (Pairs.ContainsKey(userInput))
                {
                    AddPairToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }

                else if (OfAKind.ContainsKey(userInput))
                {
                    AddOfAKindToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }

                else if (Straight.ContainsKey(userInput))
                {
                    AddStraightToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }

                else if (userInput == "fuldt hus")
                {
                    AddFuldHusToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }

                else if (userInput == "yatzy")
                {
                    AddYatzyToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }

                else if (userInput == "chance")
                {
                    AddChanceToScoreboard(userInput, countOfEachDice, AddToPossibleOutcomesInstead);
                }
            }
        }
示例#3
0
        // Main method
        public static void Main(string[] args)
        {
            Yatzy spil = new Yatzy();

            spil.StartGame();
        }