⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamecontroler.cpp

📁 模拟抓虫子的源代码,是一个很好的c++的学习代码
💻 CPP
字号:
// GameControler.cpp: implementation of the GameControler class.
//
//////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "GameControler.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GameController::GameController(const string &Title,
 const Position &WinPosition, const float WinLength,
 const float WinHeight) : Level(Slow),
 Status(SettingUp) {

	GameWindow = new SimpleWindow(Title,
	 WinLength, WinHeight, WinPosition);
	GetWindow()->Open();

	KindOfBug.resize(NumberOfBugTypes);
	KindOfBug[Slow] = new SlowBug(*GetWindow());


	KindOfBug[Fast] = new FastBug(*GetWindow());
}

GameController::~GameController() {

	delete KindOfBug[Slow];
	delete KindOfBug[Fast];
	delete GameWindow;
}

SimpleWindow *GameController::GetWindow() {
	return GameWindow;
}


void GameController::Reset() {
	Status = SettingUp;
	Level = Slow;
	CurrentBug()->Create();
}

void GameController::Play(const GameLevel l) {
	Level = l;
	Status = Playing;
	GetWindow()->StartTimer(GameSpeed);
}


int GameController::MouseClick(const Position &MousePosition) {
	if (Status == Playing
	 && CurrentBug()->IsHit(MousePosition)) {
		BugHit();
		if (Status == GameWon) {
			GetWindow()->StopTimer();
			GetWindow()->Message("You Won!");
			Reset();
			Play(Slow);
		}
	}
	else {

		GetWindow()->StopTimer();
		GetWindow()->Message("You Missed!");
		CurrentBug()->Kill();
		Reset();
		Play(Slow);
	}
	return 1;
}

int GameController::TimerTick() {
	CurrentBug()->Move();
	return 1;
}

void GameController::BugHit() {

	if (CurrentBug()->IsDying()) {
		CurrentBug()->Kill();
		Level  = (GameLevel) (Level + 1);
		if (Level == Done)
			Status = GameWon;
		else
			CurrentBug()->Create();
	}
}

GameLevel GameController::CurrentLevel() const {
	return Level;
}

Bug *GameController::CurrentBug() const {
	return KindOfBug[CurrentLevel()];
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -