private void button1_Click(object sender, EventArgs e) { c = new Character((CharacterID)cboCharTypes.SelectedIndex); c.ID = (uint)numID.Value; c.Location = new Point((int)this.numXPos.Value, (int)this.numYPos.Value); this.DialogResult = DialogResult.OK; this.Close(); }
void AddGameCharToList(Character character) { ListViewItem lvi = new ListViewItem(((CharacterID)character.TypeData.TypeID).ToString()); lvi.Tag = character; lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, character.ID.ToString())); lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, character.Location.X.ToString())); lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, character.Location.Y.ToString())); lvwChars.Items.Add(lvi); }
public void Open() { StreamReader sr = new StreamReader(this.Filename); BinaryReader bread = new BinaryReader(sr.BaseStream); /* Verifica o magic number */ byte[] magic = bread.ReadBytes(4); if (magic[0] != 'W' || magic[1] != 'E' || magic[2] != 'R' || magic[3] != 'L') { throw new InvalidMapException(); } /* Lê os metadados */ this.Width = bread.ReadUInt32(); this.Height = bread.ReadUInt32(); this.offData = bread.ReadUInt32(); this.offChars = bread.ReadUInt32(); this.PlayerX = bread.ReadUInt32(); this.PlayerY = bread.ReadUInt32(); if (this.Width == 0) throw new InvalidMapException(); if (this.Height == 0) throw new InvalidMapException(); /* Lê os dados do mapa */ this.Elements = new int[this.Width * this.Height]; bread.BaseStream.Seek(this.offData, SeekOrigin.Begin); for (uint y = 0; y < this.Height; y++) { for (uint x = 0; x < this.Width; x++) { Elements[y * this.Width + x] = bread.ReadInt32(); } } /* Lê os characters do mapa */ bread.BaseStream.Seek(this.offChars, SeekOrigin.Begin); uint count = bread.ReadUInt32(); for (int i = 0; i < count; i++) { uint elsize = bread.ReadUInt32(); uint tid, objid, xpos, ypos, hp; if (elsize >= 20) { tid = bread.ReadUInt32(); objid = bread.ReadUInt32(); xpos = bread.ReadUInt32(); ypos = bread.ReadUInt32(); hp = bread.ReadUInt32(); bread.BaseStream.Seek((elsize - 20), SeekOrigin.Current); } else { /* Elementos com size < 20 não suportados */ throw new InvalidMapException(); } Character ch = new Character((CharacterID)tid); ch.ID = objid; ch.Location = new System.Drawing.Point((int)xpos, (int)ypos); ch.HP = (int)hp; this.CharacterList.Add(ch); } bread.Close(); }