/// <summary> /// Initialize a new dice handler. /// </summary> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> depicting the display.</param> /// <param name="state">The state of the player's dice.</param> public DiceHandler(GraphicsDevice graphicsDevice, DiceState state) { screenBounds = graphicsDevice.Viewport.Bounds; if (state == null) { DiceState = new DiceState(); Reset(false); } else { DiceState = state; } }
/// <summary> /// Generates a Yacht state from its XML representation. /// </summary> /// <param name="reader">The <see cref="System.Xml.XmlReader"/> stream from which the object /// is deserialized.</param> /// <remarks>This method updates the singleton instance of <see cref="NetworkManager"/> with data read /// from the XML representation.</remarks> public void ReadXml(XmlReader reader) { // Read the start element reader.Read(); YachGameState = null; PlayerDiceState = null; NetworkManagerState = NetworkManager.Instance; // Read the start element of the first sub-element reader.Read(); // Read the yacht state's sub-elements while (reader.IsStartElement()) { if (reader.LocalName == typeof(GameState).Name) { YachGameState = new GameState(); YachGameState.Deserialize(reader); } else if (reader.LocalName == typeof(DiceState).Name) { PlayerDiceState = new DiceState(); PlayerDiceState.Deserialize(reader); } else if (reader.LocalName == typeof(NetworkManager).Name) { NetworkManagerState.Deserialize(reader); } // Read the next sub-element start element reader.Read(); } // Read the end element reader.Read(); }
/// <summary> /// Initializes the dice handler used to handle the player's dice, and loads resources used for displaying /// it. /// </summary> /// <param name="diceState">State to initialize the dice handler according to, or null to use the default /// initial state.</param> /// <param name="gameType">The game type for which the dice are initialized.</param> private void InitializeDiceHandler(DiceState diceState, GameTypes gameType) { diceHandler = new DiceHandler(ScreenManager.Game.GraphicsDevice, diceState); diceHandler.LoadAssets(ScreenManager.Game.Content); }
/// <summary> /// Serializes the DiceHandler object. /// </summary> /// <param name="writer">The xml writer to use when writing.</param> public void WriteXml(System.Xml.XmlWriter writer) { DiceState.WriteXml(writer); }
/// <summary> /// Reads a serialized DiceHandler object. /// </summary> /// <param name="reader">The xml reader from which to read.</param> public void ReadXml(System.Xml.XmlReader reader) { DiceState.ReadXml(reader); }
/// <summary> /// Positions the player's dice according to a supplied state. /// </summary> /// <param name="state">Dice state to use when positioning the dice.</param> public void LoadState(DiceState state) { DiceState = state; PositionDice(); }