带图像的C#骰子滚动程序

时间:2012-02-28 23:55:24

标签: c# dice

我正在尽我所能做这个程序,这个程序可以让用户按照自己的意愿滚动​​两个骰子,但滚动的骰子不能显示为数字而是显示为图像。

,例如

[O]

表示1的模具卷。

我还没有制作程序的循环代码,我只知道如何制作卷的随机数,我只是想不通如何制作图像的arraylist并使代码实际使用图像而不是数字...如果你知道我的意思。

这是我的代码到目前为止,感谢您的帮助!

        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);

        }





    }
}

}

3 个答案:

答案 0 :(得分: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)");

答案 1 :(得分: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");

答案 2 :(得分:0)

如果要输出文本而不是数字,请创建一个字符串数组:

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

而不是在Console.WriteLine中的diceRoll + 1放图像[diceRoll]:

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

现在你可以玩图像了,也许会创建一个三行图像来显示它们出现在骰子上的数字(点空格)。

相关问题