Ejemplo n.º 1
0
        void SpeelYahtzee(YahtzeeGame game)
        {
            int aantalpogingen = 0;

            do
            {
                game.Gooi();
                game.ToonWorp();

                aantalpogingen++;
            }while (!game.Yahtzee() && !game.FourOfAKind() && !game.ThreeOfAKind());

            // Ga na volgens de yahtzee hierarchie welke er is gegooid en hoe lang dat duurde
            if (game.Yahtzee())
            {
                Console.WriteLine("Aantal pogingen nodig voor Yahtzee: {0}", aantalpogingen);
            }
            else if (game.FourOfAKind())
            {
                Console.WriteLine("Aantal pogingen nodig voor Four Of A Kind: {0}", aantalpogingen);
            }
            else if (game.ThreeOfAKind())
            {
                Console.WriteLine("Aantal pogingen nodig voor Three Of A Kind: {0}", aantalpogingen);
            }
        }
Ejemplo n.º 2
0
        public void SetUp()
        {
            _console = Substitute.For<IConsole>();

            _category1 = Substitute.For<Category>("", null, null, null);
            _category2 = Substitute.For<Category>("", null, null, null);
            _category3 = Substitute.For<Category>("", null, null, null);

            _game = new YahtzeeGame(
                new List<Category> { _category1, _category2, _category3 },
                _console);
        }
Ejemplo n.º 3
0
        public void Play_three_rounds_and_print_final_score()
        {
            var console = Substitute.For<IConsole>();
            var game = new YahtzeeGame(
                Enumerable.Repeat(
                    new Category(
                        "", new OnesRule(), new Turn(), new Dice()),
                    3).ToList(),
                console);

            game.Play();

            Received.InOrder(() =>
            {
                console.PrintLine("Category: Ones");
                console.PrintLine("Dice: D1:2 D2:4 D3:1 D4:6 D5:1");
                console.PrintLine("[1] Dice to re-run:");
                //console.PrintLine("D1 D2 D4");
                console.PrintLine("Dice: D1:1 D2:5 D3:1 D4:2 D5:1");
                console.PrintLine("[2] Dice to re-run:");
                //console.PrintLine("D2 D4");
                console.PrintLine("Dice: D1:1 D2:1 D3:1 D4:5 D5:1");
                console.PrintLine("Category Ones score: 4");

                console.PrintLine("Category: Twos");
                console.PrintLine("Dice: D1:2 D2:4 D3:1 D4:6 D5:1");
                console.PrintLine("[1] Dice to re-run:");
                //console.PrintLine("D2 D3 D4 D5");
                console.PrintLine("Dice: D1:2 D2:5 D3:1 D4:2 D5:1");
                console.PrintLine("[2] Dice to re-run:");
                //console.PrintLine("D2 D3 D5");
                console.PrintLine("Dice: D1:2 D2:1 D3:1 D4:2 D5:1");
                console.PrintLine("Category Twos score: 2");

                console.PrintLine("Category: Threes");
                console.PrintLine("Dice: D1:2 D2:4 D3:1 D4:6 D5:1");
                console.PrintLine("[1] Dice to re-run:");
                //console.PrintLine("D1 D2 D3 D4 D5");
                console.PrintLine("Dice: D1:1 D2:5 D3:1 D4:2 D5:1");
                console.PrintLine("[2] Dice to re-run: ");
                //console.PrintLine("D1 D2 D3 D4 D5");
                console.PrintLine("Dice: D1:1 D2:1 D3:1 D4:5 D5:1");
                console.PrintLine("Category Threes score: 0");

                console.PrintLine("Yahtzee score");
                console.PrintLine("Ones: 4");
                console.PrintLine("Twos: 2");
                console.PrintLine("Threes: 0");
                console.PrintLine("Final score: 6");
            });
        }
Ejemplo n.º 4
0
            public override void OnResponse(RelayInfo info)
            {
                PlayerMobile from = User;
                int          id   = info.ButtonID;

                if (id == 0)
                {
                    return;
                }

                RollOrder old = Board.RollOrder;

                if (info.IsSwitched(1) && old != RollOrder.AsIs)
                {
                    Board.RollOrder = RollOrder.AsIs;
                }
                else if (info.IsSwitched(2) && old != RollOrder.Random)
                {
                    Board.RollOrder = RollOrder.Random;
                }
                else if (info.IsSwitched(3) && old != RollOrder.Roll)
                {
                    Board.RollOrder = RollOrder.Roll;
                }

                if (old != Board.RollOrder)
                {
                    YahtzeeGame.SendMessage(from, String.Format("Roll order has been changed to: {0}", Board.GetRollOrder()));
                    Board.InvalidateProperties();
                }

                int playerCount = Board.PlayerCount;

                for (int i = 1; i <= YahtzeeGame.MaxPlayers; i++)
                {
                    if (info.IsSwitched(i + 3) && playerCount != i)
                    {
                        Board.PlayerCount = i;
                        break;
                    }
                }

                if (playerCount != Board.PlayerCount)
                {
                    YahtzeeGame.SendMessage(User, String.Format("Amount of players have been changed: {0}", Board.PlayerCount.ToString()));
                    Board.InvalidateProperties();
                }

                Refresh();
            }
Ejemplo n.º 5
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            Level = (SecureLevel)reader.ReadInt();

            RollOrder   = (RollOrder)reader.ReadInt();
            PlayerCount = reader.ReadInt();

            if (reader.ReadInt() == 1)
            {
                Game = new YahtzeeGame(reader, this);
            }
        }
Ejemplo n.º 6
0
        public override void OnDoubleClick(Mobile from)
        {
            if (from is PlayerMobile && Game == null && (Pending == null || !Pending.Contains(from)))
            {
                BaseGump.SendGump(new YahtzeeConfirmGump((PlayerMobile)from, "Join Yahtzee?", "Would you like to join the next yahtzee game?", () =>
                {
                    lock (Lock)
                    {
                        if (Game != null)
                        {
                            YahtzeeGame.SendMessage(from, "The game has already begun. Maybe next time...", 2118);
                        }
                        else if (YahtzeeGame.IsInGame((PlayerMobile)from))
                        {
                            YahtzeeGame.SendMessage(from, "You can only play in one game of Yahtzee at a time!", 2118);
                        }
                        else
                        {
                            if (Pending == null)
                            {
                                Pending = new List <Mobile>();
                                Timer.DelayCall(TimeSpan.FromSeconds(120), () =>
                                {
                                    if (Game == null)
                                    {
                                        Pending.ForEach(mob => mob.SendMessage("You lack the required players for Yahtzee!"));
                                        Pending.Clear();
                                        Pending = null;
                                    }
                                });
                            }

                            Pending.Add(from);

                            if (Pending.Count > 1)
                            {
                                ColUtility.ForEach(Pending.Where(mob => mob != from), mob => mob.SendMessage("{0} has joined the Yahtzee game!", from.Name));
                            }

                            if (Pending.Count >= PlayerCount)
                            {
                                Game = new YahtzeeGame(Pending, this, RollOrder);
                                Pending.ForEach(mob => YahtzeeGame.SendMessage(mob, "yahtzee will begin in 10 seconds!"));
                                Pending.Clear();

                                Timer.DelayCall(TimeSpan.FromSeconds(10), Game.BeginGame);
                            }
                            else
                            {
                                Pending.ForEach(mob => YahtzeeGame.SendMessage(mob, String.Format("Still waiting on {0} more players!", PlayerCount - Pending.Count)));
                            }
                        }
                    }
                }));
            }
            else if (Game != null && from is PlayerMobile)
            {
                PlayerEntry entry = Game.GetEntry((PlayerMobile)from);

                if (entry != null)
                {
                    BaseGump.SendGump(new YahtzeeGump(entry, entry.Player, Game));
                }
            }
        }
Ejemplo n.º 7
0
        void Start()
        {
            YahtzeeGame yahtzeeGame = new YahtzeeGame();

            SpeelYahtzee(yahtzeeGame);  // speel het gemaakte spel
        }
 public MainWindow()
 {
     yahtzeeGame = new YahtzeeGame();
     InitializeComponent();
     updateDisplay();
 }