public static Deck Load(string name) { StreamReader reader = null; try { reader = new StreamReader(new FileStream("Content/Decks/" + name + ".ydk", FileMode.Open, FileAccess.Read)); Deck deck = new Deck(); bool side = false; while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line == null) continue; line = line.Trim(); if (line.StartsWith("#")) continue; if (line.Equals("!side")) { side = true; continue; } int id; if (!int.TryParse(line, out id)) continue; deck.AddNewCard(id, side); } reader.Close(); if (deck.Cards.Count > 60) return null; if (deck.ExtraCards.Count > 15) return null; if (deck.SideCards.Count > 15) return null; return deck; } catch (Exception) { if (reader != null) reader.Close(); return null; } }
public static Deck Load(string name) { StreamReader reader = null; try { reader = new StreamReader(new FileStream("Content/Decks/" + name + ".ydk", FileMode.Open, FileAccess.Read)); Deck deck = new Deck(); bool side = false; while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line == null) { continue; } line = line.Trim(); if (line.StartsWith("#")) { continue; } if (line.Equals("!side")) { side = true; continue; } int id; if (!int.TryParse(line, out id)) { continue; } deck.AddNewCard(id, side); } reader.Close(); if (deck.Cards.Count > 60) { return(null); } if (deck.ExtraCards.Count > 15) { return(null); } if (deck.SideCards.Count > 15) { return(null); } return(deck); } catch (Exception) { if (reader != null) { reader.Close(); } return(null); } }