Help with creating an updating screen for a simple game.

Hey guys. Obviously I'm knew to c++ and programming in general for that matter. I decided to take on a personal project of my own. I want to create a simple, yet unique, 2d terminal game. I'm not ready for any complex graphics. I just want to use chars to create anything the user will see on screen. But I am having trouble with making a "map" if you will.

The best idea I have come up with so far was to use for loops to display a 2d array of chars. The player's char is set = to a variable. And I need the program to read in values from the keyboard to determine where to move the players char. I wanted to use the directional keys, but I've read that using chars would be the easier way to go. So I set up an if statement to test for w,a,s,d keys for movement. I've used the _getch() function to take in the values without the player having to use the return key. But when I push one of the buttons, the char does not move. Also, the screen clearly reprints every time a key is pushed. I pasted my source code so you guys can see what I'm talking about. I would like to know if there is a way to display a screen of chars, and update them without reprinting all of them. Or at least make it to where the player won't be able to visually see that the screen is reprinting. I know I have a long way to guy, and I'm not asking for anyone to write or clean my code up for me. I want to do as much of this on my own as possible. That way I can guarantee that I fully understand what all is going on inside the program.

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

using namespace std;

bool keepPlaying = true;
char movement = 'w';
char character = '#';
int yCord = 20;
int xCord = 20;
bool input = true;

int main()
{
    char startZone[29][79] = {array here; had to remove due to size restrictions but it was just an array of ' ' and 'x' to create a rectangular box}

   startZone[yCord][xCord] = character;

    do
    {
            for(int row = 0; row < 29; row++)
            {
                for(int column = 0; column < 79; column++)
                {
                    cout << startZone[row][column];
                }
            cout << endl;
            }

        movement = _getch();

        if (movement == 'd')
        {
            xCord = xCord++;
        }
        if (movement == 'a')
        {
            xCord = xCord--;
        }
        if (movement == 'w')
        {
            yCord = yCord++;
        }
        if (movement == 's')
        {
            yCord = yCord--;
        }
    }while(input);



    return 0;
}
Topic archived. No new replies allowed.