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;
//}
}
}
}
私は、ゲームの指定された数のために実行シリーズ(選択したゲームの数)の最高の勝者を決定し、各ゲームの結果を表示するには、このプログラムが必要です。私はエラーを受け取っていませんが、コードを実行すると、名前とゲームの数が尋ねられます。プレイするゲームの数を選択したら、ゲームの量を選んだ回数と同じ回数「ロック、ペーパー、はさみを選んでください」と表示されます。どのようにすれば、ゲームの数を正確に数え、勝者を決定し、正しい出力を表示することができますか?
ためrepeatadly痛い、ランダムにゲームを実行する必要があります。非常にランダムではありませんhttp://dilbert.com/strip/2001-10-25 – Steve
入力いただきありがとうございます。 –
@Steve良い点は、それも参照してください... – Nico