Console Layout Control "Windows.h" experts needed

Hi guys,

I am working right not on a little stub program to make sure everything is working fine before delving into the actual project. I a new to the windows.h library so please bear with me.

Here's the code...

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
#include <iostream>
#include <Windows.h>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <string>

using namespace std;


char world[20][20]={'0','0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0','0','0',' ','0',
					'0',' ',' ',' ','0','0','0',' ',' ',' ','0','0','0',' ','0','0','0','0',' ','0',
					'0',' ',' ','0','0','0','0',' ','0',' ',' ','0','0',' ',' ','0','0','0',' ','0',
					'0',' ',' ','0','0','0','0',' ','0','0',' ','0','0',' ',' ','0','0','0',' ','0',
					'0',' ',' ','0','0','0','0',' ','0','0',' ','0',' ',' ',' ',' ','0','0',' ','0',
					'0','0',' ',' ',' ','0',' ',' ','0','0',' ',' ',' ',' ',' ',' ','0','0',' ','0',
					'0','0',' ',' ',' ','0',' ','0','0','0','0','0',' ',' ',' ',' ','0','0',' ','0',
					'0','0',' ',' ',' ',' ',' ',' ',' ','0','0','0',' ',' ',' ',' ',' ','0',' ','0',
					'0','0','0','0','0','0','0','0',' ','0','0',' ',' ',' ','0',' ',' ','0',' ','0',
					'0','0','0','0','0','0','0','0',' ','0','0',' ',' ','0','0','0',' ','0',' ','0',
					'0','0','0','0','0','0','0','0',' ',' ',' ',' ',' ','0','0','0',' ',' ',' ','0',
					'0',' ',' ',' ','0','0','0',' ',' ','0',' ',' ',' ','0','0','0','0',' ',' ','0',
					'0',' ','0','0','0','0','0',' ','0','0',' ',' ',' ',' ','0','0','0',' ',' ','0',
					'0',' ','0','0','0','0','0',' ','0','0','0',' ',' ',' ','0','0','0','0',' ','0',
					'0',' ',' ','0','0','0','0',' ','0','0','0','0',' ','0','0','0',' ',' ',' ','0',
					'0','0',' ',' ',' ','0',' ',' ','0','0','0','0',' ','0','0','0',' ','0',' ','0',
					'0','0',' ',' ',' ','0',' ','0','0','0','0','0',' ','0','0','0',' ','0',' ','0',
					'0','0',' ',' ',' ',' ',' ',' ',' ','0','0','0',' ','0','0','0',' ','0',' ','0',
					'0','0','0','0','0','0','0','0',' ','0','0','0',' ',' ',' ',' ',' ','0',' ','0',
					'0','0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0','0','0',' ','0',

					};


void print_world(char w[20][20],const int number, int& the_x, int& the_y);
void clear_screen();
bool check_collision(char w[][20], int the_size, int the_x, int the_y);

int main(){

	char dummy;
	int x=1, y=1;
	bool collision;

	do{
			
		clear_screen();
		

		if(GetAsyncKeyState(VK_RIGHT)){
			x++;
			collision=check_collision(world,20,x,y);
			if(collision)
				x--;


		}
		if(GetAsyncKeyState(VK_LEFT)){
			x--;
			collision=check_collision(world,20,x,y);
			if(collision)
				x++;

		}
		if(GetAsyncKeyState(VK_UP)){
			y--;
			collision=check_collision(world,20,x,y);
			if(collision)
				y++;


		}
		if(GetAsyncKeyState(VK_DOWN)){
			y++;
			collision=check_collision(world,20,x,y);
			if(collision)
				y--;

		}

		print_world(world,20,x,y);

		Sleep(100);


	}while(true);

	cin>>dummy;


	return 0;
}

void print_world(char w[20][20],const int number, int& the_x, int& the_y){

	for(int i=0;i<number;i++){

		for(int j=0;j<number;j++){
			
		
			if(the_x==j && the_y==i)
				cout<<'x';

			else if(w[i][j]=='0')
				cout<<static_cast<char>(178);

			else 
				cout<<world[i][j];	

		}
		
		cout<<endl;
	
	}
}
bool check_collision(char w[][20], int the_size, int the_x, int the_y){

	for(int i=0;i<the_size;i++){
	
		for(int j=0;j<the_size;j++){
			
			if(w[the_y][the_x]=='0')
				return true;
			else
				return false;
		}
	
	}
}
void clear_screen(){//need windows header file for this

	HANDLE handle_out;
	COORD position;

	handle_out=GetStdHandle(STD_OUTPUT_HANDLE);//std output handle is the monitor

	position.X=0;
	position.Y=0;

	SetConsoleCursorPosition(handle_out,position);//sets cursor in the specified position
}



Idea is simply, move a player on a map, and check for walls.

Issue #1:
Here's what I would like to add. To the right of the map, say a \t over, the player's stats such as strength, mana etc. However, with the map in the way, I am not sure how to program this as it's looping through a 2D array.

Issue #2:
When I add messages to the bottom of the program, and the text hits the bottom of console, the whole thing starts jumping up and down. How do I make the text fall off the bottom of the screen while holding everything else constant?

Issue #3:
How do I switch between cin>>some_stuff; and the GetAsyncKeyState(xxx); states?

Thanks for your time guys,

MIke
Topic archived. No new replies allowed.