Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows Forms
is there a way to make a control to change location everytime it runs. not just randomly but perhaps at points x,y and z.
Posted 26-Mar-13 11:17am
Comments
Zoltán Zörgő at 26-Mar-13 16:18pm
   
Of course. What have you tried? Z??? Do you have a 3D GUI?
ryanb31 at 26-Mar-13 16:18pm
   
Sure. Where are you stuck?
Code-genious at 26-Mar-13 16:26pm
   
u know those picture games whereby you try to select two same pictures? i wrote it. but now my friends now where the same pictures are and the game is not fun anymore. is any way to make the pictures to swap positions with each other at every run.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

"u know those picture games whereby you try to select two same pictures? i wrote it. but now my friends now where the same pictures are and the game is not fun anymore. is any way to make the pictures to swap positions with each other at every run."
 
So, you do want it randomly then. Honest, you do. You just don't want the actual location to be random.
 
Assume you have three pairs of images (yes, I know it's a bit simple - this is just an example). You set up an array of 6 Images:
private Image[] pics = new Image[6];
You then fill the slots randomly:
private Random rand = new Random();
...
   SetImage(pics, Image1, rand.Next(0, 6));
   SetImage(pics, Image1, rand.Next(0, 6));
   SetImage(pics, Image2, rand.Next(0, 6));
   SetImage(pics, Image2, rand.Next(0, 6));
   SetImage(pics, Image3, rand.Next(0, 6));
   SetImage(pics, Image3, rand.Next(0, 6));
...
private void SetImage(Image[] pics, Image image, int index)
   {
   while (pics[index] != null)
      {
      index++;
      index %= 6;
      }
   pics[index] = image;
   }
You then use the pics array in that order to show the pictures on the screen. Because the order of the pics in the array is random, but the locations aren't, they appear in random positions each time.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 250
1 George Jonsson 175
2 Jochen Arndt 150
3 Kornfeld Eliyahu Peter 149
4 PIEBALDconsult 110
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100