You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.1 KiB
67 lines
1.1 KiB
#include <conio.h>
|
|
#include "game.h"
|
|
#include "define.h"
|
|
|
|
void Game::Load()
|
|
{
|
|
Start();
|
|
End(Loop());
|
|
}
|
|
|
|
bool Game::Loop()
|
|
{
|
|
char key;
|
|
int dir = DIR_NONE, last_dir;
|
|
while (1)
|
|
{
|
|
key = GetKey();
|
|
last_dir = dir;
|
|
switch (key)
|
|
{
|
|
case 'p': Pause(); break;
|
|
case 'q': return false; break;
|
|
case 'w': dir = DIR_UP; break;
|
|
case 's': dir = DIR_DOWN; break;
|
|
case 'a': dir = DIR_LEFT; break;
|
|
case 'd': dir = DIR_RIGHT; break;
|
|
default: dir = last_dir; break;
|
|
}
|
|
|
|
if (player.PlayerMove(wall, dir))
|
|
{
|
|
if (player.TryEatBean(bean))
|
|
{
|
|
if (bean.IsEmpty() && goldBean.IsEmpty())
|
|
return true;
|
|
}
|
|
if (player.TryEatGoldBean(goldBean))
|
|
{
|
|
if (bean.IsEmpty() && goldBean.IsEmpty())
|
|
return true;
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
monster[i].SetSpeed(MONSTER_ESCAPE_SPEED);
|
|
monster[i].SetStatus(MONSTER_ESCAPE_STATUS);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
if (monster[i].TryEatPlayer(player))
|
|
return false;
|
|
monster[i].MonsterMove(wall, player, bean, goldBean);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
char Game::GetKey()
|
|
{
|
|
char key = 0;
|
|
if (_kbhit())
|
|
{
|
|
key = _getch();
|
|
}
|
|
return key;
|
|
}
|