Exemple #1
0
        public static void Problem3()
        {
            Console.WriteLine("Creation of the Game:");
            Monopoly game = Monopoly.GetInstance();

            #region Add players
            //Adding players
            game.AddPlayer("Jean");
            game.AddPlayer("Paul");
            game.AddPlayer("Jacques");
            game.AddPlayer("Christine");
            game.AddPlayer("UselessPlayer");
            Console.WriteLine(game);
            #endregion

            #region Try deleting a player
            game.DeletePlayer("UselessPlayer");
            Console.WriteLine("UselessPlayer Deleted:");
            Console.WriteLine(game);
            #endregion

            #region Simulating some round
            Console.WriteLine("\nHow many rounds do you want to simulate ? ");
            string n;
            int    value;
            do
            {
                n = Console.ReadLine();
            } while (!int.TryParse(n, out value));


            for (int i = 0; i < value; i++)
            {
                game.PlayRound();
            }
            #endregion

            #region Others different check
            //Try adding a player during the game
            game.AddPlayer("Cassandre");
            //! You can't add players when the game has already started

            //Check if the iterator pattern works properly
            Console.WriteLine(game);

            //Check if the singleton pattern works properly
            Console.WriteLine("\nLet's check that the singleton pattern works properly");
            Monopoly game2 = Monopoly.GetInstance();
            Console.WriteLine(game2);
            // !! This is exactly the same game, the iterator pattern is working properly.

            //Let's see the historic of moves of Jacques:
            Console.WriteLine("\nLet's see the historic of Jacques");
            game.ShowHistoric("Jacques");

            //Let's see if we can delete the last move of Jacques
            Console.WriteLine("\nLet's try to delete the last move of Jacques");
            game.Restore("Jacques");
            game.ShowHistoric("Jacques");
            #endregion
        }