Easier way to make a roguelike?

This is my attempt at making a simple room in a roguelike, obviously it's very glitchy and doesn't have much logic behind it at all, but it took quite some time just to make this tiny bit.. is there any easier way to go about creating a roguelike?

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <conio2.h>
#include <windows.h>
using namespace std;
 
void gotoXY( int x, int y )
{
        HANDLE output_handle;
 
        COORD pos;
 
        pos.X = x;
        pos.Y = y;
 
        output_handle = GetStdHandle( STD_OUTPUT_HANDLE );
 
        SetConsoleCursorPosition( output_handle, pos );
}
 
void gotoXYZ( int cord1, int cord2 )
{
        HANDLE output_handle;
 
        COORD pos;
 
        pos.X = cord1;
        pos.Y = cord2;
 
        output_handle = GetStdHandle( STD_OUTPUT_HANDLE );
 
        SetConsoleCursorPosition( output_handle, pos );
}
 
 
 
 
int main()
{
        const int consoleWidth = 35;
        const int consoleHeight = 19;
        char navigate;
        int cord1 = 32;
        int cord2 = 12;
        int a = 0;

   do
        { 
            gotoXY(32, 12);
            cin >> navigate;
   
    gotoXY( 5, 3 );
        cout << "Welcome to the World! This is your house";
    gotoXY( 5, 4);
        cout << "Controls: ";
        textcolor(LIGHTCYAN);
        cout << "    W: Up, ";
        textcolor(CYAN);
        cout << "   A: Left, ";
        textcolor(LIGHTMAGENTA);
        cout << "   S: Down, ";
        textcolor(MAGENTA);
        cout << "    D: Right";
 

    for( int y = 10; y < consoleHeight;  ++y )
        {
                for( int x = 20; x < consoleWidth - 2; ++x )
                {
                        gotoXY( x, y );
                        textcolor(DARKGRAY);
                        cout << ':';
                }
        }
        
    for ( int y = 9; y < 10; ++y)
    {
        for( int x = 20; x < 35 - 2; ++x)
        {
            
        gotoXY( x, y);
        textcolor(LIGHTGRAY);
        cout << '@';
        }
    }
    
    for (int y = 19; y < 20; ++y)
    {
        for( int x = 20; x < 35 - 2; ++x)
        {
        gotoXY( x, y);
        textcolor(LIGHTGRAY);
        cout << '@';
        }
    }
    
    for (int y = 9; y < 19; ++y)
    {
        for( int x = 20; x < 23 - 2; ++x)
        {
        gotoXY( x, y);
        textcolor(LIGHTGRAY);
        cout << '@';
        }
    }
    
    for (int y = 9; y < 20; ++y)
    {
        for( int x = 33; x < 36 - 2; ++x)
        {
        gotoXY( x, y);
        textcolor(LIGHTGRAY);
        cout << '@';
        }
    }
    
    
    for (int y = 15; y < 17; ++y)
    {
        for( int x = 33; x < 36 - 2; ++x)
        {
        gotoXY( x, y);
        textcolor(WHITE);
        cout << '#';
        }
    }
     
        
        gotoXY( 5, 6);
        cin  >> navigate;
       
        if(navigate == 'S' || navigate == 's')
        {
        cord2++;
        gotoXYZ(cord1, cord2);
        cout << '+';
        gotoXY(5, 5);
        cout << "                                                                 " << endl;
    }
    else if(navigate == 'W' || navigate == 'w')
    {
        cord2--;
        gotoXYZ(cord1, cord2);
        cout << '+';
        gotoXY(5, 5);
        cout << "                                                                 " << endl;
    }
    else if(navigate == 'A' || navigate == 'a')
    {
        cord1--;
        gotoXYZ(cord1, cord2);
        cout << '+';
        gotoXY(5, 5);
        cout << "                                                                 " << endl;
    }
    else
    {
        cord1++;
        gotoXYZ(cord1, cord2);
        cout << '+';
        gotoXY(5, 5);
        cout << "                                                                 " << endl;
    }
   
    }
    while(a == 0);
        
        
        
        
        _getch();
 
        return 0;
}
Last edited on
I would recommend not using the console and using a lib better suited for games... like SFML.

Other than that, you shouldn't be hardcoding the drawing of a room like that. Your world/map should be stored in some kind of array, and then your drawing code should just iterate over the array and draw the appropriate tile at the appropriate position.

Here's a very simple example (but a bad implementation):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// this should be a dynamically created/modified array containing your map
char map[][] = {
"##########",
"#........#",
"#........#",
"#........#",
"#........#",
"#........#",
"##########"
};


for(int y; ...)
{
  cout << map[y] << '\n';
}
Topic archived. No new replies allowed.