예제 #1
0
 public YatzyGame()     // default constructor der laver YatzyGame objekt
 {
     dices = new Dice[] //hver gang vi laver nyt YatzyGame objekt skal der laves et nyt array som indeholder 6 objekter af typen Dice dvs. 6 nye terninger.
     {
         new Dice(), new Dice(), new Dice(),
         new Dice(), new Dice(), new Dice()
     };
     scoreboard = new Scoreboard();
 }
예제 #2
0
        public YatzyGame(int noDices)
        { //constructor til at vælge antal dices man spiller med.
            int n = noDices;

            dices = new Dice[n];
            for (int i = 0; i < n; i++)
            {
                dices[i] = new Dice();
            }
            scoreboard = new Scoreboard();
        }
예제 #3
0
파일: Roll.cs 프로젝트: Edderkoppekaw/Yatzy
        public Roll(Scoreboard scoreboard, List <Die> dice)
        {
            // Convert dice to their int value
            var diceList = dice.Select(d => d.Current).ToList();

            foreach (var rule in scoreboard.Rules)
            {
                if (!rule.Used)
                {
                    var ruleScores = rule.GetScores(diceList).Distinct();
                    foreach (var score in ruleScores)
                    {
                        Outcomes.Add(new Outcome(rule, score));
                    }

                    // If no outcomes from rule, add zero score option
                    if (ruleScores.Count() == 0)
                    {
                        Outcomes.Add(new Outcome(rule, 0));
                    }
                }
            }
            Outcomes = Outcomes.OrderByDescending(o => o.Points).ToList();
        }
예제 #4
0
        // this is the master which asks all the questions and keeps track of the answers and decides what to do with it aka the main menu
        public void Game()
        {
            Console.WriteLine("---------- Welcome to Yatzy ----------");
            Console.WriteLine("Please enter your name");
            string Username = Console.ReadLine();

            while (GameRunning)
            {
                if (hasRemainingTries() == false)
                {
                    Console.WriteLine("Which outcome to choose?");

                    var outcomeIndex = Console.ReadLine()[0] - 'a';
                    if (outcomeIndex >= 0 && outcomeIndex < Roll.Outcomes.Count)
                    {
                        Roll.UseOutcome(outcomeIndex);
                        tries = totaltriesmain;
                    }
                    Console.Clear();
                    continue;
                }
                else
                {
                    Console.WriteLine("Please choose an option:");
                    Console.WriteLine("1.) for Rolling all 6 dices");
                    Console.WriteLine("2.) for settings");
                    Console.WriteLine("3.) for scoreboard");
                    Console.WriteLine("4.) for quitting the game");
                }
                if (!_hand.FirstRound && tries != totaltriesmain)
                {
                    Console.WriteLine("5.) Choose the dices you want to reroll with ',' symbol between");
                    Console.WriteLine("6.) End turn");
                }

                if (UpScoreboard.Rules.All(r => r.Used) && Scoreboard.Rules.All(r => r.Used))
                {
                    Console.Clear();
                    Console.WriteLine("You have finished the game");
                    Console.WriteLine("===============");
                    UpScoreboard.Print();
                    Console.WriteLine("===============");
                    Scoreboard.Print();
                    Console.WriteLine("===============");
                    Totalscore = UpScoreboard.Sum() + Scoreboard.Sum();
                    if (UpScoreboard.Sum() >= 63)
                    {
                        Totalscore += 50;
                    }
                    Console.WriteLine("Total score: " + Totalscore);
                    GameRunning = false;
                }

                if (!int.TryParse(Console.ReadLine(), out UserChoice))
                {
                    Console.WriteLine("Sorry that was not a valid input. Try again");
                    continue;
                }
                else
                {
                    switch (UserChoice)
                    {
                    case 1:
                        tries--;
                        Console.Clear();
                        Console.WriteLine("You rolled:");
                        _hand.RerollAll();
                        PrintOutcomes();
                        Console.WriteLine("Remaining rolls: " + tries);
                        Console.WriteLine();
                        break;

                    case 2:
                        Console.Clear();
                        new Settings();
                        tries = Settings.totaltries;
                        _hand.CreateDice();

                        break;

                    case 3:
                        Console.Clear();
                        Console.WriteLine("Scoreboard: " + Username);
                        Console.WriteLine("===============");
                        Console.WriteLine("Upper Scoreboard: ");
                        if (UpScoreboard.Rules.All(r => r.Used))
                        {
                            UpScoreboard.Print();
                            Console.WriteLine("===============");
                            Console.WriteLine("Lower Scoreboard: ");
                            Scoreboard.Print();
                            Totalscore = UpScoreboard.Sum() + Scoreboard.Sum();
                            if (UpScoreboard.Sum() >= 63)
                            {
                                Totalscore += 50;
                            }
                            Console.WriteLine("===============");
                            Console.WriteLine("Total score: " + Totalscore);
                        }
                        else
                        {
                            UpScoreboard.Print();
                        }
                        Console.WriteLine("===============");
                        break;

                    case 4:
                        GameRunning = false;
                        Console.WriteLine("Thx for playing byebye - enter to quit");
                        break;

                    case 5:
                        if (tries != totaltriesmain)
                        {
                            tries--;
                            _hand.RerollDices(AskUserForDices());
                            PrintOutcomes();
                        }
                        break;

                    case 6:
                        if (tries != totaltriesmain)
                        {
                            tries = 0;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            Console.ReadLine();
        }