Results 1 to 5 of 5

Thread: Forms to be loaded on random

  1. #1
    v1rTUAL is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2011
    Posts
    3
    Reputation
    0

    Forms to be loaded on random

    I am trying to create a simple game for children for my final year project, I have a number of form that will display a different type of question for each form. I am aware of the form1.Show() and form1.Hide(), is there anyway that I can load a form on random. for e.g, lets say I have form1, form2, form3, form4.... I want the order of the forms to be shown in random order. Thank you in advance.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,335
    Reputation
    1543
    Put your forms into a List. Use a Random object to generate a random index for that List. Remove the form at that index and display it. Continue until the List is empty. If you don't mind repeats then use an array instead of a List and don't remove.

  3. #3
    v1rTUAL is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2011
    Posts
    3
    Reputation
    0
    Thank you very much for the answer, I got it after a few tries, However i have another question. this is the scenario. I have total of 50 forms, starting with the Menu form. For example, when the user complete the game in from1 it will allow them to enter form2. i have added a menu button on each forms so that they could always return to the MENU, my question is, what do i do so that they could return back to the previous form that they came from. I do not want them to start the game from the beginning again. for example if the user return to menu in level 10, they should be able to return back to level 10 when they click on the return to game to game button. Thanks in advance.

  4. #4
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    You could also declare the forms as a control array, and just randomize the array index...

    Code:
    Dim Forms(50) As Windows.Forms.Form
    Then pick a number between 0 and 49 and show the form:

    Code:
            Dim rnd As Random = New Random(DateTime.Now.Millisecond)
            Forms(rnd.Next(0, 49)).Show()

  5. #5
    v1rTUAL is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0
    Join Date
    Oct 2011
    Posts
    3
    Reputation
    0
    Thanks guys the game is better now that they cant memorize the sequencing after some time of playing it.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking