【发布时间】:2014-08-30 20:46:14
【问题描述】:
///TEAM PICKING APP帮助Dota 2选秀///
表单上的对象:
- 英雄列表框
- team1ListBox
- team2ListBox
- 添加Team1Button
- 添加Team2Button
- 标签放置在每个团队的列表框下方
我有一个名为英雄的班级。 Hero 的每个实例都有布尔值和一个字符串作为其名称。布尔值跟踪该英雄能力的属性,例如他是否有远程攻击。
在我的 MainForm 上,有一个列表框,其中包含所有可用的英雄。您选择一个英雄,然后按下两个按钮之一:将对象发送到Team 1 的列表框或Team 2 的列表框的按钮。每个团队的列表框下方是记录该团队能力的标签,例如团队列表框中有多少 英雄 具有远程攻击。每次您按下该团队的按钮时,该团队的标签都会更新。
我认为我能够将对象从一个列表移动到另一个列表。但是每次你按下发送的两个按钮之一时,我都无法让计数工作:
public class Hero {
public string Name;
public bool IsInitiator;
public bool IsTank;
public bool IsNuker;
public bool IsCarry;
public bool IsPusher;
public bool IsRanged;
public bool IsGreedy;
public bool IsAOE;
public bool IsDisabler;
public bool IsRat;
public Hero(string tempName){
Name = tempName;
IsInitiator = false;
IsTank = false;
IsNuker = false;
IsCarry = false;
IsPusher = false;
IsRanged = false;
IsGreedy = false;
IsAOE = false;
IsDisabler = false;
IsRat = false;
}
public override string ToString()
{
return Name;
}
}
public partial class MainForm : Form
{
public int rcounter;
public int dcounter;
List<Hero> rHeroes = new List<Hero>();
List<Hero> dHeroes = new List<Hero>();
public MainForm()
{
InitializeComponent();
//只是一个示例英雄
Hero Abbadon = new Hero("Abbadon");
Abbadon.IsCarry=true;
Abbadon.IsGreedy=true;
Abbadon.IsTank=true;
heroList.Items.Add(Abbadon);
}
//添加到team1 ...又名Radiant。更新那些标签文本!
void addTeam1ButtonClick(object sender, EventArgs e)
{
rcounter++;
rHeroes.Add(heroList.SelectedItem as Hero);
team1List.Items.Add(heroList.SelectedItem);
heroList.Items.Remove(heroList.SelectedItem);
for (int i = 0; i == rcounter; i++)
{
int rangedCounts = 0;
if (rHeroes[i].IsTank == true){
rangedCounts++;
}
radiantRangedLabel.Text = rangedCounts.ToString();
}
}
}
【问题讨论】:
标签: c# class validation parameter-passing listboxitems