0
让我开始我到目前为止。这里是我的3类:岩石纸剪刀阵列应用程序C#
class Program
{
static void Main(string[] args)
{
Game rps = new Game();
rps.printHeader();
rps.gameStart();
}
}
class GameDetails
{
public string Name;
public int game;
public GameDetails()
{
Name = "unknown";
game = 0;
}
}
class Game
{
string name;
int numPlays;
int game;
GameDetails[] gameArray;
public int NumGames
{
get
{
return numPlays;
}
set
{
numPlays = value;
}
}
public void printHeader()
{
Console.WriteLine("Welcome to rock, paper, scissors");
this.userSettings();
}
private void InitializeArrays()
{
gameArray = new GameDetails[game];
for (int game = 0; game < numPlays; game++)
{
gameArray[game] = new GameDetails();
}
}
public void userSettings()
{
Console.WriteLine("What is your name: ");
name = Console.ReadLine();
Console.WriteLine("How many games would you like to play?: ");
Int32.TryParse(Console.ReadLine(), out numPlays);
while (numPlays < 10 && numPlays % 2 == 0)
{
Console.WriteLine("\nNumber is not odd try again.");
Console.WriteLine("How many games would you like to play?: ");
Int32.TryParse(Console.ReadLine(), out numPlays);
}
}
public void gameStart()
{
for (game = 1; game <= numPlays; game++)
Console.WriteLine("Please choose Rock, Paper, or Scissors");
string userSelection = Console.ReadLine();
Random r = new Random();
int computerSelection = r.Next(4);
if (computerSelection == 1)
{
if (userSelection == "rock")
{
Console.WriteLine("Computer Choice: Rock\n");
Console.WriteLine("Game [{0}] is a tie", game);
}
else if (userSelection == "paper")
{
Console.WriteLine("Computer Choice: Paper\n");
Console.WriteLine("Game[{ 0}] is a tie", game);
}
else if (userSelection == "scissors")
{
Console.WriteLine("Computer Choice: Scissors\n");
Console.WriteLine("Game [{0}] is a tie", game);
}
else
{
Console.WriteLine("You must choose either rock, paper or scissors");
}
}
else if (computerSelection == 2)
{
if (userSelection == "rock")
{
Console.WriteLine("Computer Choice: Paper\n");
Console.WriteLine("You lose game [{0}], papaer beats rock", game);
}
else if (userSelection == "paper")
{
Console.WriteLine("Computer Choice: Scissors\n");
Console.WriteLine("You lose game [{0}], scissors beats paper", game);
}
else if (userSelection == "scissors")
{
Console.WriteLine("Computer Choice: Rock\n");
Console.WriteLine("You lose game [{0}], Rock beats scissors", game);
}
else
{
Console.WriteLine("You must choose either rock, paper or scissors");
}
}
else if (computerSelection == 3)
{
if (userSelection == "rock")
{
Console.WriteLine("The computer chose scissors");
Console.WriteLine("You win game [{0}], rock beats scissors", game);
}
else if (userSelection == "paper")
{
Console.WriteLine("The computer chose rock");
Console.WriteLine("You win game [{0}],paper beats rock", game);
}
else if (userSelection == "scissors")
{
Console.WriteLine("The computer chose paper");
Console.WriteLine("You win game [{0}], scissors beats paper!", game);
}
else
{
Console.WriteLine("You must choose either rock, paper or scissors");
}
Console.ReadLine();
// int arrayIndex = game - 1;
// gameArray[arrayIndex].Result = game;
// }
// }
//public override string ToString()
//{
// string outputString = game + "\n";
// for (int game = 1; game < numPlays; game++)
// {
// int index = game - 1;
// outputString += "Game " + game + ":" + gameArray[index].Result + "\n";
// }
// return outputString;
//}
}
}
}
我需要这个程序只为游戏指定数量的运行,确定一个最佳的(数选择游戏)系列的赢家,并显示每场比赛的结果。我没有收到任何错误,但是当我运行代码时,它要求提供名称和多少游戏。在我选择玩多少游戏之后,它会显示“请选择摇滚,纸张或剪刀”,其数量与我选择的游戏数量相同。我该如何正确计数游戏数量,确定赢家,并显示正确的输出。
哎哟,随机里面一个for循环。不是很随意http://dilbert.com/strip/2001-10-25 – Steve
感谢您输入@Nico。 –
@Steve好点,没看见.. – Nico