using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignProject
{
class Art
{
public string name { get; set; }
public int id { get; set; }
public int power { get; set; }
public int byteLength { get { return (4 + Encoding.GetEncoding("Shift_JIS").GetBytes(this.name).Length + 4 * 2); } }
public Art(string name, int id, int power)
{
this.name = name;
this.id = id;
this.power = power;
}
public Art(byte[] data)
{
int index = 0;
int nameLength = BitConverter.ToInt32(data, index);
index += 4;
byte[] namebyte = new byte[nameLength];
Array.ConstrainedCopy(data, index, namebyte, 0, nameLength);
Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
this.name = sjisEnc.GetString(namebyte);
index += nameLength;
this.id = BitConverter.ToInt32(data, index);
index += 4;
this.power = BitConverter.ToInt32(data, index);
}
public byte[] ToByte()
{
Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
byte[] strbytes = sjisEnc.GetBytes(this.name);
byte[] data = new byte[4 + strbytes.Length + 4 * 2];
int index = 0;
byte[] temp = BitConverter.GetBytes(strbytes.Length);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
Array.ConstrainedCopy(strbytes, 0, data, index, strbytes.Length);
index += strbytes.Length;
temp = BitConverter.GetBytes(this.id);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.power);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
return (data);
}
public string DrawString()
{
return(this.name + "," + this.id + "," + this.power);
}
}
class Character
{
public string name { get; set; }
public int imageID { get; set; }
public int Life { get; set; }
public int LifeMax { get; set; }
public int attack { get; set; }
public int defence { get; set; }
public int speed { get; set; }
public List<Art> arts { get; private set; }
public int artsByteLength {
get {
if (this.arts != null)
{
return (
this.arts[0].byteLength
+ this.arts[1].byteLength
+ this.arts[2].byteLength
+ this.arts[3].byteLength
);
}
else
{
return (0);
}
}
}
public Character(string name, int imageID, int LifeMax, int atk, int def,int spd)
{
this.name = name;
this.imageID = imageID;
this.Life = LifeMax;
this.LifeMax = LifeMax;
this.attack = atk;
this.defence = def;
this.speed = spd;
this.arts = new List<Art>();
}
public Character(Byte[] data)
{
int index = 0;
int strLength = BitConverter.ToInt32(data, index);
index += 4;
byte[] temp = new byte[strLength];
Array.ConstrainedCopy(data, index, temp, 0, strLength);
Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
this.name = sjisEnc.GetString(temp);
index += strLength;
this.imageID = BitConverter.ToInt32(data, index);
index += 4;
this.Life = BitConverter.ToInt32(data, index);
index += 4;
this.LifeMax = BitConverter.ToInt32(data, index);
index += 4;
this.attack = BitConverter.ToInt32(data, index);
index += 4;
this.defence = BitConverter.ToInt32(data, index);
index += 4;
this.speed = BitConverter.ToInt32(data, index);
index += 4;
this.arts = new List<Art>();
for (int i = 0; i < 4; ++i)
{
strLength = BitConverter.ToInt32(data, index);
temp = new byte[4 + strLength + 4 * 2];
Array.ConstrainedCopy(data, index, temp, 0, 4 + strLength + 4 * 2);
this.arts.Add(new Art(temp));
index = index + 4 + strLength + 4 * 2;
}
}
public byte[] ToByte()
{
Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
byte[] strbytes = sjisEnc.GetBytes(this.name);
byte[] data = new byte[4 + strbytes.Length + 4 * 6 + this.artsByteLength];
int index = 0;
byte[] temp = BitConverter.GetBytes(strbytes.Length);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
Array.ConstrainedCopy(strbytes, 0, data, index, strbytes.Length);
index += strbytes.Length;
temp = BitConverter.GetBytes(this.imageID);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.Life);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.LifeMax);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.attack);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.defence);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
temp = BitConverter.GetBytes(this.speed);
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
for (int i = 0; i < this.arts.Count; ++i)
{
temp = this.arts[i].ToByte();
Array.ConstrainedCopy(temp, 0, data, index, temp.Length);
index += temp.Length;
}
return(data);
}
public string DrawString()
{
return(
this.name + "," +
this.imageID + "," +
this.Life + "," +
this.LifeMax + "," +
this.attack + "," +
this.defence + "," +
this.speed
);
}
}
}
最終更新:2010年12月22日 16:28