📄 game.cpp
字号:
#include "stdafx.h"
#include "Game.h"
Game::Game(void)
{
this->score = 0;
this->stillProcessing = false;
this->EnterGame = false;
this->time = 500;
this->level =1;
this->engine = NULL;
this->CurrentBlock = NULL;
this->nextBlock = NULL;
}
Game::Game(HDC hdc,DOCINFO *info)
{
this->score = 0;
this->stillProcessing = false;
this->EnterGame = false;
this->time = 500;
this->level =1;
this->engine = new GameField(hdc,*info);
this->CurrentBlock = new Block(Point(GameField::SquareSize*(GameField::Width/2),
GameField::SquareSize*(GameField::Height -3)),BlockTypes::Undefined,*engine);
this->nextBlock = new Block(Point(GameField::SquareSize*(GameField::Width+5),
GameField::SquareSize*(GameField::Height-20)),BlockTypes::Undefined,*engine);
}
Game::~Game(void)
{
if(this->engine != NULL)
delete engine;
if(this->CurrentBlock != NULL)
delete CurrentBlock;
if(this->nextBlock != NULL)
delete nextBlock;
}
bool Game::ReDraw()
{
if(EnterGame)
engine->Redraw();
else
return false;
return true;
}
bool Game::SetHDC(HDC &hdc)
{
this->engine->hdc = &hdc;
return true;
}
bool Game::Init(HDC *hdc, DOCINFO *info)
{
this->engine = new GameField(*hdc,*info);
this->CurrentBlock = new Block(Point(GameField::SquareSize*(GameField::Width/2),
GameField::SquareSize*(2)),BlockTypes::Undefined,*engine);
this->nextBlock = new Block(Point(GameField::SquareSize*(GameField::Width+5),
GameField::SquareSize*(GameField::Height-20)),BlockTypes::Undefined,*engine);
return true;
}
bool Game::Start()
{
if(!this->EnterGame)
return false;
this->stillProcessing = true;
return true;
}
bool Game::Stop()
{
if(!this->EnterGame)
return false;
this->stillProcessing = false;
return true;
}
bool Game::NextOne()
{
delete this->CurrentBlock;
CurrentBlock = new Block(Point(GameField::SquareSize*(GameField::Width/2),
GameField::SquareSize),nextBlock->GetType(),*engine);
delete this->nextBlock;
nextBlock = new Block(Point(GameField::SquareSize*(GameField::Width+5),
GameField::SquareSize*(GameField::Height-20)),BlockTypes::Undefined,*engine);
return true;
}
bool Game::GetProcessing()
{
return this->stillProcessing;
}
int Game::GetTime()
{
return this->time;
}
void Game::Switch()
{
this->stillProcessing = ! this->stillProcessing;
}
int Game::GetLevel()
{
return this->level;
}
bool Game::Go()
{
switch(this->score)
{
case 2000:
if(level == 1)
{
this->time -= 100;
level++;
}
break;
case 5000:
if(level == 2)
{
this->time -= 100;
level++;
}
break;
case 8000:
if(level == 3)
{
this->time -= 100;
level++;
}
break;
case 11000:
if(level == 4)
{
this->time -= 100;
level++;
}
break;
case 15000:
if(level == 5)
{
this->time -= 50;
level++;
}
break;
case 20000:
return true;
default:
break;
}
return false;
}
void Game::ReStrat()
{
delete this->CurrentBlock;
delete this->nextBlock;
this->CurrentBlock = new Block(Point(GameField::SquareSize*(GameField::Width/2),
GameField::SquareSize*(2)),BlockTypes::Undefined,*engine);
this->nextBlock = new Block(Point(GameField::SquareSize*(GameField::Width+5),
GameField::SquareSize*(GameField::Height-20)),BlockTypes::Undefined,*engine);
this->time = 500;
this->score = 0;
this->level = 1 ;
this->EnterGame = false;
this->stillProcessing = false;
this->engine->Clear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -