|
|
|
|
#include "Game.h"
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#include <graphics.h>
|
|
|
|
|
#define KEY_DOWN(vKey) ((GetAsyncKeyState(vKey) & 0x8000) ? 1:0)
|
|
|
|
|
Game::Game()
|
|
|
|
|
{
|
|
|
|
|
m_snake2 = new Snake(250);
|
|
|
|
|
this->m_snake = nullptr;
|
|
|
|
|
this->m_food = nullptr;
|
|
|
|
|
|
|
|
|
|
this->m_GameState = 0;
|
|
|
|
|
this->m_msg = PlayerMsg();
|
|
|
|
|
this->m_ranklist = new RankList();
|
|
|
|
|
}
|
|
|
|
|
Game::~Game()
|
|
|
|
|
{
|
|
|
|
|
delete m_snake;
|
|
|
|
|
delete m_snake2;
|
|
|
|
|
}
|
|
|
|
|
void Game::Init()
|
|
|
|
|
{
|
|
|
|
|
initgraph(640, 480);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::Run()
|
|
|
|
|
{
|
|
|
|
|
ShowMainUI();
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (m_GameState == 0 && MouseHit()) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 240 && mouse.x <= 400 && mouse.y >= 175 && mouse.y <= 215)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>ʼѡ<CABC><D1A1>
|
|
|
|
|
ChangeChooseUI(240, 175, 400, 215, 1);
|
|
|
|
|
m_GameState = 1;
|
|
|
|
|
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
PlayGame();
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 240 && mouse.x <= 400 && mouse.y >= 295 && mouse.y <= 335)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>а<EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(240, 295, 400, 335, 2);
|
|
|
|
|
m_GameState = 2;
|
|
|
|
|
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
ShowRank();
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 240 && mouse.x <= 400 && mouse.y >= 355 && mouse.y <= 395)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(240, 355, 400, 395, 3);
|
|
|
|
|
m_GameState = 3;
|
|
|
|
|
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
ShowRule();
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 240 && mouse.x <= 400 && mouse.y >= 415 && mouse.y <= 455)
|
|
|
|
|
{
|
|
|
|
|
//<2F>˳<EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(240, 415, 400, 455, 4);
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 240 && mouse.x <= 400 && mouse.y >= 235 && mouse.y <= 275)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>ʼѡ<CABC><D1A1>
|
|
|
|
|
ChangeChooseUI(240, 235, 400, 275, 5);
|
|
|
|
|
m_GameState = 5;
|
|
|
|
|
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
Sleep(500);
|
|
|
|
|
PlayGame2();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((m_GameState == 2 || m_GameState == 3) && MouseHit()) //<2F><><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 20 && mouse.x <= 63 && mouse.y >= 20 && mouse.y <= 43)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(20, 20, 63, 43, 6);
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
m_GameState = 0;
|
|
|
|
|
ShowMainUI();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::Close()
|
|
|
|
|
{
|
|
|
|
|
closegraph();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::InitData()
|
|
|
|
|
{
|
|
|
|
|
if (this->m_snake != nullptr)
|
|
|
|
|
{
|
|
|
|
|
delete(this->m_snake);
|
|
|
|
|
this->m_snake = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (this->m_food != nullptr)
|
|
|
|
|
{
|
|
|
|
|
delete(this->m_food);
|
|
|
|
|
this->m_food = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->m_msg = PlayerMsg();
|
|
|
|
|
this->m_snake = new Snake();
|
|
|
|
|
this->m_food = new Food();
|
|
|
|
|
}
|
|
|
|
|
void Game::InitData2()
|
|
|
|
|
{
|
|
|
|
|
if (this->m_snake != nullptr)
|
|
|
|
|
{
|
|
|
|
|
delete(this->m_snake);
|
|
|
|
|
this->m_snake = nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (this->m_food != nullptr)
|
|
|
|
|
{
|
|
|
|
|
delete(this->m_food);
|
|
|
|
|
this->m_food = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->m_msg = PlayerMsg();
|
|
|
|
|
|
|
|
|
|
this->m_snake = new Snake();
|
|
|
|
|
this->m_food = new Food();
|
|
|
|
|
|
|
|
|
|
if (this->m_snake2 != nullptr)
|
|
|
|
|
{
|
|
|
|
|
delete(this->m_snake2);
|
|
|
|
|
this->m_snake2 = nullptr;
|
|
|
|
|
}
|
|
|
|
|
this->m_snake2 = new Snake(250);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::PlayGame()
|
|
|
|
|
{
|
|
|
|
|
InitData2();
|
|
|
|
|
DrawGamePlay();
|
|
|
|
|
|
|
|
|
|
BeginBatchDraw();
|
|
|
|
|
|
|
|
|
|
bool backMainUI = false;
|
|
|
|
|
bool rePlayGame = false;
|
|
|
|
|
bool changeShowData = false;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
changeShowData = false;
|
|
|
|
|
//ʳ<><CAB3>
|
|
|
|
|
if (this->m_food->getState() == false)
|
|
|
|
|
{
|
|
|
|
|
m_food->Generate(this->m_snake);
|
|
|
|
|
m_food->DrawFood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case 72: //<2F><>
|
|
|
|
|
case 119: //w
|
|
|
|
|
case 87:
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_UP);
|
|
|
|
|
break;
|
|
|
|
|
case 80: //<2F><>
|
|
|
|
|
case 115: //s
|
|
|
|
|
case 83:
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_DOWN);
|
|
|
|
|
break;
|
|
|
|
|
case 75: //<2F><>
|
|
|
|
|
case 97: //a
|
|
|
|
|
case 65:
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_LEFT);
|
|
|
|
|
break;
|
|
|
|
|
case 77: //<2F><>
|
|
|
|
|
case 100: //d
|
|
|
|
|
case 68:
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_RIGHT);
|
|
|
|
|
break;
|
|
|
|
|
case 99: //c <20><><EFBFBD><EFBFBD>
|
|
|
|
|
case 67:
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->getSpeed() + 1);
|
|
|
|
|
break;
|
|
|
|
|
case 120://x <20><><EFBFBD><EFBFBD>
|
|
|
|
|
case 88:
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->getSpeed() - 1);
|
|
|
|
|
break;
|
|
|
|
|
case 122://z <20>ع<EFBFBD>ԭ<EFBFBD><D4AD>
|
|
|
|
|
case 90:
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->OrgSpeed);
|
|
|
|
|
break;
|
|
|
|
|
case 32: //<2F>ո<EFBFBD><D5B8><EFBFBD>ͣ
|
|
|
|
|
DrawPause(); //״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
if (key == 32) //<2F><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ClearRegion(505, 240, 640, 480);
|
|
|
|
|
DrawRunning(); //<2F><><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 27) //esc<73><63> <20>˳<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseHit())
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 347 && mouse.y <= 373)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|
|
|
|
if (changeShowData)
|
|
|
|
|
{
|
|
|
|
|
ClearRegion(505, 115, 640, 200);
|
|
|
|
|
DrawScore();
|
|
|
|
|
DrawSnakeLen();
|
|
|
|
|
DrawSpeed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>ƶ<EFBFBD>
|
|
|
|
|
m_snake->Move();
|
|
|
|
|
//<2F><>ʳ<EFBFBD><CAB3>
|
|
|
|
|
if (m_snake->ColideFood(m_food->getPos()))
|
|
|
|
|
{
|
|
|
|
|
m_snake->EatFood();
|
|
|
|
|
|
|
|
|
|
this->m_food->setState(false);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
this->m_msg.score += 10;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(505, 115, 640, 200);
|
|
|
|
|
DrawScore();
|
|
|
|
|
DrawSnakeLen();
|
|
|
|
|
DrawSpeed();
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>
|
|
|
|
|
if (m_snake->ColideWall(10, 10, 470, 470) || m_snake->ColideSnake())
|
|
|
|
|
{
|
|
|
|
|
////<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|
|
|
|
m_snake->Dead();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(0, 0, 479, 480);
|
|
|
|
|
|
|
|
|
|
m_snake->DrawSnake();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿<EFBFBD>ʼ
|
|
|
|
|
DrawRebegin();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>GameOVer
|
|
|
|
|
DrawGameOver();
|
|
|
|
|
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
if (key == 32) //<2F><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 8);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 27) //esc<73><63> <20>˳<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseHit())
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 347 && mouse.y <= 373)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 397 && mouse.y <= 423)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 8);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
|
|
|
|
|
if (rePlayGame)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
ClearRegion(0, 0, 479, 480);
|
|
|
|
|
|
|
|
|
|
this->m_snake->DrawSnake();
|
|
|
|
|
|
|
|
|
|
if (this->m_food->getState() == true)
|
|
|
|
|
{
|
|
|
|
|
m_food->DrawFood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
int sleep = 30 - m_snake->getSpeed();
|
|
|
|
|
Sleep(sleep * 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
m_msg.len = m_snake->getLen();
|
|
|
|
|
|
|
|
|
|
m_ranklist->SaveMsg(m_msg);
|
|
|
|
|
m_ranklist->SaveToRank();
|
|
|
|
|
|
|
|
|
|
m_GameState = 0;
|
|
|
|
|
ShowMainUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
|
|
|
|
|
if (rePlayGame)
|
|
|
|
|
{
|
|
|
|
|
m_msg.len = m_snake->getLen();
|
|
|
|
|
|
|
|
|
|
m_ranklist->SaveMsg(m_msg);
|
|
|
|
|
m_ranklist->SaveToRank();
|
|
|
|
|
|
|
|
|
|
PlayGame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void Game::PlayGame2()
|
|
|
|
|
{
|
|
|
|
|
InitData2();
|
|
|
|
|
DrawGamePlay2();
|
|
|
|
|
|
|
|
|
|
BeginBatchDraw();
|
|
|
|
|
|
|
|
|
|
bool backMainUI = false;
|
|
|
|
|
bool rePlayGame = false;
|
|
|
|
|
bool changeShowData = false;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
changeShowData = false;
|
|
|
|
|
//ʳ<><CAB3>
|
|
|
|
|
if (this->m_food->getState() == false)
|
|
|
|
|
{
|
|
|
|
|
m_food->Generate(this->m_snake);
|
|
|
|
|
m_food->DrawFood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case 72: //<2F><>
|
|
|
|
|
m_snake2->ChangeDir(Dir::DIR_UP);
|
|
|
|
|
break;
|
|
|
|
|
case 119: //w
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_UP);
|
|
|
|
|
break;
|
|
|
|
|
case 80: //<2F><>
|
|
|
|
|
m_snake2->ChangeDir(Dir::DIR_DOWN);
|
|
|
|
|
break;
|
|
|
|
|
case 115: //s
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_DOWN);
|
|
|
|
|
break;
|
|
|
|
|
case 75: //<2F><>
|
|
|
|
|
m_snake2->ChangeDir(Dir::DIR_LEFT);
|
|
|
|
|
break;
|
|
|
|
|
case 97: //a
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_LEFT);
|
|
|
|
|
break;
|
|
|
|
|
case 77: //<2F><>
|
|
|
|
|
m_snake2->ChangeDir(Dir::DIR_RIGHT);
|
|
|
|
|
break;
|
|
|
|
|
case 100: //d
|
|
|
|
|
m_snake->ChangeDir(Dir::DIR_RIGHT);
|
|
|
|
|
break;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
case 99: //c <20><><EFBFBD><EFBFBD>
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->getSpeed() + 1);
|
|
|
|
|
break;
|
|
|
|
|
case 120://x <20><><EFBFBD><EFBFBD>
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->getSpeed() - 1);
|
|
|
|
|
break;
|
|
|
|
|
case 122://z <20>ع<EFBFBD>ԭ<EFBFBD><D4AD>
|
|
|
|
|
changeShowData = m_snake->setSpeed(m_snake->OrgSpeed);
|
|
|
|
|
break;
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҷ<EFBFBD><D2B6>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
case '1'://1 <20><><EFBFBD><EFBFBD>
|
|
|
|
|
changeShowData = m_snake2->setSpeed(m_snake2->getSpeed() + 1);
|
|
|
|
|
break;
|
|
|
|
|
case '2'://2 <20><><EFBFBD><EFBFBD>
|
|
|
|
|
changeShowData = m_snake2->setSpeed(m_snake2->getSpeed() - 1);
|
|
|
|
|
break;
|
|
|
|
|
case '3'://3 <20>ع<EFBFBD>ԭ<EFBFBD><D4AD>
|
|
|
|
|
changeShowData = m_snake2->setSpeed(m_snake2->OrgSpeed);
|
|
|
|
|
break;
|
|
|
|
|
case 32: //<2F>ո<EFBFBD><D5B8><EFBFBD>ͣ
|
|
|
|
|
DrawPause(); //״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʾ
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
if (key == 32) //<2F><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ClearRegion(505, 240, 640, 480);
|
|
|
|
|
DrawRunning(); //<2F><><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 27) //esc<73><63> <20>˳<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseHit())
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 347 && mouse.y <= 373)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|
|
|
|
if (changeShowData)
|
|
|
|
|
{
|
|
|
|
|
ClearRegion(505, 115, 640, 200);
|
|
|
|
|
//DrawScore();
|
|
|
|
|
DrawSnakeLen2();
|
|
|
|
|
DrawSpeed2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>ƶ<EFBFBD>
|
|
|
|
|
m_snake->Move();
|
|
|
|
|
m_snake2->Move();
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>ʳ<EFBFBD><CAB3><EFBFBD>ĵط<C4B5><D8B7><EFBFBD><EFBFBD>뻥<EFBFBD><EBBBA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (m_snake->ColideFood(m_food->getPos()))
|
|
|
|
|
{
|
|
|
|
|
m_snake->EatFood();
|
|
|
|
|
this->m_food->setState(false);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
this->m_msg.score += 10;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(505, 115, 640, 200);
|
|
|
|
|
DrawScore();
|
|
|
|
|
DrawSnakeLen2();
|
|
|
|
|
DrawSpeed2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_snake2->ColideFood(m_food->getPos()))
|
|
|
|
|
{
|
|
|
|
|
m_snake2->EatFood();
|
|
|
|
|
this->m_food->setState(false);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
this->m_msg2.score += 10;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(505, 115, 640, 200);
|
|
|
|
|
DrawScore();
|
|
|
|
|
DrawSnakeLen2();
|
|
|
|
|
DrawSpeed2();
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>
|
|
|
|
|
if (m_snake->ColideWall(10, 10, 470, 470) || m_snake->ColideSnake2(*m_snake2))
|
|
|
|
|
{
|
|
|
|
|
////<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|
|
|
|
m_snake->Dead();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(0, 0, 479, 480);
|
|
|
|
|
|
|
|
|
|
m_snake->DrawSnake();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿<EFBFBD>ʼ
|
|
|
|
|
DrawRebegin();
|
|
|
|
|
settextcolor(0x5555FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 220, L"player2 win");
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>GameOVer
|
|
|
|
|
DrawGameOver();
|
|
|
|
|
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
if (key == 32) //<2F><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 27) //esc<73><63> <20>˳<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseHit())
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 347 && mouse.y <= 373)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 397 && mouse.y <= 423)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
|
|
|
|
|
if (rePlayGame)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_snake2->ColideWall(10, 10, 470, 470) || m_snake2->ColideSnake2(*m_snake))
|
|
|
|
|
{
|
|
|
|
|
////<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|
|
|
|
m_snake2->Dead();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD>
|
|
|
|
|
ClearRegion(0, 0, 479, 480);
|
|
|
|
|
|
|
|
|
|
m_snake2->DrawSnake2();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¿<EFBFBD>ʼ
|
|
|
|
|
DrawRebegin();
|
|
|
|
|
settextcolor(0x5555FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 220, L"player1 win");
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>GameOVer
|
|
|
|
|
DrawGameOver();
|
|
|
|
|
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (_kbhit())
|
|
|
|
|
{
|
|
|
|
|
char key = _getch();
|
|
|
|
|
if (key == 32) //<2F><><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 27) //esc<73><63> <20>˳<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MouseHit())
|
|
|
|
|
{
|
|
|
|
|
MOUSEMSG mouse = GetMouseMsg();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
if (mouse.mkLButton)
|
|
|
|
|
{
|
|
|
|
|
if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 347 && mouse.y <= 373)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 347, 588, 373, 6);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
backMainUI = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (mouse.x >= 510 && mouse.x <= 588 && mouse.y >= 397 && mouse.y <= 423)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѡ<EFBFBD><D1A1>
|
|
|
|
|
ChangeChooseUI(510, 397, 588, 423, 7);
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Sleep(500);
|
|
|
|
|
|
|
|
|
|
rePlayGame = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
|
|
|
|
|
if (rePlayGame)
|
|
|
|
|
{
|
|
|
|
|
FlushMouseMsgBuffer();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
ClearRegion(0, 0, 479, 480);
|
|
|
|
|
|
|
|
|
|
this->m_snake->DrawSnake();
|
|
|
|
|
this->m_snake2->DrawSnake2();
|
|
|
|
|
if (this->m_food->getState() == true)
|
|
|
|
|
{
|
|
|
|
|
m_food->DrawFood();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FlushBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
int sleep = 30 - m_snake->getSpeed();
|
|
|
|
|
Sleep(sleep * 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndBatchDraw();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD>UI
|
|
|
|
|
if (backMainUI)
|
|
|
|
|
{
|
|
|
|
|
m_msg.len = m_snake->getLen();
|
|
|
|
|
|
|
|
|
|
m_ranklist->SaveMsg(m_msg);
|
|
|
|
|
m_ranklist->SaveToRank();
|
|
|
|
|
|
|
|
|
|
m_GameState = 0;
|
|
|
|
|
ShowMainUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
|
|
|
|
|
if (rePlayGame)
|
|
|
|
|
{
|
|
|
|
|
m_msg.len = m_snake->getLen();
|
|
|
|
|
|
|
|
|
|
m_ranklist->SaveMsg(m_msg);
|
|
|
|
|
m_ranklist->SaveToRank();
|
|
|
|
|
|
|
|
|
|
PlayGame2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::ShowMainUI()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
cleardevice();
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>----------*/
|
|
|
|
|
settextstyle(80, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
outtextxy(230, 60, L"̰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>----------*/
|
|
|
|
|
|
|
|
|
|
setlinecolor(0xFF00FF);
|
|
|
|
|
rectangle(240, 175, 400, 215);
|
|
|
|
|
rectangle(240, 235, 400, 275);
|
|
|
|
|
rectangle(240, 295, 400, 335);
|
|
|
|
|
rectangle(240, 355, 400, 395);
|
|
|
|
|
rectangle(240, 415, 400, 455);
|
|
|
|
|
|
|
|
|
|
settextstyle(28, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0x55FFFF);//<2F><>ɫ
|
|
|
|
|
|
|
|
|
|
outtextxy(276, 180, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ");
|
|
|
|
|
outtextxy(276, 240, L"˫<EFBFBD><EFBFBD>ģʽ");
|
|
|
|
|
outtextxy(287, 300, L"<EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>");
|
|
|
|
|
outtextxy(297, 360, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(297, 420, L"<EFBFBD>˳<EFBFBD>");
|
|
|
|
|
settextstyle(24, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0xAAAAAA);
|
|
|
|
|
outtextxy(255, 450, L"(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CharToTCHAR(const char* _char, TCHAR* tchar)
|
|
|
|
|
{
|
|
|
|
|
int iLength;
|
|
|
|
|
iLength = MultiByteToWideChar(CP_UTF8, 0, _char, strlen(_char) + 1, NULL, 0);
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, _char, strlen(_char) + 1, tchar, iLength);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::ShowRank()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
cleardevice();
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>----------*/
|
|
|
|
|
settextstyle(60, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
outtextxy(160, 40, L"̰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>");
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD>Ʒ<EFBFBD><C6B7>ؼ<EFBFBD>----------*/
|
|
|
|
|
setlinecolor(0xFFFFFF);
|
|
|
|
|
rectangle(20, 20, 63, 43);
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(20, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(22, 22, L" <20><> ");
|
|
|
|
|
|
|
|
|
|
/*---------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD>Ϣ---------------*/
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(20, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(140, 120, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(240, 120, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(340, 120, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(490, 120, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
|
|
|
|
std::vector<PlayerMsg> msg = m_ranklist->getRankList();
|
|
|
|
|
if (msg.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x5555FF);
|
|
|
|
|
settextstyle(40, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(230, 200, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < msg.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x5555FF);
|
|
|
|
|
settextstyle(15, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(15, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
TCHAR t[40];
|
|
|
|
|
_stprintf_s(t, _T("%d"), msg[i].id);
|
|
|
|
|
outtextxy(145, 150 + 30 * i, t);
|
|
|
|
|
|
|
|
|
|
_stprintf_s(t, _T("%d"), msg[i].score);
|
|
|
|
|
outtextxy(245, 150 + 30 * i, t);
|
|
|
|
|
|
|
|
|
|
_stprintf_s(t, _T("%d"), msg[i].len);
|
|
|
|
|
outtextxy(345, 150 + 30 * i, t);
|
|
|
|
|
|
|
|
|
|
//_stprintf_s(t, _T("%s"), msg[i].r_time.c_str());
|
|
|
|
|
CharToTCHAR(msg[i].r_time.c_str(), t);
|
|
|
|
|
outtextxy(450, 150 + 30 * i, t);
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::ShowRule()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ<EFBFBD><C9AB>ɫ
|
|
|
|
|
cleardevice();
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>----------*/
|
|
|
|
|
settextstyle(60, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
outtextxy(160, 40, L"̰<EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(20, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(120, 150, L"<EFBFBD><EFBFBD> <20><> <20><> <20><> <20><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>(˫<><CBAB><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>Ҷ<EFBFBD>)");
|
|
|
|
|
outtextxy(120, 180, L"w a s d <20><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD>˫<EFBFBD><CBAB>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>");
|
|
|
|
|
outtextxy(230, 210, L"<EFBFBD>ٶȵȼ<EFBFBD>1-25<32><35>Ĭ<EFBFBD><C4AC>12");
|
|
|
|
|
outtextxy(70, 240, L"c<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>٣<EFBFBD>x<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>٣<EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ,<2C><><EFBFBD>Ҷ<EFBFBD> 1 <20><><EFBFBD>٣<EFBFBD>2 <20><><EFBFBD>٣<EFBFBD>");
|
|
|
|
|
outtextxy(90, 270, L"z<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ԭʼ<EFBFBD>ٶȣ<EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҷ<EFBFBD> 0 <20>ָ<EFBFBD><D6B8><EFBFBD>");
|
|
|
|
|
outtextxy(240, 300, L"<EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ/<2F><><EFBFBD><EFBFBD>");
|
|
|
|
|
|
|
|
|
|
outtextxy(180, 350, L"<EFBFBD>뽫<EFBFBD><EFBFBD><EFBFBD>뷨<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷨״̬<EFBFBD><EFBFBD>");
|
|
|
|
|
|
|
|
|
|
/*--------------<2D><><EFBFBD>Ʒ<EFBFBD><C6B7>ؼ<EFBFBD>----------*/
|
|
|
|
|
|
|
|
|
|
setlinecolor(0xFFFFFF);
|
|
|
|
|
rectangle(20, 20, 63, 43);
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(20, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(22, 22, L" <20><> ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawGamePlay()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
cleardevice();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ2<CEAA><32><EFBFBD><EFBFBD>ɫʵ<C9AB>ߣ<EFBFBD><DFA3>ָ<EFBFBD><D6B8><EFBFBD>Ϸ<EFBFBD><CFB7>
|
|
|
|
|
setlinecolor(BROWN);
|
|
|
|
|
setlinestyle(PS_SOLID, 2);
|
|
|
|
|
line(482, 0, 482, 480);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ߺ<EFBFBD>ʳ<EFBFBD><CAB3>
|
|
|
|
|
this->m_snake->DrawSnake();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>
|
|
|
|
|
DrawScore();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DrawSnakeLen();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
DrawSpeed();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ״̬
|
|
|
|
|
DrawRunning();
|
|
|
|
|
}
|
|
|
|
|
void Game::DrawGamePlay2()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
setbkcolor(BG_COLOR);//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫ
|
|
|
|
|
cleardevice();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ2<CEAA><32><EFBFBD><EFBFBD>ɫʵ<C9AB>ߣ<EFBFBD><DFA3>ָ<EFBFBD><D6B8><EFBFBD>Ϸ<EFBFBD><CFB7>
|
|
|
|
|
setlinecolor(BROWN);
|
|
|
|
|
setlinestyle(PS_SOLID, 2);
|
|
|
|
|
line(482, 0, 482, 480);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ߺ<EFBFBD>ʳ<EFBFBD><CAB3>
|
|
|
|
|
this->m_snake->DrawSnake();
|
|
|
|
|
this->m_snake2->DrawSnake();
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DrawSnakeLen2();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
DrawSpeed2();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ״̬
|
|
|
|
|
DrawRunning();
|
|
|
|
|
}
|
|
|
|
|
void Game::DrawScore()
|
|
|
|
|
{
|
|
|
|
|
TCHAR s[] = _T("<EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
settextstyle(16, 0, _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
outtextxy(510, 120, s);
|
|
|
|
|
|
|
|
|
|
settextcolor(0xFF5555);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
TCHAR t[5];
|
|
|
|
|
_stprintf_s(t, _T("%d"), m_msg.score);
|
|
|
|
|
outtextxy(590, 120, t);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawSnakeLen()
|
|
|
|
|
{
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 150, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>");
|
|
|
|
|
|
|
|
|
|
settextcolor(0xFF55FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
TCHAR t[5];
|
|
|
|
|
_stprintf_s(t, _T("%d"), m_snake->getLen());
|
|
|
|
|
outtextxy(590, 150, t);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawSpeed()
|
|
|
|
|
{
|
|
|
|
|
TCHAR s[] = _T("<EFBFBD><EFBFBD>ǰ<EFBFBD>ٶȣ<EFBFBD>");
|
|
|
|
|
settextstyle(16, 0, _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
outtextxy(510, 180, s);
|
|
|
|
|
|
|
|
|
|
int speed = m_snake->getSpeed();//<2F>ٶȵȼ<C8B5><C8BC><EFBFBD>ʾΪ1 - 25
|
|
|
|
|
if (speed <= 9)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x00AA00);//»
|
|
|
|
|
}
|
|
|
|
|
else if (speed >= 18)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x0000AA);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x55FFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
TCHAR t[5];
|
|
|
|
|
_stprintf_s(t, _T("%d"), speed);
|
|
|
|
|
outtextxy(590, 180, t);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
void Game::DrawSnakeLen2()
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 90, L"<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>");
|
|
|
|
|
|
|
|
|
|
settextcolor(0xFF55FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
TCHAR t[5];
|
|
|
|
|
_stprintf_s(t, _T("%d"), m_snake->getLen());
|
|
|
|
|
outtextxy(590, 90, t);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 150, L"<EFBFBD>߶<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>");
|
|
|
|
|
settextcolor(RED);//<2F><>
|
|
|
|
|
TCHAR c[5];
|
|
|
|
|
_stprintf_s(c, _T("%d"), m_snake2->getLen());
|
|
|
|
|
outtextxy(590, 150, c);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
void Game::DrawSpeed2()
|
|
|
|
|
{
|
|
|
|
|
TCHAR s[] = _T("<EFBFBD><EFBFBD>һ<EFBFBD>ٶȣ<EFBFBD>");
|
|
|
|
|
settextstyle(16, 0, _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
outtextxy(510, 120, s);
|
|
|
|
|
|
|
|
|
|
int speed = m_snake->getSpeed();//<2F>ٶȵȼ<C8B5><C8BC><EFBFBD>ʾΪ1 - 25
|
|
|
|
|
if (speed <= 9)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x00AA00);//»
|
|
|
|
|
}
|
|
|
|
|
else if (speed >= 18)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x0000AA);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x55FFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
TCHAR t[5];
|
|
|
|
|
_stprintf_s(t, _T("%d"), speed);
|
|
|
|
|
outtextxy(590, 120, t);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
TCHAR x[] = _T("<EFBFBD>߶<EFBFBD><EFBFBD>ٶȣ<EFBFBD>");
|
|
|
|
|
settextstyle(16, 0, _T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
outtextxy(510, 180, x);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
int speed2 = m_snake2->getSpeed();//<2F>ٶȵȼ<C8B5><C8BC><EFBFBD>ʾΪ1 - 25
|
|
|
|
|
if (speed2 <= 9)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x00AA00);//»
|
|
|
|
|
}
|
|
|
|
|
else if (speed >= 18)
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x0000AA);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x55FFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
TCHAR c[5];
|
|
|
|
|
_stprintf_s(c, _T("%d"), speed);
|
|
|
|
|
outtextxy(590, 180, c);
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
void Game::DrawRunning()
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x55FF55);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 250, L"<EFBFBD><EFBFBD>Ϸ <20><><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 280, L"ף<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawPause()
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0xFF55FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 250, L"<EFBFBD><EFBFBD>Ϸ <20><>ͣ");
|
|
|
|
|
outtextxy(510, 280, L"<EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 310, L"Esc<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>");
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
|
|
|
|
|
setlinecolor(0xFFFFFF);
|
|
|
|
|
rectangle(510, 347, 588, 373);
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(517, 352, L"<EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD>Ϸ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawRebegin()
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0x5555FF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 250, L"<EFBFBD><EFBFBD>Ϸ <20><><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 280, L"<EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(510, 310, L"Esc<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>");
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><>
|
|
|
|
|
|
|
|
|
|
setlinecolor(0xFFFFFF);
|
|
|
|
|
rectangle(510, 347, 588, 373);
|
|
|
|
|
rectangle(510, 397, 588, 423);
|
|
|
|
|
|
|
|
|
|
settextcolor(0XFFFFFF);
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(517, 352, L"<EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD>Ϸ");
|
|
|
|
|
outtextxy(517, 402, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::DrawGameOver()
|
|
|
|
|
{
|
|
|
|
|
settextcolor(0xFFFFFF);//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
settextstyle(48, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(170, 210, L"GAMEOVER");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::ChangeChooseUI(int left, int top, int right, int bottom, int kind)
|
|
|
|
|
{
|
|
|
|
|
setfillcolor(0XFFFFFF); //ʹ<>ð<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
fillrectangle(left, top, right, bottom);
|
|
|
|
|
|
|
|
|
|
setlinecolor(0x55FF55); //<2F><><EFBFBD>߱߿<DFB1><DFBF><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
rectangle(left, top, right, bottom);
|
|
|
|
|
|
|
|
|
|
settextstyle(28, 0, L"<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>");
|
|
|
|
|
settextcolor(0xFF5555);//<2F><><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
|
|
|
|
setbkcolor(0XFFFFFF); //<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>ɫΪ<C9AB><CEAA>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ֵı<D6B5><C4B1><EFBFBD>ɫ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ɰ<EFBFBD>ɫ
|
|
|
|
|
switch (kind)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
outtextxy(276, 175, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ");
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
outtextxy(287, 295, L"<EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>");
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
outtextxy(297, 355, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
outtextxy(297, 415, L"<EFBFBD>˳<EFBFBD>");
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
outtextxy(276, 235, L"˫<EFBFBD><EFBFBD>ģʽ");
|
|
|
|
|
case 6:
|
|
|
|
|
settextcolor(0);
|
|
|
|
|
settextstyle(20, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(22, 22, L" <20><> ");
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
settextcolor(0);
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(517, 352, L"<EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD>Ϸ");
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
settextcolor(0);
|
|
|
|
|
settextstyle(16, 0, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
outtextxy(517, 402, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setbkcolor(BG_COLOR); //<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::ClearRegion(int left, int top, int right, int bottom)
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ɫ<EFBFBD><C9AB>ȫ<EFBFBD><C8AB><EFBFBD>䣬<EFBFBD>ޱ߿<DEB1><DFBF>ľ<EFBFBD><C4BE><EFBFBD>
|
|
|
|
|
setfillcolor(BG_COLOR);
|
|
|
|
|
setfillstyle(BS_SOLID);
|
|
|
|
|
solidrectangle(left, top, right, bottom);
|
|
|
|
|
}
|