Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 比较字符统计信息以产生预定的第三个值_C#_.net_Visual Studio 2010_C# 4.0 - Fatal编程技术网

C# 比较字符统计信息以产生预定的第三个值

C# 比较字符统计信息以产生预定的第三个值,c#,.net,visual-studio-2010,c#-4.0,C#,.net,Visual Studio 2010,C# 4.0,我试图创建一个工具,当输入一个角色的名字时,它会将他们的“武器技能”与其他输入的角色进行比较 我使用一个密钥对来表示角色及其当前状态,并通过一系列条件检查来运行它。我想我可以通过添加一个电子表格来规避所有这些问题,但是“Excel12.0对象库”不在我的COM列表中,我看不到任何替换项 有更好的方法吗?如果语句看起来不雅 我已经搜索过对象,DataGridView和Chart听起来很有希望,但就我所看到的示例和一些小提琴而言,它们无法按照我的意愿使用 如果您有任何建议或事情需要调查,我们将不胜感

我试图创建一个工具,当输入一个角色的名字时,它会将他们的“武器技能”与其他输入的角色进行比较

我使用一个密钥对来表示角色及其当前状态,并通过一系列条件检查来运行它。我想我可以通过添加一个电子表格来规避所有这些问题,但是“Excel12.0对象库”不在我的COM列表中,我看不到任何替换项

有更好的方法吗?如果语句看起来不雅

我已经搜索过对象,DataGridView和Chart听起来很有希望,但就我所看到的示例和一些小提琴而言,它们无法按照我的意愿使用

如果您有任何建议或事情需要调查,我们将不胜感激

数据

    1   2   3   4   5   6   7   8   9   10
1   4   4   5   6   6   6   6   6   6   6
2   3   4   4   4   5   5   6   6   6   6
3   2   3   4   4   4   4   5   5   6   6
4   2   3   3   4   4   4   4   4   5   5
5   2   2   3   3   4   4   4   4   4   4
6   2   2   3   3   3   4   4   4   4   4
7   2   2   2   3   3   3   4   4   4   4
8   2   2   2   3   3   3   3   4   4   4
9   2   2   2   2   3   3   3   3   4   4
10  2   2   2   2   3   3   3   3   3   4
我的密码

namespace ThereIsOnlyRules
{
public partial class Calculator : Form
{
    public Calculator()
    {
        InitializeComponent();
    }

    StoreVariables test = new StoreVariables();

    private void Form1_Load(object sender, EventArgs e)
    {

        test.doWork();
    }
    private void button1_Click(object sender, EventArgs e)
    {

        lblwinner.Text = "";
        string attackCharacter = attackBox.Text;
        string opponentCharacter = opponentBox.Text;
        string toHitRoll = test.ToHit(attackCharacter, opponentCharacter);
        lblwinner.Text = toHitRoll;

    }
}
public class StoreVariables
{
    public Dictionary<string, int> attacker = new Dictionary<string, int>();
    public Dictionary<string, int> opponent = new Dictionary<string, int>();
    //string attackUnit { get; set; }
    //string opponentUnit { get; set; }
    int weaponSkill { get; set; }
    public void doWork()
    {
        Attacker();
        Opponent();
        //ToHit();
    }
    private void Attacker()             
    {
        attacker.Add("Warrior", 3);
        attacker.Add("Destroyer", 4);
        attacker.Add("Reaver", 9);
        attacker.Add("Killer", 10);
    }
    private void Opponent()
    {
        opponent.Add("Warrior", 3);
        opponent.Add("Destroyer", 4);
        opponent.Add("Reaver", 9);
        opponent.Add("Killer", 10);
    }
    public string ToHit(string attackerName, string opponentName)
    {
        string toHit = "0";

        int value;
        int AWS = 0;
        int OWS = 0;
        if (attacker.TryGetValue(attackerName, out value))
        {
            AWS = value;
        }
        if (opponent.TryGetValue(opponentName, out value))
        {
            OWS = value;
        }

        if (OWS == 10)
        {
            if (AWS >= 5)
            {
                toHit = "4+";
                return toHit;
            }
            else if (AWS <= 4)
            {
                toHit = "5+";
                return toHit;
            }
            else
            {
                return null;
            }
        }
        else if (OWS == 9)
        {
            if (AWS == 10)
            {
                toHit = "3+";
                return toHit;
            }
            else if (AWS >= 5)
            {
                toHit = "4+";
                return toHit;
            }
            else if (AWS <= 4)
            {
                toHit = "5+";
                return toHit;
            }
            else
            {
                return "I haven't implemented the rest yet, choose Killer as opponent";
            }
        }
        else
        {
            return null;
        }
    }
}
}
namespace-ThereIsOnlyRules
{
公共部分类计算器:表单
{
公共计算器()
{
初始化组件();
}
StoreVariables测试=新的StoreVariables();
私有void Form1\u加载(对象发送方、事件参数e)
{
test.doWork();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
lblwinner.Text=“”;
字符串attackCharacter=attackBox.Text;
字符串opponentCharacter=opponentBox.Text;
字符串toHitRoll=test.ToHit(attackCharacter,opponentCharacter);
lblwinner.Text=toHitRoll;
}
}
公共类存储变量
{
公共字典攻击者=新建字典();
公共字典=新字典();
//字符串攻击单元{get;set;}
//字符串对立面{get;set;}
int武器技能{get;set;}
公共工作
{
攻击者();
对手();
//ToHit();
}
私有无效攻击者()
{
添加(“战士”,3);
添加(“破坏者”,4);
添加(“掠夺者”,9);
添加(“杀手”,10);
}
私人
{
添加(“战士”,3);
添加(“驱逐舰”,4);
对手。添加(“掠夺者”,9);
添加(“杀手”,10);
}
公共字符串ToHit(字符串attackerName、字符串opponentName)
{
字符串toHit=“0”;
int值;
int AWS=0;
int-OWS=0;
if(攻击者.TryGetValue(attackerName,out值))
{
AWS=数值;
}
if(对手.TryGetValue(对手名称,输出值))
{
OWS=价值;
}
如果(OWS==10)
{
如果(AWS>=5)
{
toHit=“4+”;
返回到HIT;
}
否则如果(AWS=5)
{
toHit=“4+”;
返回到HIT;
}

否则,如果(AWSExcel、DataGrid和Chart)与您的问题没有任何共同之处,您必须对其进行编码。您的问题来自于您的程序中没有玩家逻辑

你应该使用OOP来实现这一点。只是一个非常简单的示例来向你展示这个想法(你必须在Player类中执行OWS或其他任何操作):

Game类只显示了用法。通常情况下,您会实现比较运算符或进行其他比较。

帮助我了解了这段代码的实际用途,但对我来说似乎没有那么简单。;D
public abstract class Player : IComparable
{

    public abstract int Skill { get; }

    public int CompareTo(object obj)
    {
        if (obj is Player)
            return this.Skill.CompareTo(((Player) obj).Skill);
        throw new ArgumentException();
    }
}

public class Warrior : Player
{
    public override int Skill
    {
        get { return 3; }
    }
}

public class Destroyer : Player
{
    public override int Skill
    {
        get { return 4; }
    }
}

public class Game
{

    public Player Attacker { get; set; }

    public Player Opponent { get; set; }

    public bool AttackerWins
    {
        get { return Attacker.CompareTo(Opponent) == 1; }
    }

    public bool OpponentWins
    {
        get { return Opponent.CompareTo(Attacker) == 1; }
    }
}