Example #1
0
        static void Main(string [] args)
        {
            int numberOfPlayers = 0;

            Console.WriteLine("                 Welcome to MONOPOLY");
            Console.WriteLine("______________________________________________________");

            Console.WriteLine("               **** Game Started ****");
            Console.WriteLine();

            Console.Write("Please enter the number of players to start the game : ");
            while (!((int.TryParse(Console.ReadLine(), out numberOfPlayers)) &&
                    ((numberOfPlayers >= 2) && (numberOfPlayers <= 8))))
            {
                Console.WriteLine("Player should between 2 and 8 !");
            }

            //creating the array of players,die array and the gameBoard that contains 40 cell
            Player[] arrayOfPlayers = new Player[numberOfPlayers];
            Die[] die = new Die[2];
            GameBoard gameBoard = new GameBoard();

            for (int i = 0; i < numberOfPlayers; i++)
            {
                arrayOfPlayers[i] = new Player(5000, "Player" + (i + 1));
                arrayOfPlayers[i].Position = gameBoard.GetCell(0);
            }

            //creating gameMaster
            GameMaster gameMaster = new GameMaster(die, gameBoard, arrayOfPlayers);

            Console.WriteLine();
            if ((args.Length > 0) && args[0].Equals("test"))
            {
                gameMaster.PlayGame("test");
            }
            else
            {
                gameMaster.PlayGame();
            }
        }
        private void Setup()
        {
            if (this.Dispatcher.CheckAccess())
            {
                myBoard = new GameBoard();
                myBoard.SetBinding(WidthProperty, "myGrid.Height");
                myBoard.SetBinding(HeightProperty, "myGrid.Height");
                myBoard.Background = ThemeParser.GetColor(ThemeParser.Colors.Board);
                Grid.SetRowSpan(myBoard, 3);
                Grid.SetColumn(myBoard, 0);
                myChat = new ChatComponent();
                myChat.NewOutgoingMessage += new EventHandler<NewOutgoingMessageEventArgs>(Chat_NewOutgoingMessage);
                Grid.SetColumn(myChat, 1);
                Grid.SetRow(myChat, 2);
                myChat.Margin = new Thickness(5, 0, 0, 0);
                myMenu = new MenuFader(myCanvas);
                myMenu.Margin = new Thickness(25,0,25,0);
                myMenu.HostGameClicked += new EventHandler<HostGameClickEventArgs>(myMenu_HostGameClicked);
                myMenu.JoinGameClicked += new EventHandler<JoinGameClickEventArgs>(myMenu_JoinGameClicked);
                myMenu.CloseGameClicked += new EventHandler<CloseGameClickEventArgs>(myMenu_CloseGameClicked);
                myMenu.StartGameClicked += new EventHandler<StartGameClickEventArgs>(myMenu_StartGameClicked);
                myGrid.Children.Add(myBoard);
                myGrid.Children.Add(myChat);
                myCanvas.Children.Add(myMenu);
                myBoard.GameBuilt += new EventHandler<GameBoardBuiltEventArgs>(myBoard_GameBuilt);
                myBoard.Dice.RollEnded += new EventHandler<RollEndedEventArgs>(Dice_RollEnded);
                myBoard.Dice.RollStarted += new EventHandler<RollStartedEventArgs>(Dice_RollStarted);
                myBoard.Dice.EndTurn += new EventHandler<EndTurnEventArgs>(Dice_EndTurn);
                ToggleTurnItems(false);

            }
            else this.Dispatcher.BeginInvoke(new Action(Setup), null);
        }