我怎样才能制作一个小骰子应用程序? [英] How can I make a small dice app ?

查看:104
本文介绍了我怎样才能制作一个小骰子应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  - 如何表示骰子指数的随机数组? 
-loop取10个数字
-保存数组中的随机数或使用数组列表(更好)
-use列表框显示10个随机保存的数字

****************************

另一个问题。

如何从表单传递到另一个表单?
如果我想为骰子应用添加计时器怎么办?

Ps:对我来说非常重要的是要事先知道解决方案





我尝试了什么:



我一周以来都在尝试,但我没有达到任何目标

私人随机死亡=新随机();

For(int i = 0; i< 5; i ++)}
Die [i] = i;
}



这里的问题是我如何在阵营中加入阵列如果我不使用阵列

和我如此混淆:(

解决方案

Quote:

- 如何表示代表骰子指数?

-loop取10个数字

-保存数组中的随机数或使用数组列表(更好)



如果您尝试使用代表骰子卷的随机数填充数组,那么这很简单:

  private  Random die =  new  Random(); 
...
int [] rolls = new int [ 10 ];
for int i = 0 ; i < rolls.Length; i ++)
{
rolls [i] = die.Next( 6 )+ 1 ;
}

不要使用ArrayList - 它非常非常过时。有更好的构造称为通用集合,它更容易使用:

 List< int> rolls = new List< int>(); 
for(int i = 0; i< 10; i ++)
{
rolls.Add(die.Next(6)+ 1);
}

使用泛型集合时,你不必在尝试使用它们时将值转换为特定的数据类型,系统强制你只能放右其中的数据类型。

引用:

- 使用列表框显示10个随机保存的数字



 myListBox.DataSource = rolls; 





引用:

如何从表单传递到另一个?



这很复杂:它取决于很多因素,以及它可能超出了你目前的知识范围 - 你真的需要在你开始涉足复杂的东西之前先得到这样的基本内容并真正排序。

但是...

在两个表格之间传递信息,第1部分:父母对孩子 [ ^ ]

在两个表格之间转移信息,第2部分:从孩子到父母 [ ^ ]

在两种表格之间传递信息,第3部分:儿童到儿童 [ ^ ]

Quote:

如果我想为骰子应用添加计时器怎么办?

系统.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); 
timer.Interval = 1000;
timer.Tick + = timer_Tick;
timer.Start();
...
void timer_Tick(对象发送者,EventArgs e)
{
//在这里做你的计时器。
}


-How can i array of random numbers that represent the dice index ?
-loop take 10 numbers
-save the random numbers in array or use an array list(better)
-use list box to show the 10 random saved numbers

****************************

another side question.

How can I pass from form into another ?
What if I want to add a timer for the dice app ?

P.s: it’s very important for me to know the solution 
thanks in advance.



What I have tried:

I was trying it since a week and i did not reach any goal

Private random die = new random();

For(int i=0; i<5; i++)}
Die[i]=i;
}


HERE THE PROBLEM IS HOW CAN I ADD IT TO ARRAY IF I DONT USE ARRAYLIST
AND IM SO CONFUSED :(

解决方案

Quote:

-How can i array of random numbers that represent the dice index ?
-loop take 10 numbers
-save the random numbers in array or use an array list(better)


If you are trying to fill an array with random numbers that represent dice rolls, then that's simple:

private Random die = new Random();
...
int[] rolls = new int[10];
for (int i = 0; i < rolls.Length; i++)
   {
   rolls[i] = die.Next(6) + 1;
   }

Don't use ArrayList - it'a very, very out of date. There are better constructs called Generic Collections which are much easier to use:

List<int> rolls = new List<int>();
for (int i = 0; i < 10; i++)
    {
    rolls.Add(die.Next(6) + 1);
    }

With generic collections you don;t have to cast teh values to a particular datatype when you try to use them, and the system enforces that you can only put the right type of data in them.

Quote:

-use list box to show the 10 random saved numbers


myListBox.DataSource = rolls;



Quote:

How can I pass from form into another ?


That is complicated: it depends on a lot of factors, and it probably outside your knowledge set at the moment - you really need to get basic stuff like this well and truly sorted before you start wading into the complex stuff.
But...
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]

Quote:

What if I want to add a timer for the dice app ?

            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = 1000;
            timer.Tick += timer_Tick;
            timer.Start();
...
        void timer_Tick(object sender, EventArgs e)
            {
            // Do your timer stuff here.
            }


这篇关于我怎样才能制作一个小骰子应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆