首先了解C#赛车跑道代码部分 [英] Head first C# race track code part
问题描述
Guy Bettors = new Guy[3];
Bettors[0]=new Guy();
Bettors[0].Name="Joe";
Bettors[1]=new Guy();
Bettors[1].Name="Bob";
Bettors[2]=new Guy();
Bettors[2].Name="Al"
if (winner != (int)numericUpDownDog.Value)
{
Bettors[0].Cash -= Bettors[0].MyBet.Amount;
Bettors[0].UpdateLabels();
}
else
{
Bettors[0].Cash += Bettors[0].MyBet.Amount;//Add the amount bet to the Cash so the guy is able to change his bet
Bettors[0].UpdateLabels();
}
上面的代码是joe的工作代码.
起作用的计时器代码使4条狗赛跑到终点,并且随机选择获胜者,谁首先越过赛道的终点,则该代码对我来说确实很好,并且获胜者的1,2,3或4值被保存为变量".赢家" .numericUpDownDog
值也是1或2或3或4号狗.我正在尝试使某物进入循环或某个变量以保存Bettor [1]或Betters [0]或Betters [2],以便执行的代码将是其中之一下面的代码.
The above code is working code for joe.
Timer code that works to race the 4 dogs to the endline and the winner is randomly selected who crosses the endline of racetrack first that code works really well for me and the winner dog 1,2,3 or 4 value gets saved for variable "winner".numericUpDownDog
value is also 1 or 2 or 3 or 4 th dog.I am trying to achieve somethin to put in a loop or somevariable to save Bettor[1] or Betters[0] or betters[2] so that executed code will be either one of below code.
if (winner != (int)numericUpDownDog.Value)
{
Bettors[0].Cash -= Bettors[0].MyBet.Amount;
Bettors[0].UpdateLabels();
}
else
{
Bettors[0].Cash += Bettors[0].MyBet.Amount;//Add the amount bet to the Cash so the guy is able to change his bet
Bettors[0].UpdateLabels();
}
or
if (winner != (int)numericUpDownDog.Value)
{
Bettors[1].Cash -= Bettors[1].MyBet.Amount;
Bettors[1].UpdateLabels();
}
else
{
Bettors[1].Cash += Bettors[1].MyBet.Amount;//Add the amount bet to the Cash so the guy is able to change his bet
Bettors[1].UpdateLabels();
}
or
if (winner != (int)numericUpDownDog.Value)
{
Bettors[2].Cash -= Bettors[2].MyBet.Amount;
Bettors[2].UpdateLabels();
}
else
{
Bettors[2].Cash += Bettors[2].MyBet.Amount;//Add the amount bet to the Cash so the guy is able to change his bet
Bettors[2].UpdateLabels();
}
请以书面形式指导我,下注者将是joe或bob或al.
please direct me in the kind of writing the code the bettor will be either joe or bob or al.
推荐答案
private void UpdateWinner(Guy guy)
{
if (winner != (int)numericUpDownDog.Value) {
guy.Cash -= guy.MyBet.Amount;
guy.UpdateLabels();
}
else
{
guy.Cash += guy.MyBet.Amount;
guy.UpdateLabels();
}
}
这篇关于首先了解C#赛车跑道代码部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!