public static Player CreateNewPlayer() { // Pick name Console.WriteLine("What is your name?"); string name = Console.ReadLine().Trim(); // lets egyptize the name int choice = 0; string userInput = ""; string[] names = {(name.ToLower() + "nefer").ToUpperFirstLetter(), (name.ToLower() + "hotep").ToUpperFirstLetter(), "Ptah" + name.ToLower() + "tep", "Nefe" + name.ToLower() + "bet", "Ankh" + name.ToLower() + "amun", "Iset" + name.ToLower() + "rure", "Neb" + name.ToLower() + "kare"}; while (choice < 1 || choice > 7) { Console.WriteLine("That sounds just bad. What about:"); for (int i=0; i<names.Length; i++) Console.WriteLine("\t{0}: {1}", i+1, names[i]); userInput = Console.ReadLine(); int.TryParse(userInput, out choice ); } // create new name string newname = names[choice-1]; Characteristics ch = new Characteristics(10,2,1,0); Characteristics ch2 = new Characteristics(10,2,1,0); Player p = new Player(newname, ch, ch2, 100, 2, 2); p.SetCurrentDungeon("dungeon1"); Item amulet = new Item("Amulet with crocodile"); p.PickItem(amulet); Console.Clear(); Console.WriteLine("You wake up."); Console.WriteLine("Your head is spinning and you feel throbbing pain on the back of your head."); Console.WriteLine("There is pitch dark all around you, not a single ray of light. And who are you, anyway?"); Console.ReadKey(); Console.WriteLine("Oh yes, your name is {0} and you were building the tomb for Khasekhemre, pharaohs chief accountant.", newname); Console.WriteLine("And thats the last thing you remember"); Console.ReadKey(); Console.WriteLine("You should probably find out what happened."); Console.ReadKey(); return p; }
public static Player LoadPlayerFromXml(string playername) { string path = filePath + "players/" + playername.ToLower() + "/player.xml"; XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode root = doc.DocumentElement; // get attributes of player - name and positions string name = root.Attributes["name"].Value; int x = int.Parse(root.Attributes["x"].Value); int y = int.Parse(root.Attributes["y"].Value); string dungeonName = root.Attributes["currentDungeon"].Value; Characteristics ch = new Characteristics(0,0,0,0); Characteristics cch = new Characteristics(0,0,0,0); Inventory bag = new Inventory(0); Inventory equiped = new Inventory(0); string[] b = new string[6]; foreach (XmlNode node in root.ChildNodes) { string nodeName = node.Name; switch (nodeName) { case "Characteristics": { ch = LoadCharacteristicsFromXml((XmlElement)node); break; } case "CurrentCharacteristics": { cch = LoadCharacteristicsFromXml((XmlElement)node); break; } case "Bag": { bag = LoadInventoryFromXml((XmlElement)node); break; } case "Equiped": { equiped = LoadInventoryFromXml((XmlElement)node); break; } case "Body": { b = LoadBodyFromXML((XmlElement)node); break; } } } Player p = new Player(name, ch, cch, bag.maxsize, x, y); p.bag = bag; p.equiped = equiped; p.SetBody(new Body(b)); p.SetCurrentDungeon(dungeonName); lua.DoFile(filePath + "players/" + p.Name.ToLower() + "/config.lua"); return p; }