2012-02-28 65 views
2

我正在尽我所能做这个程序,它是让程序,让用户滚动两个骰子尽可能多,但骰子滚动不能显示为数字,但作为数字,但作为一个图像。C#骰子滚动程序与图像

[O]

为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

我不能帮助编码,但死亡的复数是骰子。骰子没有意义。把它丢去外面。 – 2012-02-29 00:00:19

+0

那些真正的图像还是只是在数字的周围画出括号? – 2012-02-29 00:31:01

+0

我也是这么认识的。忽略我的答案,如果你的意思是像jpegs的实际图像,而不仅仅是ascii图像。 – 2012-02-29 00:32:21

回答

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"); 
+0

对不起,我打算使用ASCII艺术来做骰子。 所以我的意思是我该如何创建一个数组列表来让它调出dice1,dice2,dice3等随机ASCII艺术而不是数字 – 2012-02-29 00:39:10

0

如果你想输出的文本,而不是数量,创建一个字符串数组:

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

而不是diceRoll + 1 Console.WriteLine把图像[diceRoll]:

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

现在你可以用图片播放,也许是创建一个三线的图像,因为它们出现在模具显示的数字(点空的空间)。

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