public void AddPlayer(Player p) { PlayerTreeNode q = new PlayerTreeNode(p); playerList.Nodes.Add(q); playerList.NodeMouseDoubleClick += (object sender, TreeNodeMouseClickEventArgs e) => { ((PlayerTreeNode)e.Node).Player.GetPane(this).Show(); }; }
public PlayerStatsPane(MainUI parent, Player p) { InitializeComponent(); this.Player = p; this.ParentUI = parent; updateStats(); }
public void AddPlayer(Player p) { this.Grid[p.x, p.y] = p; this.Refresh(); }
public PlayerTreeNode(Player p) : base(p.Name) { Player = p; }
public static Player[] loadGame(String fileName) { var startTime = DateTime.Now; //Will only be here if file is valid already StreamReader reader = new StreamReader(fileName); int lineCount = File.ReadAllLines(fileName).Length; Player[] arr = new Player[lineCount]; string[] sarr = new string[lineCount]; //reads in all lines as a big string for each string temp; var j = 0; while ((temp = reader.ReadLine()) != null) { sarr[j] = temp; j++; } reader.Close(); //done with reading var i = 0; //need to parse lines into player info foreach (string s in sarr) { string[] dataArr = new string[18]; dataArr = s.Split('-'); arr[i] = new Player(); arr[i].setName(dataArr[0]); //name arr[i].setClass(dataArr[1]); //class arr[i].setLevel(int.Parse(dataArr[2])); //level arr[i].setHP(int.Parse(dataArr[3])); //HP arr[i].setMP(int.Parse(dataArr[4])); //MP arr[i].setGold(int.Parse(dataArr[5])); //Gold arr[i].getGear().setHeadgear(dataArr[6]); //headgear arr[i].getGear().setArmor(dataArr[7]); //Armor arr[i].getGear().setShoes(dataArr[8]); //shoes arr[i].getGear().setGloves(dataArr[9]); //gloves arr[i].getGear().setAccessory(dataArr[10]); //accessory arr[i].getGear().setJewlery(dataArr[11]); //jewlery arr[i].getGear().setLeftHand(dataArr[12]); //Weapon1 arr[i].getGear().setRightHand(dataArr[13]); //Weapon2 arr[i].getGear().setEtc(dataArr[14]); //Shield arr[i].getStats().setSTR(int.Parse(dataArr[15])); //STR arr[i].getStats().setDEX(int.Parse(dataArr[16])); //DEX arr[i].getStats().setCON(int.Parse(dataArr[17])); //CON arr[i].getStats().setINT(int.Parse(dataArr[18])); //INT arr[i].getStats().setWIS(int.Parse(dataArr[19])); //WIS arr[i].getStats().setCHA(int.Parse(dataArr[20])); //CHA i++; } var totalSeconds = (DateTime.Now - startTime).TotalSeconds; Console.WriteLine("{0} loaded in {1} seconds.", fileName, totalSeconds); return arr; }
public Player[] gameInit() { Player[] Arr; Console.ForegroundColor = ConsoleColor.Yellow; bool loadStatus = UI.Agree("Would you like to load a previous save file?"); if (loadStatus) //if user wants to load then give options and load chosen one { //http://stackoverflow.com/questions/14877237/getting-all-file-names-from-a-folder-using-c-sharp string[] fileArray = Directory.GetFiles(@"C:\Users\Chris\repos\DnD\DnD\bin\Debug\", "*.txt", SearchOption.AllDirectories); Console.ForegroundColor = ConsoleColor.Red; foreach (String s in fileArray) //parses and prints out all text files already in project { string temp = s.Substring(s.IndexOf("g") + 2); string r = temp.Replace(".txt", ""); Console.Write(String.Format("{0,-15}", r)); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; string fileName = UI.PromptLine("What game would you like to load?\n"); while (!File.Exists(@"C:\Users\Chris\repos\DnD\DnD\bin\Debug\" + fileName + ".txt")) //if file doesn't exist in case of typo { if (fileName == "") { fileName = UI.PromptLine("No file chosen. What game would you like to load?\n"); } if (fileName == "q") //option to quit to not get stuck in menu { bool quitStatus = UI.Agree("Are you sure that you want to quit?"); if (quitStatus) { Environment.Exit(-1); } else { fileName = UI.PromptLine("What game would you like to load?\n"); } } Console.WriteLine("File: " + fileName + ".txt does not exist. Please enter a valid file name, start a new game, or type 'q' to quit.\n"); fileName = UI.PromptLine("What game would you like to load?\n"); } //if here then ok to load file and exists Arr = Loader.loadGame(fileName + ".txt"); } else //if user chose to make a new instance of game { int playerCount = UI.PromptInt("How many adventurers are playing?\n"); Arr = new Player[playerCount]; Console.WriteLine(); for (int i = 0; i < playerCount; i++) { Player p = new Player(); p.setName(UI.PromptLine("What is player " + (i + 1) + "s name?\n")); p.setClass(UI.PromptLine("What is player " + (i + 1) + "s class?\n")); Console.WriteLine(); Arr[i] = p; } } printWelcome(); Console.WriteLine(); return Arr; }