-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeader.cpp
More file actions
111 lines (97 loc) · 2.12 KB
/
Copy pathHeader.cpp
File metadata and controls
111 lines (97 loc) · 2.12 KB
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
#pragma once
#include "Header.h"
ControlKeys::ControlKeys()
{
Right = VK_RIGHT;
Left = VK_LEFT;
}
Car::Car() {
shape = " |*|\n |\n|***|";
}
Game::Game()
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO area;
GetConsoleScreenBufferInfo(hStdOut, &area);
bottom_limit = area.srWindow.Bottom - 10; //-10 Bottom Offset
top_limit = area.srWindow.Top;
left_limit = area.srWindow.Left;
right_limit = area.srWindow.Right;
//cout << right_limit << " " << bottom_limit << endl;
//cout << right_limit/2 << " " << bottom_limit/2 << endl;
int j = -1, max = 0, h = 0 ;
for (int i = 0; i < (car.shape).length() ; i++) {
if (car.shape[i] == '\n') {
player.push_back("");
j++;
continue;
}
if (i == 0) {
player.push_back("");
j++;
}
player[j] = player[j] + car.shape[i];
}
car.bottom_b = j;
car.top_b = 0;
j = 0;
for (auto i = player.begin(); i != player.end(); ++i)
{
h = (*i).length();
if (h > max) {
max = h;
car.max_i = j;
}
j++;
}
car.left_b = 0;
car.right_b = max;
for (int i = 0; i < bottom_limit; i++) {
game_lines.push_back("|");
for (int j = 0;j < right_limit - 1;j++) {
if (i ==(int)((float)(bottom_limit / 1.2)) && j == right_limit / 2) {
//cout << j << " " << i << endl;
car.posX = j + 1;
car.posY = i;
}
game_lines[i] = game_lines[i] + " ";
}
game_lines[i] = game_lines[i] + "|\n";
}
for (int i = 0;i < bottom_limit;i++) {
for (int j = 0;j < right_limit - 1; j++) {
if (i == car.posY && j == car.posX) {
int f = 0;
for (int k = 0;k < player.size();k++) {
for (f = 0;f < player[k].length(); f++) {
(game_lines[i])[j+f] = (player[k])[f];
}
i++;
}
j = j + f;
}
}
}
}
void Game::DisplayGame()
{
for (auto i = game_lines.begin(); i != game_lines.end(); ++i)
cout << *i;
}
void Game::DisplayPlayer()
{
for (auto i = player.begin(); i != player.end(); ++i)
cout << *i <<endl;
cout << car.max_i << " " << car.right_b << " " << car.bottom_b << endl;
}
Obstacle::Obstacle()
{
posX = 1;
posY = 1;
shape = "=====";
}
void Obstacle::setPosition(int x, int y)
{
posX = x;
posY = y;
}