2

ユーザーが2つのサイコロを好きなだけ振ることができるようにするプログラムを作成するために、このプログラムを実行するために最善を尽くしていますが、転がったサイコロは数字ではなく画像として表示できません。

そのような

[お]

1のサイコロを振る。

私はまだプログラムのループコードを作成しておらず、ロールの乱数を作成する方法しか知りません。画像の配列リストを作成する方法と、代わりに実際に画像を使用するコードを作成する方法がわかりません数字...あなたが私が何を意味するか知っていれば。

ここに私のコードがあります、助けてくれてありがとう!

        int[] DiceUno = new int[6];
        int[] DiceDos = new int[6];
        Random rnd = new Random();

        Console.WriteLine("This program will allow you to roll two dice");
        Console.WriteLine("\nAs many times as you want");
        Console.WriteLine("\n\nWhen you want to exit the program, please type (exit)");
        Console.WriteLine("\nPress any key to begin rolling");
        Console.Read();


        for (int i = 0; i < 1; i++)
        {
            int diceRoll = 0;
            diceRoll = rnd.Next(6);
            DiceUno[diceRoll]++;
            Console.WriteLine("Dice 1 is rolled a: {0}", diceRoll + 1);
            diceRoll = rnd.Next(6);
            DiceDos[diceRoll]++;
            Console.WriteLine("Dice 2 is rolled a: {0}", diceRoll + 1);

        }





    }
}

}

4

3 に答える 3

5

これは、いくつかの迅速で汚れた LINQ を使用して機能するはずです。

var die = new Dictionary<int, string>
{
    { 1, "[     ]\n[  o  ]\n[     ]" }, //or a path to an image somewhere or anything you want
    { 2, "[     ]\n[ o o ]\n[     ]" },
    { 3, "[  o  ]\n[ o o ]\n[     ]" },
    { 4, "[ o o ]\n[     ]\n[ o o ]" },
    { 5, "[ o o ]\n[  o  ]\n[ o o ]" },
    { 6, "[ o o ]\n[ o o ]\n[ o o ]" },
};

do
{
    var shuffled = die.OrderBy(x => Guid.NewGuid()).Take(2);

    foreach (KeyValuePair<int, string> i in shuffled)
    {
        Console.WriteLine(i.Value);
        Console.WriteLine();
    }
} while (Console.ReadLine() != "(exit)");
于 2012-02-29T00:42:04.680 に答える
0

数値ではなくテキストを出力する場合は、文字列の配列を作成します。

string[] images = new string[]
    { "o", "oo", "ooo", "oooo", "ooooo", "oooooo" };

そして、Console.WriteLineのdiceRoll + 1の代わりに、images [diceRoll]を配置します:

Console.WriteLine("Dice 1 is rolled a: {0}", images[diceRoll]);

これで、画像で遊ぶことができます。おそらく、3行の画像を作成して、ダイ(ドットのないスペース)に表示される数字を表示します。

于 2012-02-29T00:35:29.043 に答える
0

次のような単純なものではないのはなぜですか

Dictionary<int, string> valueToDiceImage = new Dictionary<int, string>() 

{

 {0, "[0]"},

 {1, "[1]"},

 {2, "[2]"},

 {3, "[3]"},

 {4, "[4]"},

 {5, "[5]"},

 {6, "[6]"},

};

そして、次のように使用します。

int diceRoll = rnd.next(6); 
System.Console.Write("User Rolled a " + valueToDiceImage[diceRoll] + "\n");
于 2012-02-29T00:29:22.060 に答える