Array map...and hit detection...console

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
116
#include <iostream>

using namespace std;

void movePlayer();
void youWin();

	const int COLS = 14;
	const int ROWS = 7;
	int map[ROWS][COLS] = {	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,	
				1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,	
				1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1,	
				1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
				1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 5, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1  };

	int mapDisp[ROWS][COLS];



	char entry;
	int charCol = 3,
		charRow = 1;

int main()
{
	movePlayer();
	
	system("pause");

	return 0;
}

void movePlayer()
{
	cout << "GOAL: Get your player to the number 5 on the map.\n";
	cout << "Press a letter, and then press enter to move positions.\n";
	cout << "3 = player position\n";
	cout << "1 = barriers\n";
	cout << "0 = empty space\n\n";

	for (int index = 0; index < ROWS; index++)
	{
		for (int ind = 0; ind < COLS; ind++)
		{
			mapDisp[index][ind] = map[index][ind];
		}
	}

	mapDisp[charRow][charCol] = 3;

	for (int row = 0; row < ROWS; row++)
	{
		for (int col = 0; col < COLS; col++)
		{
			cout << mapDisp[row][col] << " ";
		}
		cout << endl;
	}
	
	if (map[charRow][charCol] == 5)
		youWin();
	
	cout << endl;
	
	// If R col + 1
	// If L col - 1
	// If U row - 1
	// If D row + 1

	cout << "L = left\nR = right\nU = up\nD = down\n\n";
	cin >> entry;

	if (entry == 'L' || entry == 'l')
	{
		charCol--;
		if (map[charRow][charCol] == 1)
			charCol++;
	}
	else if (entry == 'R' || entry == 'r')
	{
		charCol++;
		if (map[charRow][charCol] == 1)
			charCol--;
	}
	else if (entry == 'U' || entry == 'u')
	{
		charRow--;
		if (map[charRow][charCol] == 1)
			charRow++;
	}
	else if (entry == 'D' || entry == 'd')
	{
		charRow++;
		if (map[charRow][charCol] == 1)
			charRow--;
	}
	else
		exit(0);



	system("cls");

	movePlayer();
}

void youWin()
{
	cout << "you win!";

	system("pause");

	exit(0);
}
A problem well stated is a problem half solved. You haven't mentioned your problem yet.
Topic archived. No new replies allowed.