Esempio n. 1
0
        }//end ContinueGame

        /// <summary>
        /// Link the labels on the GUI form to the dice and players
        /// </summary>
        /// <param name="form"></param>
        private void LoadLabels(Yahtzee form)
        {
            Label[] diceLabels = form.GetDice();
            for (int i = 0; i < dice.Length; i++)
            {
                dice[i].Load(diceLabels[i]);
            }
            for (int i = 0; i < players.Count; i++)
            {
                players[i].Load(form.GetScoresTotals());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor for Game
        /// </summary>
        /// <param name="myForm"> Application form </param>
        public Game(Yahtzee myForm)
        {
            numPlayers         = 2;
            form               = myForm;
            currentPlayerIndex = 0;
            players            = new BindingList <Player>();
            for (int i = 0; i < numPlayers; i++)
            {
                players.Add(new Player("Player " + (i + 1), form.GetScoresTotals()));
            }

            currentPlayer = players[currentPlayerIndex];
            dice          = new Die[Num_Die];

            dieLabels = form.GetDice();
            for (int i = 0; i < Num_Die; i++)
            {
                dice[i] = new Die(dieLabels[i]);
            }

            playersFinished = 0;
            numRolls        = 0;
        }
Esempio n. 3
0
        /// <summary>
        /// Load a saved game from the default save game file
        /// </summary>
        /// <param name="form">the GUI form</param>
        /// <returns>the saved game</returns>
        public static Game Load(Yahtzee form)
        {
            Game game = null;

            if (File.Exists(savedGameFile))
            {
                try {
                    Stream          bStream    = File.Open(savedGameFile, FileMode.Open);
                    BinaryFormatter bFormatter = new BinaryFormatter();
                    game = (Game)bFormatter.Deserialize(bStream);
                    bStream.Close();
                    game.form = form;
                    game.ContinueGame();
                    return(game);
                } catch {
                    MessageBox.Show("Error reading saved game file.\nCannot load saved game.");
                }
            }
            else
            {
                MessageBox.Show("No current saved game.");
            }
            return(null);
        }