Moving array of characters

khn
Last edited on
@victor1599

I don't quite understand this 'game'. Is your map just one long line of 28 squares, or were you wanting 4 rows of 7 squares? What is the object?
sorry, he
Last edited on
@victor1599

Well, here's the program using the 'R' key, for 'move Right'.
I also added in text showing what the lines do

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <windows.h>
#include <string.h>

using namespace std;

bool gameRunning = true;

char Player = 'P'; // These are to be char statements, not int's
char Dragon = 'D';

char map[28];

int main()
{
	int display;
	char move;
	
		map[0] = Player;
		map[27] = Dragon;
		cout << map[0];// Next 7 lines, print out the map array
		for (display = 1; display < 27; display++)
		{
			map[display] = '*';
			cout << map[display];
		}
		cout << map[27];
		cout << endl << endl << "Press 'R', to move your character, 'P', one square to the right, to meet the Dragon.." << endl;
		// Above line, lets user know what key to press
		display=0; // Start at map[0]
		while (gameRunning == true) 
	{
			do
			{
				cin >> move; // Get user input
				move = toupper(move); // Make it uppercase
				if(move == 'R') // If input correct
				{
					map[display] = '*'; // Remove old location of player
					display++; // Increase display location
					map[display] = 'P'; // Insert player in new map array location
				}
			}while(move !='R');
			for(int x=0;x<28;x++) // Print out new map array with the changed player location
					cout << map[x];
			if (display == 27) // If player at end of map array, end game
			{
				gameRunning = false;
			}
	}
		cout << endl << endl << "You met up with the Dragon. Game over." << endl; // Show text explaining why game ended
}
Last edited on
Thank you!!
victor, stop editing away your questions after they've been answered. It makes the entire discussion useless for anyone who might have benefited.
For completion, here's the question, repeated:

Hi, I'm trying to create a game in which the 'P' is my player and the 'D' is the dragon, and I have 28 positions on the board and the player starts in space 1. The player can only travel forward(higher numbers). And I have to keep track of the current position of the player and mark it on the on-screen map with P. I already made the map but I don't know how to do it so that my player can move forward. Thanks in advanced

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
#include <iostream>
#include <windows.h>
#include <string.h>

using namespace std;

bool gameRunning = true;

int Player = 'P';
int Dragon = 'D';

char map[28];

int main()
{
	while (gameRunning == true) {
		for (int display = 0; display < 28; display++)
		{
			map[display] = '*';
			(map[0] = Player);
			(map[27] = Dragon);
			cout << map[display];

			if (display == 27) {
				gameRunning = false;
			}
		}

	}

Last edited on
Odd that you had that handy, but nice.
Google has it cached, lol.
Where? Is it somewhere in the HTML of the site?
Search for this URL with google. Click on little triangle to the right of the link. Click "Cached".
Last edited on
Ah, I see. Thanks!
Should we wait until Google has a solid cache, before we answer new questions?
Yes
Topic archived. No new replies allowed.