need help

im trying to build a text world with a movable player, i dont know what i did wrong and how to fix it.

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

#include <iostream>
#include <stdexcept>
using namespace std;

enum Facing{
	kNorth=0,
	kEast,
	kWest,
	kSouth,
};

struct Player{
	Facing facing;
	int x;
	int y;
};

struct Tile {
	char* src;
	char walls[4];
	int roomDescribe;

	// strings go here

	bool visited;
};

#define kOpen "OOOO"
#define kBlock "NNNN"
#define kN_W "WOOO"
#define kE_W "OWOO"
#define kW_W "OOWO"
#define kS_W "OOOW"
#define kNE_Corn "WWOO"
#define kNW_Corn "WOWO"
#define kSE_Corn "OWOW"
#define kSW_Corn "OOWW"
#define kNE_Door "DWOO"
#define kNW_Door "DOWO"
#define kSE_Door "OWOD"
#define kSW_Door "OOWD"

const int gWidth = 12;
const int gHeight = 4;
const int gMaxWidth = gWidth -1;

char* gFloor[gHeight][gWidth]= {
	{kNE_Corn, kN_W, kN_W, kNW_Corn, kNE_Corn, kN_W, kN_W, kNW_Corn, kNE_Corn, kN_W, kN_W, kNW_Corn},
	{kE_W, kOpen, kOpen, kW_W, kE_W, kOpen, kOpen, kW_W, kE_W, kOpen, kOpen, kW_W},
	{kSE_Door, kOpen, kOpen, kSW_Corn, kSE_Door, kOpen, kOpen, kSW_Corn, kSE_Door, kOpen, kOpen, kSW_Corn},
	{kSE_Corn, kS_W, kS_W, kS_W, kS_W, kS_W, kS_W, kS_W, kS_W, kS_W, kS_W, kSW_Corn}
};



Player gPlayer = {kNorth,0,0};

bool gPlaying=true;

Tile** gTiles = NULL;

void World_Allocate(Tile**& ary, int rows, int cols)
{
	ary = new Tile*[rows];
	if (!ary) throw runtime_error("cant allocate array of pointers ");

	for (int row = 0; row < rows; row++) {
		ary[row] = new Tile[cols];
		if (!ary[row]) throw runtime_error("cant allocate a row");
	}
}


void World_dispose(Tile**& ary, int rows)
{
	//dispose of columns
	for (int row = 0; rows; row++){
		delete [] ary[row];
	}
	delete [] ary;
}


int main()
{
	World_Allocate(gTiles, gHeight, gWidth);

	for (int row = 0; row < gHeight; row++){
		for (int col = 0; col < gWidth col++){
			gTiles[row][col].roomDescribe = 0;
			gTiles[row][col]. src = NULL;
			gTiles[row][col].visited = false;
		}
	}

	
	//printing rows 
	for(int row=0;row <4;row++){
		//printing cols
		for(int col=0; col<12;col++){
			cout<<gFloor[row][col]<<",";
		}
		cout<<endl;
	}

	cout << gFloor[0][0][2];

	do{
		char key; cin>>key;
		switch (tolower(key)){
		case 'q':gPlayer=false;break;
		case 'n':gPlayer=true;break;
		case 'e':gplayer=true;break;
		case 'w':gplayer=true;break;
		case 's':gplayer=true;break;

		}

	} while(gPlaying);

	Facing facingNow = kNorth;
	player.x = 10;
	player.y = 5;

	bool playing = true;
	do{
		char key; cin >> key;
		cout << room[player.y][player.x] << endl;
	} while (playing);

	World_dispose(gTiles, 5);

	return 0;
}


any help would be appreciated
Last edited on
closed account (o3hC5Di1)
Hey there,

Could you do following things first please:

1. changed [end code] in your post to [/code], then it will have syntax highlighting.
2. indent your code (http://en.wikipedia.org/wiki/Programming_style#Indentation)
3. describe what it is exactly that's not working or what errors you get.

It will help us to help you a lot better :)

Thanks!

NwN
Last edited on
Topic archived. No new replies allowed.