public void createCharacter(string Class, string name) { int hp = 0; int mp = 0; int white = 0; int dark = 0; int damage = 1; if (Class == "Warrior") { hp = ran.Next(5) + 10; damage = ran.Next(3) + 5; } else if (Class == "Mage") { hp = ran.Next(2) + 4; mp = ran.Next(3) + 2; dark = ran.Next(3) + 6; } else if (Class == "Ranger") { hp = ran.Next(3) + 6; damage = ran.Next(4) + 6; } else if (Class == "Necromancer") { hp = ran.Next(2) + 3; mp = ran.Next(3) + 5; dark = ran.Next(2) + 4; white = ran.Next(3) + 2; } else if (Class == "Rogue") { hp = ran.Next(4) + 4; mp = ran.Next(2) + 1; damage = ran.Next(3) + 4; dark = ran.Next(5) + 2; } else if (Class == "Healer") { hp = ran.Next(3) + 4; mp = ran.Next(3) + 2; damage = ran.Next(4) + 3; white = ran.Next(5) + 6; } character ch1 = new character(hp, mp, Class, name, white, dark, damage); Save.JSONSeralize(ch1); //Application.Restart(); Close(); }
public world() { InitializeComponent(); player = Save.getCharacter(); PlayerStats.Text = player.printInfo(); if (!player.TutorialComplete) { player.tree = 1; AdventureDialogue.Text = "do you want to do the tutorial? (you will get bonus exp for doing so)"; } }
public static void JSONSeralize(character ch) { string filename = ch.Name + ".json"; string file = ""; DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo("saves"); FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles(); foreach (FileInfo foundFile in filesInDir) { string fullName = foundFile.FullName; file = foundFile.Name; } if (file == filename) { MessageBox.Show("You can't have the same name twice"); } else { File.WriteAllText("saves\\" + filename, JsonConvert.SerializeObject(ch)); } }
public static void JSONDeseralize(string name) { ch1 = JsonConvert.DeserializeObject <character>(File.ReadAllText("saves\\" + name)); }