//simple quick text file implementation for now //each row contains: //PlayerClassNum ItemID | in integer form internal static Barracks load() { string s; Barracks b = new Barracks(); bool added = false; try { TextReader tr = new StreamReader(savefile); while ((s = tr.ReadLine()) != null) { string[] strs = s.Split(SEPERATOR); if(strs.Length <= 0) continue; int x, y; if (strs[0] == SPAREITEMS) { for (int i = 1;i<strs.Length ;i++) { ItemID newItem = (ItemID)int.Parse(strs[i]); b.addItem(newItem); } }else if (strs.Length == 2) { x = int.Parse(strs[0]); y = int.Parse(strs[1]); added = true; b.addHero((PlayerClassNum)x, (ItemID)y); } } tr.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } if (!added) b = getNewGameBarracks(); return b; }
static Barracks getNewGameBarracks() { Barracks b = new Barracks(); b.addHero(PlayerClassNum.vang, ItemID.none); b.addHero(PlayerClassNum.vang, ItemID.none); b.addHero(PlayerClassNum.puri, ItemID.none); b.addHero(PlayerClassNum.puri, ItemID.none); b.addHero(PlayerClassNum.puri, ItemID.none); b.addHero(PlayerClassNum.mage, ItemID.none); b.addHero(PlayerClassNum.mage, ItemID.none); b.addHero(PlayerClassNum.mage, ItemID.none); b.addHero(PlayerClassNum.assa, ItemID.none); b.addHero(PlayerClassNum.assa, ItemID.none); b.addHero(PlayerClassNum.assa, ItemID.none); b.addHero(PlayerClassNum.archer, ItemID.none); b.addHero(PlayerClassNum.archer, ItemID.none); b.addHero(PlayerClassNum.archer, ItemID.none); b.addHero(PlayerClassNum.bard, ItemID.none); b.addHero(PlayerClassNum.bard, ItemID.none); for (int i=0; i < InGame.randy.Next(10)+5;i++ ) { b.addItem(Item.getRandomItem()); } return b; }