Need help on my game

I have finally got a final idea of a project I want to do. I am trying to make a game were the @ sign moves around the games board when the user puts in one of the pre determined commands. I'm having a trouble in doing this so any help would be very much appreciated.

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
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;


char map[20] [40] = {"#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "# @ #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################"};
int Gamespeed = 5;
int Level = 1;
bool stopgame = false;
int hp = 10;
int MaxHp = 10;
int mp = 15;
int MaxMana = 15;
const int maxCmd = 5;
const string prompCmd[maxCmd] = {"Up", "Down", "Left", "Right", "Attack" }; 
int main ()
{
	while (stopgame == false && Level == 1)
	{
		system("cls");

		for (int y = 0; y < 20; y++)
		{
			cout << map[y] << endl;
		}
		for (int y = 0; y< 20; y++)
		{
			for (int x = 0; x<40; x++)
			{
				
			}
		}
		
		Sleep(Gamespeed);
	}
	return 0;
}

I anyone could help me it will really help me out. :D

Check out my reply and example in this thread:
http://www.cplusplus.com/forum/beginner/131482/
closed account (j3Rz8vqX)
An temporary option:
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
#include <iostream>
#include <windows.h>
using namespace std;
struct Object
{
public:
    int x,y;
    char sprite;
    Object()
    {
        x=y=2;          //default location (2,2);
        sprite='@';     //default sprite (@);
    }
    char draw();
};
namespace global
{
    const static char esc = 27;//Escape;
    const static char cr = 13;//Carriage return;
    const static char etx = 3;//Ctrl-C; end of text;

    const static int SIZEX = 38;//Map size(X);
    const static int SIZEY = 20;//Map size(Y);
    char map[SIZEY][SIZEX] =
                            {"#####################################",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#####################################",
                            "#####################################",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#####################################",
                            "#####################################",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#####################################",
                            "#####################################",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#   #   #   #   #   #   #   #   #   #",
                            "#####################################"};
    Object player;
    char input;
}
void position(int x, int y)
{
    static HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    static COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(handle,coord);
}
void draw()
{
    position(0,0);//Reposition cursor to 0,0 position of command prompt.
    for(int y=0;y<global::SIZEY;++y)
    {
        for(int x=0;x<global::SIZEX;++x)
        {
            if(x == global::player.x && y == global::player.y)
            {
                cout<<global::player.sprite;
            }
            else
            {
                cout<<global::map[y][x];
            }
        }
        cout<<endl;
    }
}
bool event(char &input)
{
    if(GetAsyncKeyState(0x57))//Detect for 'w' Key. Up
    {
        --global::player.y;
        return true;
    }
    if(GetAsyncKeyState(0x53))//Detect for 's' Key. Down
    {
        ++global::player.y;
        return true;
    }
    if(GetAsyncKeyState(0x41))//Detect for 'a' Key. Left
    {
        --global::player.x;
        return true;
    }
    if(GetAsyncKeyState(0x44))//Detect for 'd' Key. Right
    {
        ++global::player.x;
        return true;
    }
    if(GetAsyncKeyState(VK_ESCAPE))//Detect for 'ESCAPE' Key. Escape
    {
        input = global::esc;
        return false;
    }
    if(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(0x43))//Detect for 'control' and 'c' Key. Ctrl-C
    {
        input = global::esc;
        return false;
    }
    //Unimplemented key entered:
    return false;

}
void debug()
{
    cout<<"x: "<<global::player.x<<" y: "<<global::player.y<<"     "<<endl;//Extra space to clear the debug location.
}
int main()
{
    draw();
    debug();//Post x and y location
    do
    {
        if(event(global::input))
        {
            draw();//Draw the map.
            debug();//Post x and y location
        }
    }while(global::input!=global::esc && global::input!=global::etx);
    return 0;
}
closed account (j3Rz8vqX)
A conio.h adaption:
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
#include <iostream>
#include <conio.h>
using namespace std;
struct Object
{
public:
    int x,y;
    char sprite;
    Object()
    {
        x=y=2;          //default location (2,2);
        sprite='@';     //default sprite (@);
    }
    char draw();
};
namespace global
{
    const static char esc = 27;//Escape;
    const static char cr = 13;//Carriage return;
    const static char etx = 3;//Ctrl-C; end of text;

    const static int SIZEX = 38;//Map size(X);
    const static int SIZEY = 20;//Map size(Y);
    char map[SIZEY][SIZEX] =
                                         {"#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################",
					 "#####################################",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#   #   #   #   #   #   #   #   #   #",
					 "#####################################"};
    Object player;
    char input;
    int adjustScreen=0;
}
void adjust(int y)
{
    if(y>0)
    {
        for(int i=0;i<y;i++)
            cout<<endl;
    }
}
void draw()
{
    adjust(100);
    for(int y=0;y<global::SIZEY;++y)
    {
        for(int x=0;x<global::SIZEX;++x)
        {
            if(x == global::player.x && y == global::player.y)
            {
                cout<<global::player.sprite;
            }
            else
            {
                cout<<global::map[y][x];
            }
        }
        cout<<endl;
    }
    adjust(global::adjustScreen);
}
bool event(char input)
{
    if(input=='w')
    {
        --global::player.y;
        return true;
    }
    if(input=='s')
    {
        ++global::player.y;
        return true;
    }
    if(input=='a')
    {
        --global::player.x;
        return true;
    }
    if(input=='d')
    {
        ++global::player.x;
        return true;
    }
    //Adjust command prompt:
    if(input>='0'&&input<='9')
    {
        global::adjustScreen=input-'0';
        return true;
    }

    //Unimplemented key entered:
    return false;

}
void debug()
{
    cout<<"x: "<<global::player.x<<" y: "<<global::player.y<<" Adjust: "<<global::adjustScreen<<endl;//Also. display space adjustment
}
int main()
{
    draw();
    debug();
    do
    {
        if(event(global::input = getch()))
        {
            draw();
            debug();
        }
    }while(global::input!=global::esc && global::input!=global::etx);
    return 0;
}
Topic archived. No new replies allowed.