私はプログラミングを試みることに非常に慣れていないため、質問を正しく行う方法さえわかりません。ユーザーがプログラムを終了するときにランダムなカード番号をユーザーに表示できないというエラーがあります。(行 21 を参照してください:Console.WriteLine("\n" + "Your lucky card For today is: " + yourCard[luckyFiftyTwo]));
配列、ランダマイザーなどはすべてメソッド 'Get Fortune' 内に含まれています。
メソッドをスライスして、2 つ目のランダマイザーを入れることはできますが、それを行うにはコード行を繰り返す必要があり、インスタンスを呼び出すことができるはずだと私には思えます (これもわかりません)。私が正しく言っている場合は、お気軽に訂正してください。私は本当に学びたいと思っています - ありがとう) 誰かがプログラムを終了するときまで。したがって、'yourCard[luckyFiftyTwo]' の結果を getFortune メソッドから渡し、magic8ball メソッド内でアクセスできるようにする必要があります。
どんな助けでも大歓迎です。私がやろうとしていることを説明できたことを願っています。繰り返しますが、私は本当に頭が悪く、先生が求めていることの範囲を超えて何かをしようとしています - これは学ぶのに良い方法だと思います (私たちはまだ配列を使用していません - breakCase ステートメントですべてを行うことができます。しかし、配列はより明確でタイトになると思いました)。
今バタバタしてます。助けてください。
コードは次のとおりです。
using System;
namespace a040___Methods_Array___Crazy8ball
{
class Program
{
//test in chunks
public void Magic8ball()
{
Console.WriteLine(" - - - - - - - - = = = = Wisdom of Magic 8 Ball = = = = - - - - - - - - \n \n ");
Console.WriteLine("Would you like to consult the wisdom of the Magic 8 Ball? \n");
PlayAgain();//we do here to ask if they want to play (Y)(N)(?)
do
{
GetFortune();
} while (PlayAgain()); //while they keep wanting to play
Console.WriteLine("Thank you for consulting the wisdom of the Magic 8 Ball.");
Console.WriteLine("\n" + "Your lucky card For today is: " + yourCard[luckyFiftyTwo]);
}
public Boolean PlayAgain()
{
Console.WriteLine("\n" + "Please enter \"Y\" to play, or \"N\" If you would prefer not to continue to play.");
String command = Console.ReadLine().ToLower(); //Read in data
if (command == "y") return true;
if (command == "n") return false;
Console.WriteLine("\n" + "What was that? I'm sorry but the Magic 8 Ball didn't understand your entry.");
return false;
}
public void GetFortune()//produces random results
{
Random rnd = new Random();
int luckyEight = rnd.Next(19); // create random number (0 - 20)
int luckySix = rnd.Next(5); // create random number (0 - 5)
//int luckyFiftyTwo = rnd.Next(1, 52); // create random number (0 - 52)
int luckyFiftyTwo = rnd.Next(53); // create random number (1 - 53)
//type of array - name of array - declaration of array - array size
String[] responses = new String[20];//array is a square bracket
responses[0] = "It is certain.";
responses[1] = "It is decidedly so.";
responses[2] = "Yes definitely.";
responses[3] = "You may rely on it.";
responses[4] = "As I see it yes.";
responses[5] = "Most likely.";
responses[6] = "Outlook good.";
responses[7] = "Yes";
responses[8] = "Signs point to yes.";
responses[9] = "Reply hazy try again.";
responses[10] = "Ask again later.";
responses[11] = "Better not tell you now.";
responses[12] = "Cannot predict now.";
responses[13] = "Concentrate and ask again.";
responses[14] = "Don't count on it.";
responses[15] = "My reply is no.";
responses[16] = "My sources say no.";
responses[17] = "Outlook not so good.";
responses[18] = "Very doubtful.";
responses[19] = "No.";
//type of array - name of array - declaration of array - array size
String[] confusiusSays = new String[6];//array is a square bracket
confusiusSays[0] = "Confucius Say: Help, I'm prisoner in a Chinese bakery!!!\n";
confusiusSays[1] = "A relationship is the opportunity to do something you hate with someone you love.\n";
confusiusSays[2] = "It's ok to let a fool kiss you, but don't let a kiss fool you.\n";
confusiusSays[3] = "Never argue with a fool...he may be doing the same thing.\n";
confusiusSays[4] = "An Optimist is a girl who regards a bulge as a curve.\n";
confusiusSays[5] = "A Shotgun wedding is a case of wife or death.\n";
//type of array - name of array - declaration of array - array size
String[] yourCard = new String[54];//array is a square bracket
//joker
yourCard[0] = "The Joker";
//clubs
yourCard[1] = "The One of Clubs";
yourCard[2] = "The Two of Clubs";
yourCard[3] = "The Three of Clubs";
yourCard[4] = "The Four of Clubs";
yourCard[5] = "The Five of Clubs";
yourCard[6] = "The Six of Clubs";
yourCard[7] = "The Seven of Clubs";
yourCard[8] = "The Eight of Clubs";
yourCard[9] = "The Nine of Clubs";
yourCard[10] = "The Ten of Clubs";
yourCard[11] = "The Jack of Clubs";
yourCard[12] = "The Queen of Clubs";
yourCard[13] = "The King of Clubs";
//diamonds
yourCard[14] = "The One of Diamonds";
yourCard[15] = "The Two of Diamonds";
yourCard[16] = "The Three of Diamonds";
yourCard[17] = "The Four of Diamonds";
yourCard[18] = "The Five of Diamonds";
yourCard[19] = "The Six of Diamonds";
yourCard[20] = "The Seven of Diamonds";
yourCard[21] = "The Eight of Diamonds";
yourCard[22] = "The Nine of Diamonds";
yourCard[23] = "The Ten of Diamonds";
yourCard[24] = "The Jack of Diamonds";
yourCard[25] = "The Queen of Diamonds";
yourCard[26] = "The King of Diamonds";
//hearts
yourCard[27] = "The One of Hearts";
yourCard[28] = "The Two of Hearts";
yourCard[29] = "The Three of Hearts";
yourCard[30] = "The Four of Hearts";
yourCard[31] = "The Five of Hearts";
yourCard[32] = "The Six of Hearts";
yourCard[33] = "The Seven of Hearts";
yourCard[34] = "The Eight of Hearts";
yourCard[35] = "The Nine of Hearts";
yourCard[36] = "The Ten of Hearts";
yourCard[37] = "The Jack of Hearts";
yourCard[38] = "The Queen of Hearts";
yourCard[39] = "The King of Hearts";
//spade
yourCard[40] = "The One of Spades";
yourCard[41] = "The Two of Spades";
yourCard[42] = "The Three of Spades";
yourCard[43] = "The Four of Spades";
yourCard[44] = "The Five of Spades";
yourCard[45] = "The Six of Spades";
yourCard[46] = "The Seven of Spades";
yourCard[47] = "The Eight of Spades";
yourCard[48] = "The Nine of Spades";
yourCard[49] = "The Ten of Spades";
yourCard[50] = "The Jack of Spades";
yourCard[51] = "The Queen of Spades";
yourCard[52] = "The King of Spades";
//second joker
yourCard[53] = "The Second Joker";
Console.WriteLine("\n" + "Ask a question and the Magic 8 Ball will return divine insight!");//method stub
Console.ReadLine();
Console.WriteLine("\n" + "Magic Eight Ball Say: " + responses[luckyEight]);
Console.WriteLine("\n" + "confusius say, " + confusiusSays[luckySix]);
Console.WriteLine("\n" + "Your lucky card For today is: " + yourCard[luckyFiftyTwo]);
}
static void Main(string[] args) //This is the 'driver' method
{
Program myMethodDriver = new Program();
myMethodDriver.Magic8ball();
//look up 'Console.close'
Console.Read();
}
}
}