g++ / visual studio c++ problem...

Hi, use g++ at home on Linux and visual Studio c++ at work. Am working on 'dungeon crawl' exercise trying to get the 'player' to move using the number keypad. Have instigated '2' to move down, seemed to work with no problems on g++ at home, added the '6' or move right and no joy together with some 'random' characters in the grid.

I come to work with the code to work on, compile it in visual studio, run it to remind myself of the problem - but hey presto move down and right work fine.

Could someone try to explain why this is the case and what can be done to fix it please,

Mant thanks,

Dan

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
#include <limits>

using namespace std;

int main ()

{
char grid [10][10];					// basic game grid size
bool grid_check [10][10];			//to flag positions once something is there
int x = 0, y = 0;					//x-axis and y-axis position
int randx = 0, randy =0;			//random values to be passed to x and y position
int ran1;							//temp store for random number						
int rn;								//variable for number of random numbers required
int level;							//place to store level selection	
int n;
int move;							//direction of move integer
srand((unsigned)time(0));
bool game_end=0;
int a=0, b=0;

// Take appropriate level input
while ((cout << string(50, '\n') <<"Please select difficulty level 1-5\n") && (!(cin >> level) || level<1 || level>5))
	{
	cin.clear();
	cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}

// basing number of random nmbers needed on level
rn = (10*level);

// generating the numbers and putting markers into the check array memory
for (n=0; n<=rn; n++)
	{
	randx =rand()% 11;
	randy =rand()% 11;
	
	grid_check[randx][randy]=1;
	}
	
//fill rest of array up with dots
for (x=0; x<10; x++)				
	for (y=0; y<10; y++)
		if (grid_check[x][y] !=1)
			grid[x][y]='.';
			else grid [x][y] = 'T';
	
// Placing the treasure
grid [9][9]='X';
grid_check [9][9]=1;

// Placing the player
grid[0][0] = 'C';
grid_check [0][0] = 1;
			
//create space			
cout << string(50, '\n');  

//print out array	
for (x=0; x<10; x++)
	{
	cout << "\n\t\t\t\t";
	for (y=0; y<10; y++)
		{
		cout << grid[x][y] << " ";
		}
	}
	
// Main game loop
while (game_end == 0)
	{
	// getting appropriate input
	while ( (!(cin >> move) || move<1 || move>9))
	{
	cin.clear();
	cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}
	// Move down
if (move == 2)
	{
	grid_check[a][b]=0;		// unflag spot about to be left
	grid[a][b]='.';			// Place a point on it
	a++;					// Change value of x-axis
	grid[a][b]='C';			// Put character in new spot
	grid_check[a][b]=1;		// Flag new spot
	}
else if (move == 6)
	{
	grid_check[a][b]=0;		// unflag spot about to be left
	grid[a][b]='.';			// Place a point on it
	b++;					// Change value of x-axis
	grid[a][b]='C';			// Put character in new spot
	grid_check[a][b]=1;		// Flag new spot
	}
	
//create space			
cout << string(50, '\n'); 
 
//print out array	
for (x=0; x<10; x++)
	{
	cout << "\n\t\t\t\t";
	for (y=0; y<10; y++)
		{
		cout << grid[x][y] << " ";
		}	
	}
	}
cout << endl;
	
return 0;
}
Topic archived. No new replies allowed.