私はこれを簡単なダイスゲームとして書きました。最初の2回の反復で応答がなく、3回反復することを除いて、希望どおりに機能します。3回目の質問と回答では、出力が表示されます。
私のコードのどこが問題なのかわかりません、私はそれを何度も繰り返しました.... lol any help =)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* I am very confused but for soem reason it only returns a value every 3 tries....I dont understand
* I looked through the program and the only thing that occurs 3 times is the if else if else if statement
* but I dont see how that would do it....
*/
namespace Lab11
{
class Program
{
static void Main(string[] args)
{//declared constants
const int NUM_1 = 1;
const int NUM_6 = 6;
Console.WriteLine("\t\t\tWelcome To a Game of Dice!");
//Do while statement repeating the "roll again" question and performing the random numbers
do
{
Again();
Random ran = new Random();
//if else if else if statement doing the random numbers and telling you rolled snake or box
if (Again() == true)
{
int num1 = ran.Next(1, 7);
int num2 = ran.Next(1, 7);
//if else statement determining the output for each roll in the console.
if (num1 == NUM_6 && num2 == NUM_6)
{
Console.WriteLine("\nYou Rolled BoxCars");
}
else if (num1 == NUM_1 && num2 == NUM_1)
{
Console.WriteLine("\nYou rolled Snake-Eyes");
}
else
{
Console.WriteLine("\nYou Rolled...{0} and {1}", num1, num2);
}
}
} while (Again() == true);
//Goodbye if you press 'n'
Console.WriteLine("\n\nGoodBye");
Console.ReadLine();
}
//the yes or no method asking if you want to play again
//this is where I think the issue is but I dont see where or how....
static bool Again()
{
char response;
Console.Write("\n\nWould you like to roll the dice (y or n)? ");
response = char.Parse(Console.ReadLine());
response = char.ToLower(response);
if (response == 'y')
return true;
else
return false;
}
}
}