private void addNpcButton_Click(object sender, EventArgs e) { Npc item = new Npc(); item.Name = "Untitled"; this.npcs.Add(item); this.npcListBox.Items.Add(item.Name); }
public static Npc Load(string filePath) { Npc npc = new Npc(); using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate)) { using (BinaryReader binaryReader = new BinaryReader(fs)) { npc.Name = binaryReader.ReadString(); npc.TextureNumber = binaryReader.ReadInt32(); npc.HP = binaryReader.ReadInt32(); npc.MP = binaryReader.ReadInt32(); npc.Strength = binaryReader.ReadInt32(); } } return npc; }
private void LoadNpcs() { this.npcListBox.Items.Clear(); this.npcs = new List<Npc>(); DirectoryInfo dI = new DirectoryInfo(dataPath + "/Npcs/"); foreach (var file in dI.GetFiles("*.dat", SearchOption.TopDirectoryOnly)) { this.npcs.Add(Npc.Load(file.FullName)); this.npcListBox.Items.Add(this.npcs[this.npcs.Count - 1].Name); } if (this.npcs.Count == 0) { Npc npc = new Npc(); npc.Name = "Untitled"; npc.TextureNumber = 0; this.npcs.Add(npc); this.npcListBox.Items.Add(npc.Name); } this.npcListBox.SelectedIndex = 0; this.selectedNpc = this.npcs[this.npcListBox.SelectedIndex]; this.PopulateData(); }
private void npcListBox_SelectedIndexChanged(object sender, EventArgs e) { if (this.npcListBox.SelectedIndex < 0 || this.npcListBox.SelectedIndex > this.npcs.Count) return; this.selectedNpc = this.npcs[this.npcListBox.SelectedIndex]; this.PopulateData(); }