我正在尝试将另一个方法中的变量调用到我的数组中。 var Com =游戏的难度。但下面的方法是我尝试调用var Com,因为:var c = Com.GetChoice();
不知道为什么我无法弄清楚如何调用它。
public object SetDiff()
{
Console.WriteLine("Enter difficulty #: (1 = Easy, 2 = Normal, 3 = Impossible)");
var diff = Console.ReadLine();
int mode;
int.TryParse(diff, out mode);
if (mode == 1)
{
Console.Clear();
var Com = new Easy();
return Com;
}
if (mode == 2)
{
Console.Clear();
var Com = new Medium();
return Com;
}
if (mode == 3)
{
Console.Clear();
var Com = new Hard();
return Com;
}
else
{
Console.WriteLine("That is not a valid input.");
return SetDiff();
}
} // Apparently you can't set variables in a switch.
public int[] FaceOff(int num)
{
int PlayerWin = 0;
int ComWin = 0;
int Tie = num + 1;
// TODO : Get rid of TIES!
for (int i = 0; i < num; i++)
{
var p = p1.GetChoice();
var c = Com.GetChoice();
答案 0 :(得分:0)
您有许多不同的选择:
传递参数
public int[] FaceOff(int num, int Com){...}
制作一个&#34;全球&#34;变量强>
private int Com;
我还建议你学习OOP(面向对象编程)的基础知识。