Gui and outputting it

[In advance I apologize with all the code]I need help fixing a gui where the money amount is being outputted(near the bottom in the while() loop) where the player is:
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
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
using namespace std;

int playerX = 1, playerY = 1;
char playerChar = 143;
char map[20][15];
int getX = playerX;
int getY = playerY;
int money = 0;

bool keyPressed( char *c )
{
	if( _kbhit() )
	{
		*c = _getch();
		return true;
	}

	return false;
}

void gotoXY( int x, int y )
{
	HANDLE output_handle;

	COORD pos;

	pos.X = playerX;
	pos.Y = playerY;

	output_handle = GetStdHandle( STD_OUTPUT_HANDLE );

	SetConsoleCursorPosition( output_handle, pos );
}

void erase( int x, int y )
{
	gotoXY( playerX, playerY );
	cout << " ";
}

void draw( int x, int y )
{
	gotoXY( playerX, playerY );
	cout << playerChar;
}

int main()
{
    system("title Test"); // will get rid of
    system("color f0");
    // map
    char map[20][15]{
            {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X'},
            {'X',' ','X','X','X','X',' ','X',' ','X','X',' ',' ',' ','X'},
            {'X',' ',' ',' ','X',' ',' ','X',' ',' ',' ',' ','X',' ','X'},
            {'X',' ','X','X','X',' ','X','X','X','X','X',' ','X',' ','X'},
            {'X',' ',' ',' ',' ',' ','X',' ',' ',' ',' ',' ','X',' ','X'},
            {'X',' ','X','X',' ','X','X',' ','X',' ','X','X','X',' ','X'},
            {'X',' ',' ','X',' ',' ','X',' ','X',' ',' ',' ',' ',' ','X'},
            {'X',' ','X','X',' ','X','X',' ','X','X',' ','X','X',' ','X'},
            {'X',' ','X',' ',' ','X',' ',' ',' ','X',' ','X',' ',' ','X'},
            {'X',' ','X',' ','X','X',' ','X',' ','X',' ','X',' ','X','X'},
            {'X','$','X',' ',' ',' ',' ','X',' ',' ',' ','X',' ','O','X'},
            {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X'}};

	for(int mapY = 0; mapY < 15; mapY++){
		for(int mapX = 0; mapX < 20; mapX++)
		{
			cout << map[mapX][mapY];
		}
		cout << endl;
	}
    // wait for the player to do something
    char key = ' ';
    while( key != 27 )
    {
        cout << "Money: " << money;
        while( ! keyPressed( &key ) );
        {
        }

        key = tolower( key );

        switch( key )
        {
            case 119://w
                if(map[getX][getY-1] == 'X')
                    break;
                erase( playerX, playerY );
                if(map[getX][getY] == '$'){
                        map[getX][getY] = ' ';
                        Beep(750,75);
                        money++;
                }
                //set the new position then draw
                playerY = (playerY - 1);
                draw( playerX, playerY  );

                break;

			case 115://s
				if(map[getX][getY+1] == 'X')
					break;
                erase( playerX, playerY );
                if(map[getX][getY] == '$'){
                        map[getX][getY] = ' ';
                        Beep(750,75);
                        money++;
                }
				playerY = (playerY + 1);
				draw( playerX, playerY  );

				break;

			case 97://a
				if(map[getX-1][getY] == 'X')
					break;
                erase( playerX, playerY );
                if(map[getX][getY] == '$'){
                        map[getX][getY] = ' ';
                        Beep(750,75);
                        money++;
                }
				playerX = (playerX - 1);
				draw( playerX, playerY  );

				break;

			case 100://d
				if(map[getX+1][getY] == 'X')
					break;
                erase( playerX, playerY );
                if(map[getX][getY] == '$'){
                        map[getX][getY] = ' ';
                        Beep(750,75);
                        money++;
                }
				playerX = (playerX + 1);
				draw( playerX, playerY  );

				break;

			default:
				break;
        }
        if(getX != playerX){
            getX = playerX;
        }
        if(getY != playerY){
            getY = playerY;
        }
    }
    return 0;
}

Right above return 0. The money int is being outputted at the players position(@ is player):
XXXXXXXXXXXX
X    Money: 0
XX X Money: 0
XX X Mon   Money: 0
XXXX     M Money: 0
XX   X XXX Money: 0
X  XXXXX Money: 000
XXXX     Money: 0
X  X XXX   Money: 0ney: 0
XX X   XXX Money: 0
XX X X Money: 00000
X    X Money: 0
X XXXX Money: 0
X  @Money: 0000
XXXXXXXXXXXXXXX
Money: 0

How do I fix this?
What exactly is the problem I am lost? Also GUI stands for Graphical User Interface. This is a console application and generally speaking it is much easier to make a game using a graphical library such as SFML[1] versus the console. Also the conio library is deprecated.

[1] http://sfml-dev.org/index.php
Last edited on
My mistake, I meant HUD. HUD as in money, HP, stamina, ec. The thing that I'm lost with is the Money int being outputted at the player(outputting: Money: 0 at the players location). Sorry if I'm confusing. Also I'm using conio because that was the only input device I've seen other than the windows one.
Last edited on
You probably called the gotoxy function (moved cursor) then drew the player and forgot to move it back before drawing the money. I would advise you change the cursors location at the end of the while loop or beginning before printing the money. Also I don't understand what it is supposed to look like

XXXXXXXXXXXX
X    Money: 0
XX X Money: 0
XX X Mon   Money: 0
XXXX     M Money: 0
XX   X XXX Money: 0
X  XXXXX Money: 000
XXXX     Money: 0
X  X XXX   Money: 0ney: 0
XX X   XXX Money: 0
XX X X Money: 00000
X    X Money: 0
X XXXX Money: 0
X  @Money: 0000
XXXXXXXXXXXXXXX
Money: 0
looks pretty messy
Thanks. This helped.
Topic archived. No new replies allowed.