protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. this._ActivePlayer = null; this._CardsAvailable = null; this._MessageRequestQueue = null; this._MessageResponseQueue = null; this._Players = null; this._RNG = null; this._Table = null; this._TurnsTaken = null; } // Call the appropriate methods to clean up // unmanaged resources here. // If disposing is false, // only the following code is executed. // Note disposing has been done. disposed = true; } }
public void Load(String filename) { if (this.State != GameState.Unknown) return; //try //{ XmlDocument xdGame = new XmlDocument(); xdGame.LoadXml(Utilities.StringUtility.Decrypt(Utilities.StringUtility.Unzip(System.IO.File.ReadAllBytes(filename)))); //xdGame.Load("gamedump.xml"); XmlNode xn = xdGame.SelectSingleNode("game/rng"); if (xn != null) { MemoryStream msRandom = new MemoryStream(Convert.FromBase64String(xn.InnerText)); BinaryFormatter bf = new BinaryFormatter(); this.RNG = (Random)bf.Deserialize(msRandom); msRandom.Close(); } xn = xdGame.SelectSingleNode("game/start_time"); if (xn != null) this.StartTime = DateTime.Parse(xn.InnerText); this.State = GameState.Setup; xn = xdGame.SelectSingleNode("game/settings/GameSettings"); if (xn != null) { Cards.CardCollection allCards = Cards.CardCollection.GetAllCards(c => true); XmlSerializer myDeserializer = new XmlSerializer(typeof(GameSettings), GetAllSerializingTypes(allCards).ToArray()); using (StringReader sr = new StringReader(xn.OuterXml)) { this.Settings = (GameSettings)myDeserializer.Deserialize(sr); } } _Table = new Table(this); XmlNodeList xnl = xdGame.SelectNodes("game/players/player"); this._Players = new PlayerCollection(); foreach (XmlNode xnPlayer in xnl) { Player player = Player.Load(this, xnPlayer); this._Players.Add(player); this.Table.AddPlayer(player); } xn = xdGame.SelectSingleNode("game/table"); if (xn == null) return; this.Table.Load(xn); this._Players.Setup(this); xn = xdGame.SelectSingleNode("game/state"); if (xn != null) this.State = (GameState)Enum.Parse(typeof(GameState), xn.InnerText, true); this.TurnsTaken.Load(this, xdGame.SelectSingleNode("game/turns")); xn = xdGame.SelectSingleNode("game/activeplayer"); if (xn != null && !String.IsNullOrEmpty(xn.InnerText)) { this.ActivePlayer = this.Players.FirstOrDefault(p => p.UniqueId == new Guid(xn.InnerText)); this.ActivePlayer.SetCurrentTurn(this.TurnsTaken.Last()); } //} //catch (Exception ex) //{ // throw ex; //} }
public void SelectCards() { if (this.State != GameState.CardSelection) throw new GameCreationException("This method can only be called during CardSelection!"); if (_Table != null) _Table.TearDown(); this.CardsAvailable = Cards.CardCollection.GetAllCards(c => IsCardAllowed(c)); Cards.CardCollection _CardsChosen = new Cards.CardCollection(); if (this.Settings.Preset != null) { _CardsChosen = this.Settings.Preset.Cards; } else if (this.Settings.Constraints != null) { _CardsChosen.AddRange(this.Settings.Constraints.SelectCards(this.CardsAvailable, 10)); } this.CardsAvailable.RemoveAll(card => _CardsChosen.Contains(card)); _Table = new Table(this, this.Players.Count); _CardsChosen.ForEach(c => _Table.AddKingdomSupply(_Players, c.CardType)); // should now have a list of cards that can be drawn from for things like Bane supplies _Table.SetupSupplies(this); }