Values in an Array

Hey guys,
I'm working on a simple little game thing. I've asked for help on this forum before and received it but I'm stuck again.

In the game, a map is drawn based on constant variables set at the beginning of the code. I have a constant variable for the amount of enemies, or as I refer to them, "mobs", as well. I'm trying to make it so that the code generates random positions for the mobs, sets their position into an array, then places them down
in another function when I draw the map.

1
2
3
4
5
 	for (int i=0; i <= mobQTY; i++) {
	mobs[i] = rand() % HORIZONTAL * VERTICLE + i;
	while (mobs[i] == 0 || mobs[i] == 1 || mobs[i] == HORIZONTAL) {
			mobs[i]++;
		}




Essentially my problem is that I'm trying to make it so that when I change the constant value of the number of mobs (mobQTY), it will generate that amount in all cases. When I'm drawing the map, this is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
        char c = '.';
	int place = 0;
	int mobNum = 0;
	bool mobGen = true;
	system("cls");
	
	for (int j=0; j<VERTICLE; j++){
		cout << "        ";
		for (int i=0; i<HORIZONTAL; i++){

                  if (endLevel == place){
				c = 'O';
			}
                  else if (mobs[mobNum] == place){
				c = 'X';
				mobNum++; }

	          else if (player_coord == place){
				c = 'T';
			}
		  else{
				c = '.';
			}

			board[j][i] = c;
			cout << " " << board[j][i];
			place++;
		}
		cout << endl;
	}


Everything works except for the mob placement. I'm trying to make it so that it will put all of the mobs down on the map until it reaches it's mobQTY limit.

Am I using arrays incorrectly here? Any fix to this?
Last edited on
It is just a pain and disincentive to help if the questions are unclear and fragmented as they were in your other post. It also helps if you post all your code not just snippets. If stated clearly in English exactly what the game does as you might explain in English exactly how Othello, chess, checkers, or an ascii dungeons game works then coding it becomes easy or easier. Programming is really just translating from a human language description of a set of rules to manipulate data into their computer language equivalent.



Last edited on
Topic archived. No new replies allowed.