-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
130 lines (120 loc) · 2.96 KB
/
Copy pathmain.cpp
File metadata and controls
130 lines (120 loc) · 2.96 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "cPeoPle.h"
#include "game.h"
#include <conio.h>
#include <thread>
game *cg;
char MOVING;
void FixConsoleWindow()
{
HWND consoleWindow = GetConsoleWindow();
LONG style = GetWindowLong(consoleWindow, GWL_STYLE);
style = style & ~(WS_MAXIMIZEBOX) & ~(WS_THICKFRAME);
SetWindowLong(consoleWindow, GWL_STYLE, style);
}
void ShowCur(bool CursorVisibility) // xóa dấu con trỏ
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor = { 1, CursorVisibility };
SetConsoleCursorInfo(handle, &cursor);
}
void SubThread()
{
while (cg->isRunning())
{
//delete[]
if (!cg->getPeople().isDead()) //Nếu người vẫn còn sống
{
cg->updatePosPeople(MOVING);//Cập nhật vị trí người theo thông tin từ main
}
MOVING = ' ';// Tạm khóa không cho di chuyển, chờ nhận phím từ hàm main
if (!cg->getTraffic().getStatus())
{
cg->updatePosVehicle();//Cập nhật vị trí xe
}
cg->updatePosAnimal(); //Cập nhật vị trí thú
cg->updateTraffic();
cg->drawGame(); //ve
int lv = cg->getLevel();
if (cg->getPeople().isImpact(cg->getBird(), lv) || cg->getPeople().isImpact(cg->getDinausou(), lv)
|| cg->getPeople().isImpact(cg->getCar(), lv) || cg->getPeople().isImpact(cg->getTruck(), lv))
{
//xử lí khi chết
mciSendStringA("stop nen.mp3", 0, NULL, 0);
mciSendStringA("play die.mp3", 0, NULL, 0);
cg->drawDie();
gotoXY(1, HEIGHT + 3);
cout << " nhan Y de tiep tuc tro choi";
char temp = toupper(_getch());
if (temp == 'Y')
{
system("pause");
cg->startGame();
mciSendStringA("play nen.mp3", 0, NULL, 0);
cg->resetGame(LV_MIN);
}
else
exit(0);
}
if (cg->getPeople().isFinish())
{
// Xử lý khi về đích
// cho level tang, xoaa het vat can sau do ve lai.
cg->lvUp();
}
Sleep(cg->speedGame());
}
}
void main()
{
cg = new game;
char temp;
FixConsoleWindow();
cg->DangNhap();
mciSendStringA("play nen.mp3", 0, NULL, 0);
thread t1(SubThread);
while (1)
{
ShowCur(false); //xóa dấu nháy con trỏ.
temp = toupper(_getch());
if (!cg->getPeople().isDead())
{
if (temp == 27)
{
cg->exitGame(t1.native_handle());
}
else if (temp == 'P')
{
cg->pauseGame(t1.native_handle());
}
else if (temp == 'L')
{
cg->pauseGame(t1.native_handle());
cg->saveGame();
}
else if (temp == 'T')
{
mciSendStringA("stop nen.mp3", 0, NULL, 0);
cg->pauseGame(t1.native_handle());
system("cls");
cg->loadGame();
cg->startGame();
cg->drawGame();
mciSendStringA("play nen.mp3", 0, NULL, 0);
}
else
{
cg->resumeGame((HANDLE)t1.native_handle());
MOVING = temp; //Cập nhật bước di chuyển
}
}
else
{
if (temp == 'Y')
cg->startGame();
else {
cg->exitGame(t1.native_handle());
return;
}
}
}
}