lesson_8 #3
|
@ -5,7 +5,7 @@
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1286560408718923769" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1277994465197165617" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1286562333461475541" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1277996664550349269" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -12,6 +12,8 @@ public:
|
||||||
|
|
||||||
virtual inline uint16_t GetScore() const = 0;
|
virtual inline uint16_t GetScore() const = 0;
|
||||||
|
|
||||||
|
virtual DestroyableGroundObject* clone() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
|
@ -3,16 +3,32 @@
|
||||||
#include "DestroyableGroundObject.h"
|
#include "DestroyableGroundObject.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
class House : public DestroyableGroundObject {
|
class House: public DestroyableGroundObject
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
House() {}
|
||||||
|
|
||||||
|
House(const House &h)
|
||||||
|
{
|
||||||
|
x = h.x;
|
||||||
|
y = h.y;
|
||||||
|
width = h.width;
|
||||||
|
}
|
||||||
|
|
||||||
bool isInside(double x1, double x2) const override;
|
bool isInside(double x1, double x2) const override;
|
||||||
|
|
||||||
inline uint16_t GetScore() const override {
|
inline uint16_t GetScore() const override
|
||||||
|
{
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw() const override;
|
void Draw() const override;
|
||||||
|
|
||||||
|
House* clone() const
|
||||||
|
{
|
||||||
|
return new House(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint16_t score = 40;
|
const uint16_t score = 40;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,16 +3,75 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace MyTools {
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
void OpenLogFile(const std::string& FN);
|
namespace MyTools
|
||||||
|
{
|
||||||
|
|
||||||
void CloseLogFile();
|
// void OpenLogFile(const std::string &FN);
|
||||||
|
// void CloseLogFile();
|
||||||
|
// void WriteToLog(const std::string &str);
|
||||||
|
// void WriteToLog(const std::string &str, int n);
|
||||||
|
// void WriteToLog(const std::string &str, double d);
|
||||||
|
|
||||||
void WriteToLog(const std::string& str);
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void OpenLogFile(const std::string &FN) = 0;
|
||||||
|
virtual void CloseLogFile() = 0;
|
||||||
|
virtual void WriteToLog(const std::string &str) = 0;
|
||||||
|
virtual void WriteToLog(const std::string &str, int n) = 0;
|
||||||
|
virtual void WriteToLog(const std::string &str, double d) = 0;
|
||||||
|
virtual ~Logger() {}
|
||||||
|
};
|
||||||
|
|
||||||
void WriteToLog(const std::string& str, int n);
|
class FileLoggerSingleton: public Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static FileLoggerSingleton& getInstance()
|
||||||
|
{
|
||||||
|
static FileLoggerSingleton _instance;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
void WriteToLog(const std::string& str, double d);
|
void OpenLogFile(const std::string &FN) override;
|
||||||
|
void CloseLogFile() override;
|
||||||
|
void WriteToLog(const std::string &str) override;
|
||||||
|
void WriteToLog(const std::string &str, int n) override;
|
||||||
|
void WriteToLog(const std::string &str, double d) override;
|
||||||
|
private:
|
||||||
|
FileLoggerSingleton() {}
|
||||||
|
FileLoggerSingleton(const FileLoggerSingleton&) = delete;
|
||||||
|
FileLoggerSingleton& operator=(const FileLoggerSingleton&) = delete;
|
||||||
|
FileLoggerSingleton& operator=(FileLoggerSingleton&&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
}; // namespace MyTools
|
class LoggerSingleton: public Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static LoggerSingleton& getInstance()
|
||||||
|
{
|
||||||
|
static LoggerSingleton _instance;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenLogFile(const std::string &FN) override;
|
||||||
|
void CloseLogFile() override;
|
||||||
|
void WriteToLog(const std::string &str) override;
|
||||||
|
void WriteToLog(const std::string &str, int n) override;
|
||||||
|
void WriteToLog(const std::string &str, double d) override;
|
||||||
|
~LoggerSingleton();
|
||||||
|
|
||||||
|
private:
|
||||||
|
LoggerSingleton() {}
|
||||||
|
LoggerSingleton(const LoggerSingleton&) = delete;
|
||||||
|
LoggerSingleton& operator=(const LoggerSingleton&) = delete;
|
||||||
|
LoggerSingleton& operator=(LoggerSingleton&&) = delete;
|
||||||
|
FileLoggerSingleton& LoadLoggerSingletone();
|
||||||
|
|
||||||
|
FileLoggerSingleton *_logger = NULL;
|
||||||
|
std::vector<double> times;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace MyTools
|
||||||
|
|
|
@ -42,6 +42,8 @@ private:
|
||||||
|
|
||||||
void DropBomb();
|
void DropBomb();
|
||||||
|
|
||||||
|
void AnimateScrolling();
|
||||||
|
|
||||||
std::vector<DynamicObject*> vecDynamicObj;
|
std::vector<DynamicObject*> vecDynamicObj;
|
||||||
std::vector<GameObject*> vecStaticObj;
|
std::vector<GameObject*> vecStaticObj;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,14 @@
|
||||||
class Tank : public DestroyableGroundObject
|
class Tank : public DestroyableGroundObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Tank() {}
|
||||||
|
|
||||||
|
Tank(const Tank &t)
|
||||||
|
{
|
||||||
|
x = t.x;
|
||||||
|
y = t.y;
|
||||||
|
width = t.width;
|
||||||
|
}
|
||||||
|
|
||||||
bool isInside(double x1, double x2) const override;
|
bool isInside(double x1, double x2) const override;
|
||||||
|
|
||||||
|
@ -14,6 +22,11 @@ public:
|
||||||
|
|
||||||
void Draw() const override;
|
void Draw() const override;
|
||||||
|
|
||||||
|
Tank* clone() const
|
||||||
|
{
|
||||||
|
return new Tank(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const uint16_t score = 30;
|
const uint16_t score = 30;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Timer.h
|
||||||
|
*
|
||||||
|
* Created on: 21 дек. 2021 г.
|
||||||
|
* Author: alexander
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Timer& getInstance()
|
||||||
|
{
|
||||||
|
static Timer _instance;
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
m_beg = clock_t::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
double end() const
|
||||||
|
{
|
||||||
|
return elapsed() * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
using clock_t = std::chrono::high_resolution_clock;
|
||||||
|
using second_t = std::chrono::duration<double, std::ratio<1> >;
|
||||||
|
|
||||||
|
std::chrono::time_point<clock_t> m_beg;
|
||||||
|
|
||||||
|
double elapsed() const
|
||||||
|
{
|
||||||
|
return std::chrono::duration_cast<second_t>(clock_t::now() - m_beg).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer() {}
|
||||||
|
Timer(const Timer&) = delete;
|
||||||
|
Timer& operator=(const Timer&) = delete;
|
||||||
|
Timer& operator=(Timer&&) = delete;
|
||||||
|
};
|
320028
SBomber/log.txt
320028
SBomber/log.txt
File diff suppressed because it is too large
Load Diff
|
@ -32,7 +32,7 @@ int _kbhit()
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
MyTools::OpenLogFile("log.txt");
|
MyTools::LoggerSingleton::getInstance().OpenLogFile("log.txt");
|
||||||
|
|
||||||
SBomber game;
|
SBomber game;
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ int main(void)
|
||||||
game.TimeFinish();
|
game.TimeFinish();
|
||||||
|
|
||||||
} while (!game.GetExitFlag());
|
} while (!game.GetExitFlag());
|
||||||
|
game.AnimateScrolling();
|
||||||
MyTools::CloseLogFile();
|
MyTools::LoggerSingleton::getInstance().CloseLogFile();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,42 +9,110 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <numeric>
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
namespace MyTools {
|
namespace MyTools
|
||||||
|
{
|
||||||
|
|
||||||
std::ofstream logOut;
|
std::ofstream logOut;
|
||||||
|
|
||||||
void OpenLogFile(const std::string &FN) { logOut.open(FN, std::ios_base::out); }
|
void FileLoggerSingleton::OpenLogFile(const std::string &FN)
|
||||||
|
{
|
||||||
|
logOut.open(FN, std::ios_base::out);
|
||||||
|
}
|
||||||
|
|
||||||
void CloseLogFile() {
|
void FileLoggerSingleton::CloseLogFile()
|
||||||
if (logOut.is_open()) {
|
{
|
||||||
|
if (logOut.is_open())
|
||||||
|
{
|
||||||
logOut.close();
|
logOut.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetCurDateTime() {
|
std::string GetCurDateTime()
|
||||||
|
{
|
||||||
auto cur = std::chrono::system_clock::now();
|
auto cur = std::chrono::system_clock::now();
|
||||||
time_t time = std::chrono::system_clock::to_time_t(cur);
|
time_t time = std::chrono::system_clock::to_time_t(cur);
|
||||||
char *buf = ctime(&time);
|
char *buf = ctime(&time);
|
||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteToLog(const std::string &str) {
|
void FileLoggerSingleton::WriteToLog(const std::string &str)
|
||||||
if (logOut.is_open()) {
|
{
|
||||||
|
if (logOut.is_open())
|
||||||
|
{
|
||||||
logOut << GetCurDateTime() << " - " << str << std::endl;
|
logOut << GetCurDateTime() << " - " << str << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteToLog(const std::string &str, int n) {
|
void FileLoggerSingleton::WriteToLog(const std::string &str, int n)
|
||||||
if (logOut.is_open()) {
|
{
|
||||||
|
if (logOut.is_open())
|
||||||
|
{
|
||||||
logOut << GetCurDateTime() << " - " << str << n << std::endl;
|
logOut << GetCurDateTime() << " - " << str << n << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteToLog(const std::string &str, double d) {
|
void FileLoggerSingleton::WriteToLog(const std::string &str, double d)
|
||||||
if (logOut.is_open()) {
|
{
|
||||||
|
if (logOut.is_open())
|
||||||
|
{
|
||||||
logOut << GetCurDateTime() << " - " << str << d << std::endl;
|
logOut << GetCurDateTime() << " - " << str << d << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoggerSingleton::OpenLogFile(const std::string &FN)
|
||||||
|
{
|
||||||
|
Timer::getInstance().start();
|
||||||
|
LoadLoggerSingletone().OpenLogFile(FN);
|
||||||
|
times.push_back(Timer::getInstance().end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoggerSingleton::CloseLogFile()
|
||||||
|
{
|
||||||
|
Timer::getInstance().start();
|
||||||
|
LoadLoggerSingletone().CloseLogFile();
|
||||||
|
times.push_back(Timer::getInstance().end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoggerSingleton::WriteToLog(const std::string &str)
|
||||||
|
{
|
||||||
|
Timer::getInstance().start();
|
||||||
|
LoadLoggerSingletone().WriteToLog(str);
|
||||||
|
times.push_back(Timer::getInstance().end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoggerSingleton::WriteToLog(const std::string &str, int n)
|
||||||
|
{
|
||||||
|
Timer::getInstance().start();
|
||||||
|
LoadLoggerSingletone().WriteToLog(str, n);
|
||||||
|
times.push_back(Timer::getInstance().end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoggerSingleton::WriteToLog(const std::string &str, double d)
|
||||||
|
{
|
||||||
|
Timer::getInstance().start();
|
||||||
|
LoadLoggerSingletone().WriteToLog(str, d);
|
||||||
|
times.push_back(Timer::getInstance().end());
|
||||||
|
}
|
||||||
|
|
||||||
|
LoggerSingleton::~LoggerSingleton()
|
||||||
|
{
|
||||||
|
if (times.size())
|
||||||
|
{
|
||||||
|
std::cout << "Среднее время выполнения операций: " << std::accumulate(times.begin(), times.end(), 0.0) / times.size() << " секунд" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FileLoggerSingleton& LoggerSingleton::LoadLoggerSingletone()
|
||||||
|
{
|
||||||
|
if (!_logger)
|
||||||
|
{
|
||||||
|
_logger = &FileLoggerSingleton::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *_logger;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace MyTools
|
} // namespace MyTools
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "MyTools.h"
|
#include "MyTools.h"
|
||||||
#include "SBomber.h"
|
#include "SBomber.h"
|
||||||
#include "Bomb.h"
|
#include "Bomb.h"
|
||||||
|
@ -10,10 +9,11 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
SBomber::SBomber()
|
extern int _kbhit();
|
||||||
: exitFlag(false), startTime(0), finishTime(0), deltaTime(0), passedTime(0),
|
|
||||||
fps(0), bombsNumber(10), score(0) {
|
SBomber::SBomber() : exitFlag(false), startTime(0), finishTime(0), deltaTime(0), passedTime(0), fps(0), bombsNumber(10), score(0)
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
|
|
||||||
Plane *p = new Plane;
|
Plane *p = new Plane;
|
||||||
p->SetDirection(1, 0.1);
|
p->SetDirection(1, 0.1);
|
||||||
|
@ -64,49 +64,65 @@ SBomber::SBomber()
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
SBomber::~SBomber() {
|
SBomber::~SBomber()
|
||||||
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
|
{
|
||||||
if (vecDynamicObj[i] != nullptr) {
|
for (size_t i = 0; i < vecDynamicObj.size(); i++)
|
||||||
|
{
|
||||||
|
if (vecDynamicObj[i] != nullptr)
|
||||||
|
{
|
||||||
delete vecDynamicObj[i];
|
delete vecDynamicObj[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < vecStaticObj.size(); i++) {
|
for (size_t i = 0; i < vecStaticObj.size(); i++)
|
||||||
if (vecStaticObj[i] != nullptr) {
|
{
|
||||||
|
if (vecStaticObj[i] != nullptr)
|
||||||
|
{
|
||||||
delete vecStaticObj[i];
|
delete vecStaticObj[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::MoveObjects() {
|
void SBomber::MoveObjects()
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
|
|
||||||
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
|
for (size_t i = 0; i < vecDynamicObj.size(); i++)
|
||||||
if (vecDynamicObj[i] != nullptr) {
|
{
|
||||||
|
if (vecDynamicObj[i] != nullptr)
|
||||||
|
{
|
||||||
vecDynamicObj[i]->Move(deltaTime);
|
vecDynamicObj[i]->Move(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
void SBomber::CheckObjects() {
|
void SBomber::CheckObjects()
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
|
|
||||||
CheckPlaneAndLevelGUI();
|
CheckPlaneAndLevelGUI();
|
||||||
CheckBombsAndGround();
|
CheckBombsAndGround();
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
void SBomber::CheckPlaneAndLevelGUI() {
|
void SBomber::CheckPlaneAndLevelGUI()
|
||||||
if (FindPlane()->GetX() > FindLevelGUI()->GetFinishX()) {
|
{
|
||||||
|
if (FindPlane()->GetX() > FindLevelGUI()->GetFinishX())
|
||||||
|
{
|
||||||
exitFlag = true;
|
exitFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::CheckBombsAndGround() {
|
void SBomber::CheckBombsAndGround()
|
||||||
|
{
|
||||||
std::vector<Bomb*> vecBombs = FindAllBombs();
|
std::vector<Bomb*> vecBombs = FindAllBombs();
|
||||||
Ground *pGround = FindGround();
|
Ground *pGround = FindGround();
|
||||||
const double y = pGround->GetY();
|
const double y = pGround->GetY();
|
||||||
for (size_t i = 0; i < vecBombs.size(); i++) {
|
for (size_t i = 0; i < vecBombs.size(); i++)
|
||||||
if (vecBombs[i]->GetY() >= y) {
|
{
|
||||||
|
if (vecBombs[i]->GetY() >= y)
|
||||||
|
{
|
||||||
pGround->AddCrater(vecBombs[i]->GetX());
|
pGround->AddCrater(vecBombs[i]->GetX());
|
||||||
CheckDestoyableObjects(vecBombs[i]);
|
CheckDestoyableObjects(vecBombs[i]);
|
||||||
DeleteDynamicObj(vecBombs[i]);
|
DeleteDynamicObj(vecBombs[i]);
|
||||||
|
@ -114,54 +130,66 @@ void SBomber::CheckBombsAndGround() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::CheckDestoyableObjects(Bomb* pBomb) {
|
void SBomber::CheckDestoyableObjects(Bomb *pBomb)
|
||||||
std::vector<DestroyableGroundObject*> vecDestoyableObjects =
|
{
|
||||||
FindDestoyableGroundObjects();
|
std::vector<DestroyableGroundObject*> vecDestoyableObjects = FindDestoyableGroundObjects();
|
||||||
const double size = pBomb->GetWidth();
|
const double size = pBomb->GetWidth();
|
||||||
const double size_2 = size / 2;
|
const double size_2 = size / 2;
|
||||||
for (size_t i = 0; i < vecDestoyableObjects.size(); i++) {
|
for (size_t i = 0; i < vecDestoyableObjects.size(); i++)
|
||||||
|
{
|
||||||
const double x1 = pBomb->GetX() - size_2;
|
const double x1 = pBomb->GetX() - size_2;
|
||||||
const double x2 = x1 + size;
|
const double x2 = x1 + size;
|
||||||
if (vecDestoyableObjects[i]->isInside(x1, x2)) {
|
if (vecDestoyableObjects[i]->isInside(x1, x2))
|
||||||
|
{
|
||||||
score += vecDestoyableObjects[i]->GetScore();
|
score += vecDestoyableObjects[i]->GetScore();
|
||||||
DeleteStaticObj(vecDestoyableObjects[i]);
|
DeleteStaticObj(vecDestoyableObjects[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::DeleteDynamicObj(DynamicObject* pObj) {
|
void SBomber::DeleteDynamicObj(DynamicObject *pObj)
|
||||||
|
{
|
||||||
auto it = vecDynamicObj.begin();
|
auto it = vecDynamicObj.begin();
|
||||||
for (; it != vecDynamicObj.end(); it++) {
|
for (; it != vecDynamicObj.end(); it++)
|
||||||
if (*it == pObj) {
|
{
|
||||||
|
if (*it == pObj)
|
||||||
|
{
|
||||||
vecDynamicObj.erase(it);
|
vecDynamicObj.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::DeleteStaticObj(GameObject* pObj) {
|
void SBomber::DeleteStaticObj(GameObject *pObj)
|
||||||
|
{
|
||||||
auto it = vecStaticObj.begin();
|
auto it = vecStaticObj.begin();
|
||||||
for (; it != vecStaticObj.end(); it++) {
|
for (; it != vecStaticObj.end(); it++)
|
||||||
if (*it == pObj) {
|
{
|
||||||
|
if (*it == pObj)
|
||||||
|
{
|
||||||
vecStaticObj.erase(it);
|
vecStaticObj.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DestroyableGroundObject*> SBomber::FindDestoyableGroundObjects() const {
|
std::vector<DestroyableGroundObject*> SBomber::FindDestoyableGroundObjects() const
|
||||||
|
{
|
||||||
std::vector<DestroyableGroundObject*> vec;
|
std::vector<DestroyableGroundObject*> vec;
|
||||||
Tank *pTank;
|
Tank *pTank;
|
||||||
House *pHouse;
|
House *pHouse;
|
||||||
for (size_t i = 0; i < vecStaticObj.size(); i++) {
|
for (size_t i = 0; i < vecStaticObj.size(); i++)
|
||||||
|
{
|
||||||
pTank = dynamic_cast<Tank*>(vecStaticObj[i]);
|
pTank = dynamic_cast<Tank*>(vecStaticObj[i]);
|
||||||
if (pTank != nullptr) {
|
if (pTank != nullptr)
|
||||||
|
{
|
||||||
vec.push_back(pTank);
|
vec.push_back(pTank);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pHouse = dynamic_cast<House*>(vecStaticObj[i]);
|
pHouse = dynamic_cast<House*>(vecStaticObj[i]);
|
||||||
if (pHouse != nullptr) {
|
if (pHouse != nullptr)
|
||||||
|
{
|
||||||
vec.push_back(pHouse);
|
vec.push_back(pHouse);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -170,12 +198,15 @@ std::vector<DestroyableGroundObject*> SBomber::FindDestoyableGroundObjects() con
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ground* SBomber::FindGround() const {
|
Ground* SBomber::FindGround() const
|
||||||
|
{
|
||||||
Ground *pGround;
|
Ground *pGround;
|
||||||
|
|
||||||
for (size_t i = 0; i < vecStaticObj.size(); i++) {
|
for (size_t i = 0; i < vecStaticObj.size(); i++)
|
||||||
|
{
|
||||||
pGround = dynamic_cast<Ground*>(vecStaticObj[i]);
|
pGround = dynamic_cast<Ground*>(vecStaticObj[i]);
|
||||||
if (pGround != nullptr) {
|
if (pGround != nullptr)
|
||||||
|
{
|
||||||
return pGround;
|
return pGround;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,12 +214,15 @@ Ground* SBomber::FindGround() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Bomb*> SBomber::FindAllBombs() const {
|
std::vector<Bomb*> SBomber::FindAllBombs() const
|
||||||
|
{
|
||||||
std::vector<Bomb*> vecBombs;
|
std::vector<Bomb*> vecBombs;
|
||||||
|
|
||||||
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
|
for (size_t i = 0; i < vecDynamicObj.size(); i++)
|
||||||
|
{
|
||||||
Bomb *pBomb = dynamic_cast<Bomb*>(vecDynamicObj[i]);
|
Bomb *pBomb = dynamic_cast<Bomb*>(vecDynamicObj[i]);
|
||||||
if (pBomb != nullptr) {
|
if (pBomb != nullptr)
|
||||||
|
{
|
||||||
vecBombs.push_back(pBomb);
|
vecBombs.push_back(pBomb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,10 +230,13 @@ std::vector<Bomb*> SBomber::FindAllBombs() const {
|
||||||
return vecBombs;
|
return vecBombs;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane* SBomber::FindPlane() const {
|
Plane* SBomber::FindPlane() const
|
||||||
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
|
{
|
||||||
|
for (size_t i = 0; i < vecDynamicObj.size(); i++)
|
||||||
|
{
|
||||||
Plane *p = dynamic_cast<Plane*>(vecDynamicObj[i]);
|
Plane *p = dynamic_cast<Plane*>(vecDynamicObj[i]);
|
||||||
if (p != nullptr) {
|
if (p != nullptr)
|
||||||
|
{
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,10 +244,13 @@ Plane* SBomber::FindPlane() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelGUI* SBomber::FindLevelGUI() const {
|
LevelGUI* SBomber::FindLevelGUI() const
|
||||||
for (size_t i = 0; i < vecStaticObj.size(); i++) {
|
{
|
||||||
|
for (size_t i = 0; i < vecStaticObj.size(); i++)
|
||||||
|
{
|
||||||
LevelGUI *p = dynamic_cast<LevelGUI*>(vecStaticObj[i]);
|
LevelGUI *p = dynamic_cast<LevelGUI*>(vecStaticObj[i]);
|
||||||
if (p != nullptr) {
|
if (p != nullptr)
|
||||||
|
{
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,16 +258,19 @@ LevelGUI* SBomber::FindLevelGUI() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::ProcessKBHit() {
|
void SBomber::ProcessKBHit()
|
||||||
|
{
|
||||||
int c = getchar();
|
int c = getchar();
|
||||||
|
|
||||||
if (c == 224) {
|
if (c == 224)
|
||||||
|
{
|
||||||
c = getchar();
|
c = getchar();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked. key = ", c);
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked. key = ", c);
|
||||||
|
|
||||||
switch (c) {
|
switch (c)
|
||||||
|
{
|
||||||
|
|
||||||
case 27: // esc
|
case 27: // esc
|
||||||
exitFlag = true;
|
exitFlag = true;
|
||||||
|
@ -249,22 +292,43 @@ void SBomber::ProcessKBHit() {
|
||||||
DropBomb();
|
DropBomb();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
{
|
||||||
|
DestroyableGroundObject *clone = nullptr;
|
||||||
|
|
||||||
|
std::vector<DestroyableGroundObject*> vecDestoyableObjects = FindDestoyableGroundObjects();
|
||||||
|
for (size_t i = 0; i < vecDestoyableObjects.size(); i++)
|
||||||
|
{
|
||||||
|
if (!clone) clone = vecDestoyableObjects[i]->clone();
|
||||||
|
if (!vecDestoyableObjects[i]->isInside(clone->GetX(), clone->GetY()))
|
||||||
|
{
|
||||||
|
vecStaticObj.push_back(clone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::DrawFrame() {
|
void SBomber::DrawFrame()
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
|
|
||||||
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
|
for (size_t i = 0; i < vecDynamicObj.size(); i++)
|
||||||
if (vecDynamicObj[i] != nullptr) {
|
{
|
||||||
|
if (vecDynamicObj[i] != nullptr)
|
||||||
|
{
|
||||||
vecDynamicObj[i]->Draw();
|
vecDynamicObj[i]->Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < vecStaticObj.size(); i++) {
|
for (size_t i = 0; i < vecStaticObj.size(); i++)
|
||||||
if (vecStaticObj[i] != nullptr) {
|
{
|
||||||
|
if (vecStaticObj[i] != nullptr)
|
||||||
|
{
|
||||||
vecStaticObj[i]->Draw();
|
vecStaticObj[i]->Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,24 +339,26 @@ void SBomber::DrawFrame() {
|
||||||
FindLevelGUI()->SetParam(passedTime, fps, bombsNumber, score);
|
FindLevelGUI()->SetParam(passedTime, fps, bombsNumber, score);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::TimeStart() {
|
void SBomber::TimeStart()
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
{
|
||||||
startTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::TimeFinish() {
|
void SBomber::TimeFinish()
|
||||||
finishTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
{
|
||||||
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
finishTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||||
deltaTime = uint16_t(finishTime - startTime);
|
deltaTime = uint16_t(finishTime - startTime);
|
||||||
passedTime += deltaTime;
|
passedTime += deltaTime;
|
||||||
|
|
||||||
MyTools::WriteToLog(std::string(__func__) + " deltaTime = ", (int)deltaTime);
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " deltaTime = ", (int) deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBomber::DropBomb() {
|
void SBomber::DropBomb()
|
||||||
if (bombsNumber > 0) {
|
{
|
||||||
MyTools::WriteToLog(std::string(__func__) + " was invoked");
|
if (bombsNumber > 0)
|
||||||
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__func__) + " was invoked");
|
||||||
|
|
||||||
Plane *pPlane = FindPlane();
|
Plane *pPlane = FindPlane();
|
||||||
double x = pPlane->GetX() + 4;
|
double x = pPlane->GetX() + 4;
|
||||||
|
@ -309,3 +375,25 @@ void SBomber::DropBomb() {
|
||||||
score -= Bomb::BombCost;
|
score -= Bomb::BombCost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SBomber::AnimateScrolling()
|
||||||
|
{
|
||||||
|
MyTools::LoggerSingleton::getInstance().WriteToLog(std::string(__FUNCTION__) + " was invoked");
|
||||||
|
const size_t windowHeight = 10; // Размер окна для скроллинга
|
||||||
|
const size_t startX = MyTools::GetMaxX() / 2 - ScrollWidth / 2;
|
||||||
|
const size_t startY = MyTools::GetMaxY() / 2 - windowHeight / 2;
|
||||||
|
double curPos = 0;
|
||||||
|
do {
|
||||||
|
TimeStart();
|
||||||
|
MyTools::ClrScr();
|
||||||
|
|
||||||
|
// вывод windowHeight строк из ppScroll используя смещение curPos
|
||||||
|
// ...
|
||||||
|
MyTools::GotoXY(0, 0);
|
||||||
|
TimeFinish();
|
||||||
|
curPos += deltaTime * 0.0015;
|
||||||
|
|
||||||
|
} while (!_kbhit() && int(curPos) <= (ScrollHeight - windowHeight));
|
||||||
|
MyTools::ClrScr();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,15 +33,15 @@ IScreen& getInternalInstance() {
|
||||||
class ScreenSingletonProxy : public IScreen {
|
class ScreenSingletonProxy : public IScreen {
|
||||||
public:
|
public:
|
||||||
virtual void ClrScr() override {
|
virtual void ClrScr() override {
|
||||||
MyTools::WriteToLog("ClrScr invoke begin");
|
MyTools::LoggerSingleton::getInstance().WriteToLog("ClrScr invoke begin");
|
||||||
getInternalInstance().ClrScr();
|
getInternalInstance().ClrScr();
|
||||||
MyTools::WriteToLog("ClrScr invoke end");
|
MyTools::LoggerSingleton::getInstance().WriteToLog("ClrScr invoke end");
|
||||||
}
|
}
|
||||||
virtual void GotoXY(double x, double y) override {
|
virtual void GotoXY(double x, double y) override {
|
||||||
|
|
||||||
MyTools::WriteToLog("GotoXY invoke begin");
|
MyTools::LoggerSingleton::getInstance().WriteToLog("GotoXY invoke begin");
|
||||||
getInternalInstance().GotoXY(x, y);
|
getInternalInstance().GotoXY(x, y);
|
||||||
MyTools::WriteToLog("GotoXY invoke end");
|
MyTools::LoggerSingleton::getInstance().WriteToLog("GotoXY invoke end");
|
||||||
}
|
}
|
||||||
virtual uint16_t GetMaxX() override {
|
virtual uint16_t GetMaxX() override {
|
||||||
return getInternalInstance().GetMaxX();
|
return getInternalInstance().GetMaxX();
|
||||||
|
|
Loading…
Reference in New Issue