Help in declaration;

1
2
3
4
5
6
7
8
9
class game
{
    struct player;
    {
        int position[20][20];
         .....
          ...
     }
}
I want to declare the objects of struct player such that the value of position for all of them should be diffrent. it will be not change throughout the program...how can i do it.You can use some public function of other tricks to do it,but please help....
What are your bounds? If both X and Y are +- 1000 units, then put it in the constructor and do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class game
{
private:
  struct _player // defines a datatype
  {
    int position[20][20];
  } player[20]; // defines 20 players
public:
  game() // default constructor
  {
    // A vector of 1000 numbers in order
    std::vector<int> RandomVector;
    for (int i = 0; i < 1000; ++i) RandomVector.push_back(i);
    
    // A vector of 1000 number in random order
    std::random_shuffle( RandomVector.begin(), RandomVector.end() );  
	
    // stick the first few random numbers into position[][] as they are all unique.
    for (int i = 0; i < 20; ++i)
      for (int j = 0; j < 20; ++j)
        for (int k = 0; k < 20; ++k)
          player[i].position[j][k]=  RandomVector[k + 20*j];
  }  
};


Your struct player wasn't defined quite right, I'm trying to figure out exactley what you want. First you have to declare what the struct will hold, then you need to declare members of it. I'm guessing you want X,Y values of position and you want an array of players or something.
Last edited on
yes you figured it out right,,I want to define some points on output screen for every player...
Last edited on
Topic archived. No new replies allowed.