캐릭터의 이름을 입력하면 "무기 기술"과 다른 입력 된 문자를 비교하는 툴을 만들려고합니다.캐릭터 통계를 비교하여 미리 결정된 제 3의 값을 산출합니다.
나는 한 쌍의 조건부 검사를 통해 현재 캐릭터와 그 상태를 나타내는 키 쌍을 사용하고 있습니다. 나는 스프레드 시트를 추가하여이 모든 것을 우회 할 수있을 것이라고 생각했지만 "Excel 12.0 Object Library"는 내 COM 목록에 없으므로 대체물을 볼 수 없습니다.
더 좋은 방법이 있나요? 진술이 우아하지 않은 것처럼 보이는 경우.
개체, DataGridView 및 차트를 검색했지만 기대했던 것에서 보았지만 필자가 본 예제에서 볼 수있는 것처럼 약간의 바이올린은 내가 원하는 방식으로 사용할 수 없습니다.
조사 할 조언이나 자료를 찾아 주셔서 감사합니다.
데이터입니다.
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;
}
}
}
}
감사! 그게 진짜 도움이됩니다! – Amicable
[이 사이트] (http://blogs.msdn.com/b/csharpfaq/archive/2004/03/12/what-s-the-difference-between-code-override-code-and-code-new- code.aspx)는이 코드가 실제로 무엇을했는지 알 수있게 도와주었습니다. ;디 – Amicable