0

///TEAM PICKING APP帮助Dota 2选秀///

表格上的对象:

  1. 英雄列表框
  2. team1列表框
  3. team2ListBox
  4. addTeam1Button
  5. addTeam2Button
  6. 标签放置在每个团队的列表框下方

我有一个名为Hero的课程。Hero的每个实例都有布尔值和一个字符串作为其名称。布尔值跟踪该Hero能力的属性,例如他是否有远程攻击。

在我的 MainForm 上,有一个包含所有可用 hero 的列表。您选择一个英雄,然后按下两个按钮之一:将对象发送到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();
        }
    }

}
4

1 回答 1

1

您正在为每个英雄设置团队计数的标签,因此它将始终显示 1 或 0,具体取决于循环中检查的最后一个英雄...

将变量 rangedCounts 移到循环外

于 2014-08-30T20:58:31.643 回答