Moving array of characters

Jan 23, 2020 at 10:39pm
khn
Last edited on Jan 29, 2020 at 5:21pm
Jan 24, 2020 at 1:46am
@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?
Jan 24, 2020 at 1:49am
sorry, he
Last edited on Jan 24, 2020 at 1:53pm
Jan 24, 2020 at 2:17am
@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 Jan 24, 2020 at 3:51am
Jan 24, 2020 at 3:59am
Thank you!!
Feb 10, 2020 at 2:06am
victor, stop editing away your questions after they've been answered. It makes the entire discussion useless for anyone who might have benefited.
Feb 10, 2020 at 12:12pm
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 Feb 10, 2020 at 12:12pm
Feb 10, 2020 at 7:50pm
Odd that you had that handy, but nice.
Feb 10, 2020 at 8:52pm
Google has it cached, lol.
Feb 11, 2020 at 3:24am
Where? Is it somewhere in the HTML of the site?
Feb 11, 2020 at 9:23pm
Search for this URL with google. Click on little triangle to the right of the link. Click "Cached".
Last edited on Feb 11, 2020 at 9:24pm
Feb 12, 2020 at 8:00am
Ah, I see. Thanks!
Feb 12, 2020 at 8:08am
Should we wait until Google has a solid cache, before we answer new questions?
Feb 12, 2020 at 8:17am
Yes
Topic archived. No new replies allowed.