Exemplo n.º 1
0
        private void newGameButton_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            using (NewGameDialog dlg = new NewGameDialog())
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    int   playersCount = dlg.playersCount;
                    float money        = dlg.millions;

                    using (PlayersChoosing dlg2 = new PlayersChoosing(playersCount, money))
                    {
                        if (dlg2.ShowDialog() == DialogResult.OK)
                        {
                            players = dlg2.players;
                            Hide();
                            using (Monopoly gw = new Monopoly(players))
                            {
                                Game g = new Game(players, gw);
                                if (gw.ShowDialog() == DialogResult.OK)
                                {
                                    Show();
                                }
                            };
                        }
                    }
                }
            }
            this.Enabled = true;
        }
Exemplo n.º 2
0
        private void loadGameButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                AddExtension    = true,
                DefaultExt      = "mon",
                CheckPathExists = true,
                //sfd.FileName = "game.mon";
                Filter           = "Monopoly saved games (*.mon)|*.mon",
                InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
                Title            = "Choose a game to load",
                ValidateNames    = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(ofd.FileName))
                {
                    Game g;
                    try
                    {
                        Stream          openFileStream = File.OpenRead(ofd.FileName);
                        BinaryFormatter deserializer   = new BinaryFormatter();
                        g = (Game)deserializer.Deserialize(openFileStream);
                        openFileStream.Close();

                        Hide();
                        using (Monopoly gw = new Monopoly(g.GetPlayers()))
                        {
                            gw.Show();
                            g.SetWindow(gw);
                            g.UpdateWindow();
                            gw.Hide();
                            if (gw.ShowDialog() == DialogResult.OK)
                            {
                                Show();
                            }
                        };
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        MessageBox.Show("Failed to load game.");
                    }
                }
            }
        }
Exemplo n.º 3
0
 /**
  * The cosntructor. Prepares the game, assigns/creates its helping classes/data manipulators.
  */
 public Game(Player[] players, Monopoly window)
 {
     this.players = players;
     GameState    = GameStage.DICE;
     this.window  = window;
     //bgw = new BackgroundWorker();
     colorGroups = new int[, ] {
         { 0, 0, 0 }, { 255, 51, 51 }, { 0, 128, 255 }, { 152, 76, 0 },
         { 255, 153, 51 }, { 255, 102, 255 }, { 0, 0, 204 },
         { 0, 204, 102 }, { 255, 255, 51 }
     };
     currentPlayer       = players[playerTurnPointer];
     riskCardManager     = new RiskCardManager();
     treasureCardManager = new TreasureCardManager();
     propertyManager     = new Cards.PropertyManager();
     gameplan            = new Gameplan(players, propertyManager.GetFieldTypes());
     window.ShowPlayerInfo(currentPlayer);
     window.Load   += OnLoad;
     window.Enabled = true;
 }
Exemplo n.º 4
0
        /**
         * The only function of the dice is to simulate dice roll and redraw the "rolled"
         * number in the graphic interface.
         */
        public int Roll(Monopoly window)
        {
            //draw the dice and randomising
            int rolls  = randomizer.Next(5, 10);
            int result = 0;

            for (int i = 0; i < rolls; i++)
            {
                result = randomizer.Next(1, 7);
                window.ShowDiceNumber(result);
                Thread.Sleep(DICE_SLEEP);
            }
            Thread.Sleep(ROLL_OVER_WAIT);
            // roll again
            if (result == 6)
            {
                result += Roll(window);
            }
            return(result);
            //return 7; //for testing only!
        }
Exemplo n.º 5
0
 /**
  * Assigns the gamewindow to the property. This is used after Serialization,
  * because the graphical window is not Serialized and after loading game,
  * the newly created game window is not assigned to the Game's attribute window.
  */
 public void SetWindow(Monopoly gw)
 {
     window = gw;
 }