-3
私は自分自身と私の家族のためにMenuStripを戦闘のアクションコマンドとして使用しています。しかし、私は魔法のClick機能をどのようにセットアップするのかを決めることはできません。 menustripはほとんど空白から始まるので、私は呪文とターゲットのリストを作成することも、それらの呪文のクリックメソッドを設定することもできません。私はあなたがサブクラスにあなたのコードを分割開始すべきだと思う...行き詰まりのビットでMenuStripItemのクリックメソッドを設定するにはどうすればいいですか?
string[] Spells = { };
string[] Elements = { };
string[] Targets = { };
double[] Power = { };
double[] ManaCost = { };
StreamReader strReader = null;
try
{
FileStream flsStream = new FileStream(Application.StartupPath + "\\Spells.txt", FileMode.Open, FileAccess.Read);
strReader = new StreamReader(flsStream);
while (strReader.Peek() != -1)
{
string line = strReader.ReadLine();
string[] lines = line.Split(':');
Array.Resize(ref Spells, Spells.Length + 1);
Array.Resize(ref Elements, Elements.Length + 1);
Array.Resize(ref Targets, Targets.Length + 1);
Array.Resize(ref Power, Power.Length + 1);
Array.Resize(ref ManaCost, ManaCost.Length + 1);
Spells[Spells.Length - 1] = lines[0];
Elements[Elements.Length - 1] = lines[1];
Targets[Targets.Length - 1] = lines[2];
Power[Power.Length - 1] = Convert.ToDouble(lines[3]);
ManaCost[ManaCost.Length - 1] = Convert.ToDouble(lines[4]);
}
for (int x = 0; x < Spells.Length; x++)
{
mnuMagic.DropDownItems.Add(Spells[x]);
mnuMagic.DropDownItems[x].Name = string.Format("tsmi{0}", Spells[x]);
mnuMagic.DropDownItems[x].Text += string.Format(", {0} MP", ManaCost[x]);
if (Targets[x] == "Single")
{
try
{
if (Foe1.Status != "Dead")
{
if (Foe1.Health > Foe1.MaxHealth/2)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe1, imgEnemyStatus.Images[0]);
else if (Foe1.Health > Foe1.Health/4)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe1, imgEnemyStatus.Images[1]);
else
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe1, imgEnemyStatus.Images[2]);
}
if (Foe2.Status != "Dead")
{
if (Foe2.Health > Foe2.MaxHealth/2)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe2, imgEnemyStatus.Images[0]);
else if (Foe2.Health > Foe2.Health/4)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe2, imgEnemyStatus.Images[1]);
else
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe2, imgEnemyStatus.Images[2]);
}
if (Foe3.Status != "Dead")
{
if (Foe3.Health > Foe3.MaxHealth/2)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe3, imgEnemyStatus.Images[0]);
else if (Foe3.Health > Foe3.Health/4)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe3, imgEnemyStatus.Images[1]);
else
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe3, imgEnemyStatus.Images[2]);
}
if (Foe4.Status != "Dead")
{
if (Foe4.Health > Foe4.MaxHealth/2)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe4, imgEnemyStatus.Images[0]);
else if (Foe4.Health > Foe4.Health/4)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe4, imgEnemyStatus.Images[1]);
else
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe4, imgEnemyStatus.Images[2]);
}
if (Foe5.Status != "Dead")
{
if (Foe5.Health > Foe5.MaxHealth/2)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe5, imgEnemyStatus.Images[0]);
else if (Foe5.Health > Foe5.Health/4)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe5, imgEnemyStatus.Images[1]);
else
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(strFoe5, imgEnemyStatus.Images[2]);
}
}
catch { }
}
else if (Targets[x] == "Ally")
{
try
{
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(Fighter1.Name,imgEnemyStatus.Images[0]);
if (Fighter2.Name != null)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(Fighter2.Name);
if (Fighter3.Name != null)
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add(Fighter3.Name);
}
catch { }
}
else if (Targets[x] == "All")
{
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add("All Enemies");
}
else if (Targets[x] == "Team")
(mnuMagic.DropDownItems[x] as ToolStripMenuItem).DropDownItems.Add("All Allies");
if (Elements[x] == "Fire")
mnuMagic.DropDownItems[x].ForeColor = Color.Red;
else if (Elements[x] == "Water")
mnuMagic.DropDownItems[x].ForeColor = Color.Blue;
else if (Elements[x] == "Earth")
mnuMagic.DropDownItems[x].ForeColor = Color.FromArgb(255, 128, 0);
else if (Elements[x] == "Wind")
mnuMagic.DropDownItems[x].ForeColor = Color.LimeGreen;
if (ManaCost[x] > Fighter1.Mana) { mnuMagic.DropDownItems[x].Enabled = false; }
}
}
catch { }
}
あなたが試したこと、使用中のコード、スクリーンショットがうまくいかないことを教えてください。 – Nico