Making rpg rooms(urgent help!please)

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
#include <iostream>
using namespace std;
class Hero{
public:
   int Lrow;
   int Lcol;
};


class Room{

public:
   // available directions:
   bool North;
   bool East;
   bool South;
   bool West;
   int maprow;
   int mapcol;
   int gold;
   int potion;

   Room(){ //default constructor
       North = false;
       East = false;
       South = false;
       West = false;
   }

   void setRoom(bool n, bool e, bool s, bool w){
       North = n;
       East = e;
       South = s;
       West = w;
   }

   //overloaded constructor
   Room(bool n, bool e, bool s, bool w){
       North = n;
       East = e;
       South = s;
       West = w;
   }

   void display(){
       cout << "North: " << North<<endl;
       cout << "East: " << East<<endl;
       cout << "South: " << South<<endl;
       cout << "West: " << West<<endl;
   }

   string getN(){
       if(North == true){
           return " ";
       }
       else{
           return "-";
       }
   }
   string getS(){
       if(South == true){
           return " ";
       }
       else{
           return "-";
       }
   }
   string getW(){
       if(West == true){
           return " ";
       }
       else{
           return "|";
       }
   }
   string getE(){
       if(East == true){
           return " ";
       }
       else{
           return "|";
       }
   }


};

int main(){
   char d;
   Hero h;
   h.Lrow = 2;
   h.Lcol = 3;

   const int rows=3;
   const int cols=4;
   Room map[rows][cols];
   for(int r=0; r<rows; r++){
       for(int c=0; c<cols; c++){
           map[r][c].mapcol = c;
           map[r][c].maprow = r;
           map[r][c] = Room();
       }
   }
   //(north,east,south,west)
   map[0][0].setRoom(false, true, false, false);
   map[0][1].setRoom(false, true, true, true);
   map[0][2].setRoom(false,true, true, true);
   map[0][3].setRoom(false,false, false, true);
   map[1][0].setRoom(false, true, true, false);
   map[1][1].setRoom(true, false, false, true);
   map[1][2].setRoom(true, true, true, false);
   map[1][3].setRoom(false,false, false, true);
   map[2][0].setRoom(true, true, false, false);
   map[2][1].setRoom(false, true, false, true);
   map[2][2].setRoom(true, true, false, true);
   map[2][3].setRoom(false,false, false, true);
   while(true) {
	   printmap(map, 3, 4, h);
	   cout <<endl;
	   cout << "choose a direction (n,w,s,e): ";
	   cin >> d;


	}
}

How to fix error?
Says
[Error] 'printmap' was not declared in this scope
Last edited on
Don't make a new question for the same thing: http://www.cplusplus.com/forum/beginner/255186/
@YeetParadox

Put the following function just before int main():
1
2
3
4
5
6
void printmap( Room map[3][4], int rows, int cols, const Hero &h )
{
    cout << "This is the routine printmap\n";
    cout << "It doesn't do much at present 'cos it's not a grown-up function\n";
    cout << "So, for the moment, it just says ... Hiya!!!\n";
}


That should get you started.



Also, with the lines
1
2
3
           map[r][c].mapcol = c;
           map[r][c].maprow = r;
           map[r][c] = Room();

the third line is going to completely defeat the object of the first two.
Last edited on
Registered users can post here. Sign in or register to post.