This commit is contained in:
Alexander Zhirov 2021-12-21 01:22:05 +03:00
parent d5bc171823
commit 1c992cb95a
32 changed files with 321413 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.metadata/

128
SBomber/.cproject Normal file
View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1073495572">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1073495572" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1073495572" name="Debug" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="cdt.managedbuild.config.gnu.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1073495572." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1247106165" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.900322962" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
<builder buildPath="${workspace_loc:/SBomber}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.1629949144" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.709434385" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1321672980" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.509378779" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option defaultValue="gnu.cpp.compiler.debugging.level.max" id="gnu.cpp.compiler.exe.debug.option.debugging.level.397539802" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.dialect.std.1082192218" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++1y" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.1775322417" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/include}&quot;"/>
</option>
<option id="gnu.cpp.compiler.option.warnings.allwarn.1963130128" superClass="gnu.cpp.compiler.option.warnings.allwarn" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.242223335" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.722656849" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.240375163" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option defaultValue="gnu.c.debugging.level.max" id="gnu.c.compiler.exe.debug.option.debugging.level.1576529763" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1725434750" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.12029773" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.627509738" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1082384748" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.396893942" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.2124541293" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.116133331">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.116133331" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.116133331" name="Release" optionalBuildProperties="" parent="cdt.managedbuild.config.gnu.exe.release">
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.116133331." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1059167666" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1630136086" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
<builder buildPath="${workspace_loc:/SBomber}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.1321427917" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.943871591" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1243096622" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.1885823932" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option defaultValue="gnu.cpp.compiler.debugging.level.none" id="gnu.cpp.compiler.exe.release.option.debugging.level.252983445" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.736909080" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.170530682" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.124374195" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
<option defaultValue="gnu.c.debugging.level.none" id="gnu.c.compiler.exe.release.option.debugging.level.2078008575" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1733034693" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1406898956" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.28525497" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1523081806" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.416987492" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1003393572" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="SBomber.cdt.managedbuild.target.gnu.exe.781605416" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.116133331;cdt.managedbuild.config.gnu.exe.release.116133331.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1243096622;cdt.managedbuild.tool.gnu.cpp.compiler.input.736909080">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1073495572;cdt.managedbuild.config.gnu.exe.debug.1073495572.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1321672980;cdt.managedbuild.tool.gnu.cpp.compiler.input.242223335">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.116133331;cdt.managedbuild.config.gnu.exe.release.116133331.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.170530682;cdt.managedbuild.tool.gnu.c.compiler.input.1733034693">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1073495572;cdt.managedbuild.config.gnu.exe.debug.1073495572.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.722656849;cdt.managedbuild.tool.gnu.c.compiler.input.1725434750">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/SBomber"/>
</configuration>
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/SBomber"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>

1
SBomber/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/Debug/

27
SBomber/.project Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SBomber</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.config.gnu.exe.debug.1073495572" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<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.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 &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.exe.release.116133331" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<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.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 &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>

16
SBomber/include/Bomb.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "DynamicObject.h"
class Bomb : public DynamicObject
{
public:
static const uint16_t BombCost = 10; // ñòîèìîñòü áîìáû â î÷êàõ
void Draw() const override;
private:
};

10
SBomber/include/Crater.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include "GameObject.h"
class Crater : public GameObject {
public:
bool isInside(double xn) const;
virtual void Draw() const override;
};

View File

@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
#include "GameObject.h"
class DestroyableGroundObject : public GameObject
{
public:
virtual bool isInside(double x1, double x2) const = 0;
virtual inline uint16_t GetScore() const = 0;
protected:
};

View File

@ -0,0 +1,23 @@
#pragma once
#include <stdint.h>
#include "GameObject.h"
class DynamicObject : public GameObject
{
public:
DynamicObject() : speed(0.0), xDirction(0.0), yDirection(0) { }
inline void SetSpeed(double sp) { speed = sp; }
inline void SetDirection(double dx, double dy) { xDirction = dx; yDirection = dy; }
virtual void Move(uint16_t time) { x += xDirction * speed * time * 0.001; y += yDirection * speed * time * 0.001; };
protected:
double speed;
double xDirction, yDirection;
};

View File

@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
class GameObject {
public:
GameObject() : x(0.0), y(0.0), width(0) {}
virtual ~GameObject() = default;
virtual void Draw() const = 0;
inline void SetPos(double nx, double ny) {
x = nx;
y = ny;
}
inline double GetY() const { return y; }
inline double GetX() const { return x; }
inline void SetWidth(uint16_t widthN) { width = widthN; }
inline uint16_t GetWidth() const { return width; }
protected:
double x, y;
uint16_t width;
};

19
SBomber/include/Ground.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include "GameObject.h"
#include "Crater.h"
#include <vector>
class Ground : public GameObject {
public:
Ground() = default;
void Draw() const override;
void AddCrater(double xn);
private:
bool isInsideAnyCrater(double x) const;
std::vector<Crater> vecCrates;
};

18
SBomber/include/House.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "DestroyableGroundObject.h"
#include <cstdint>
class House : public DestroyableGroundObject {
public:
bool isInside(double x1, double x2) const override;
inline uint16_t GetScore() const override {
return score;
}
void Draw() const override;
private:
const uint16_t score = 40;
};

View File

@ -0,0 +1,32 @@
#pragma once
#include <stdint.h>
#include "GameObject.h"
class LevelGUI : public GameObject {
public:
LevelGUI() : bombsNumber(0), score(0), passedTime(0), fps(0), height(0) { }
void SetParam(uint64_t passedTimeNew, uint64_t fpsNew, uint16_t bombsNumberNew, int16_t scoreNew);
void SetHeight(uint16_t heightN) { height = heightN; };
inline uint16_t GetFinishX() const { return finishX; }
inline void SetFinishX(uint16_t finishXN) { finishX = finishXN; }
void Draw() const override;
private:
uint16_t height;
uint16_t finishX = 109;
uint64_t passedTime, fps;
uint16_t bombsNumber;
int16_t score;
};

18
SBomber/include/MyTools.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
#include <cstring>
namespace MyTools {
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);
}; // namespace MyTools

15
SBomber/include/Plane.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include "DynamicObject.h"
class Plane : public DynamicObject {
public:
void Draw() const override;
inline void ChangePlaneY(double dy) { yDirection += dy; }
private:
};

53
SBomber/include/SBomber.h Normal file
View File

@ -0,0 +1,53 @@
#pragma once
#include <vector>
#include "LevelGUI.h"
#include "Plane.h"
#include "Bomb.h"
#include "Ground.h"
#include "Tank.h"
class SBomber
{
public:
SBomber();
~SBomber();
inline bool GetExitFlag() const { return exitFlag; }
void ProcessKBHit();
void TimeStart();
void TimeFinish();
void DrawFrame();
void MoveObjects();
void CheckObjects();
private:
void CheckPlaneAndLevelGUI();
void CheckBombsAndGround();
void CheckDestoyableObjects(Bomb* pBomb);
void DeleteDynamicObj(DynamicObject * pBomb);
void DeleteStaticObj(GameObject* pObj);
Ground * FindGround() const;
Plane * FindPlane() const;
LevelGUI * FindLevelGUI() const;
std::vector<DestroyableGroundObject*> FindDestoyableGroundObjects() const;
std::vector<Bomb*> FindAllBombs() const;
void DropBomb();
std::vector<DynamicObject*> vecDynamicObj;
std::vector<GameObject*> vecStaticObj;
bool exitFlag;
uint64_t startTime, finishTime, passedTime;
uint16_t bombsNumber, deltaTime, fps;
int16_t score;
};

View File

@ -0,0 +1,35 @@
#pragma once
#include <cstdint>
#include "enums/ConsoleColors.h"
class IScreen {
public:
virtual ~IScreen() = default;
virtual void ClrScr() = 0;
virtual void GotoXY(double x, double y) = 0;
virtual uint16_t GetMaxX() = 0;
virtual uint16_t GetMaxY() = 0;
virtual void SetColor(ConsoleColor color) = 0;
};
class ScreenSingleton : public IScreen {
public:
static IScreen& getInstance();
virtual void ClrScr() override;
virtual void GotoXY(double x, double y) override;
virtual uint16_t GetMaxX() override;
virtual uint16_t GetMaxY() override;
virtual void SetColor(ConsoleColor color) override;
private:
friend IScreen& getInternalInstance();
ScreenSingleton() = default;
~ScreenSingleton() = default;
ScreenSingleton(const ScreenSingleton& root) = delete;
ScreenSingleton& operator=(const ScreenSingleton&) = delete;
ScreenSingleton(ScreenSingleton&& root) = delete;
ScreenSingleton& operator=(ScreenSingleton&&) = delete;
};

21
SBomber/include/Tank.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
#include "DestroyableGroundObject.h"
class Tank : public DestroyableGroundObject
{
public:
bool isInside(double x1, double x2) const override;
inline uint16_t GetScore() const override { return score; }
void Draw() const override;
private:
const uint16_t score = 30;
};

View File

@ -0,0 +1,20 @@
#pragma once
enum ConsoleColor {
CC_Black = 0,
CC_Blue,
CC_Green,
CC_Cyan,
CC_Red,
CC_Magenta,
CC_Brown,
CC_LightGray,
CC_DarkGray,
CC_LightBlue,
CC_LightGreen,
CC_LightCyan,
CC_LightRed,
CC_LightMagenta,
CC_Yellow,
CC_White
};

View File

@ -0,0 +1,3 @@
#pragma once
enum CraterSize { SMALL_CRATER_SIZE = 9 };

320028
SBomber/log.txt Normal file

File diff suppressed because it is too large Load Diff

61
SBomber/main.cpp Normal file
View File

@ -0,0 +1,61 @@
#include "SBomber.h"
#include "MyTools.h"
#include "ScreenSingleton.h"
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
int _kbhit()
{
static const int STDIN = 0;
static bool initialized = false;
if (!initialized)
{
// Use termios to turn off line buffering
termios term;
tcgetattr(STDIN, &term);
term.c_lflag &= ~ICANON;
tcsetattr(STDIN, TCSANOW, &term);
setbuf(stdin, NULL);
initialized = true;
}
int bytesWaiting;
ioctl(STDIN, FIONREAD, &bytesWaiting);
return bytesWaiting;
}
int main(void)
{
MyTools::OpenLogFile("log.txt");
SBomber game;
do
{
game.TimeStart();
if (_kbhit())
{
game.ProcessKBHit();
}
ScreenSingleton::getInstance().ClrScr();
game.DrawFrame();
game.MoveObjects();
game.CheckObjects();
game.TimeFinish();
} while (!game.GetExitFlag());
MyTools::CloseLogFile();
return 0;
}

9
SBomber/src/Bomb.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "Bomb.h"
#include <iostream>
#include "ScreenSingleton.h"
void Bomb::Draw() const {
//ScreenSingleton::getInstance().SetColor(CC_LightMagenta);
ScreenSingleton::getInstance().GotoXY(x, y);
std::cout << "*";
}

22
SBomber/src/Crater.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "Crater.h"
#include "ScreenSingleton.h"
#include <iostream>
#include "enums/CraterSize.h"
void Crater::Draw() const {
if (width == SMALL_CRATER_SIZE) {
ScreenSingleton::getInstance().GotoXY(x - 4, y + 1);
std::cout << "== ==";
ScreenSingleton::getInstance().GotoXY(x - 2, y + 2);
std::cout << "=====";
}
}
bool Crater::isInside(double xn) const {
const double size_2 = width / 2.0;
if (int(xn) > int(x - size_2) && xn <= int(x + size_2)) {
return true;
}
return false;
}

70
SBomber/src/Ground.cpp Normal file
View File

@ -0,0 +1,70 @@
#include "Ground.h"
#include "Crater.h"
#include "ScreenSingleton.h"
#include "enums/CraterSize.h"
#include "MyTools.h"
#include <iostream>
void Ground::Draw() const
{
ScreenSingleton::getInstance().SetColor(CC_Green);
const size_t bufSize = width + 1;
char* buf = new (std::nothrow) char[bufSize];
if (buf == nullptr)
{
return;
}
if (vecCrates.size() == 0)
{
ScreenSingleton::getInstance().GotoXY(x, y);
memset(buf, '=', bufSize);
buf[bufSize - 1] = '\0';
std::cout << buf;
}
else
{
const size_t X = size_t(x);
char c;
for (size_t i = X; i < width + X; i++)
{
c = (isInsideAnyCrater((double)i)) ? ' ' : '=';
buf[i - X] = c;
}
ScreenSingleton::getInstance().GotoXY((double)X, y);
buf[bufSize-1] = '\0';
std::cout << buf;
for (size_t i = 0; i < vecCrates.size(); i++)
{
vecCrates[i].Draw();
}
}
delete[] buf;
}
bool Ground::isInsideAnyCrater(double x) const
{
bool isInside = false;
for (size_t i = 0; i < vecCrates.size(); i++)
{
if (vecCrates[i].isInside(x))
{
isInside = true;
break;
}
}
return isInside;
}
void Ground::AddCrater(double xn)
{
Crater cr;
cr.SetPos(int(xn), y);
cr.SetWidth(SMALL_CRATER_SIZE);
vecCrates.push_back(cr);
}

44
SBomber/src/House.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "House.h"
#include <iostream>
#include "MyTools.h"
#include "ScreenSingleton.h"
bool House::isInside(double x1, double x2) const
{
const double XBeg = x + 2;
const double XEnd = x + width - 1;
if (x1 < XBeg && x2 > XEnd)
{
return true;
}
if (x1 > XBeg && x1 < XEnd)
{
return true;
}
if (x2 > XBeg && x2 < XEnd)
{
return true;
}
return false;
}
void House::Draw() const
{
ScreenSingleton::getInstance().SetColor(CC_Yellow);
ScreenSingleton::getInstance().GotoXY(x, y - 5);
std::cout << " ######## ";
ScreenSingleton::getInstance().GotoXY(x, y - 4);
std::cout << "## ##";
ScreenSingleton::getInstance().GotoXY(x, y - 3);
std::cout << "############";
ScreenSingleton::getInstance().GotoXY(x, y - 2);
std::cout << "# #";
ScreenSingleton::getInstance().GotoXY(x, y - 1);
std::cout << "# #";
ScreenSingleton::getInstance().GotoXY(x, y);
std::cout << "############";
}

48
SBomber/src/LevelGUI.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "LevelGUI.h"
#include <iostream>
#include "MyTools.h"
#include "ScreenSingleton.h"
void LevelGUI::Draw() const
{
ScreenSingleton::getInstance().SetColor(CC_White);
ScreenSingleton::getInstance().GotoXY(x, y);
char* buf = new (std::nothrow) char[width + 1];
if (buf == nullptr)
{
return;
}
memset(buf, '+', width);
buf[width] = '\0';
std::cout << buf;
ScreenSingleton::getInstance().GotoXY(x, y + height);
std::cout << buf;
delete [] buf;
buf = nullptr;
for (size_t i = size_t(y); i < height + y; i++)
{
ScreenSingleton::getInstance().GotoXY(x, (double)i);
std::cout << "+";
ScreenSingleton::getInstance().GotoXY(x + width - 1, (double)i);
std::cout << "+";
}
ScreenSingleton::getInstance().GotoXY(3, 1);
std::cout << "FramePerSecond: " << static_cast<int>(fps / (passedTime / 1000.0));
ScreenSingleton::getInstance().GotoXY(25, 1);
std::cout << "PassedTime: " << static_cast<int>(passedTime / 1000.0) << " sec";
ScreenSingleton::getInstance().GotoXY(46, 1);
std::cout << "BombsNum: " << bombsNumber;
ScreenSingleton::getInstance().GotoXY(62, 1);
std::cout << "Score: " << score;
}
void LevelGUI::SetParam(uint64_t passedTimeNew, uint64_t fpsNew, uint16_t bombsNumberNew, int16_t scoreNew)
{
passedTime = passedTimeNew;
fps = fpsNew;
bombsNumber = bombsNumberNew;
score = scoreNew;
}

50
SBomber/src/MyTools.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "MyTools.h"
#include <stdint.h>
#include <time.h>
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
namespace MyTools {
std::ofstream logOut;
void OpenLogFile(const std::string &FN) { logOut.open(FN, std::ios_base::out); }
void CloseLogFile() {
if (logOut.is_open()) {
logOut.close();
}
}
std::string GetCurDateTime() {
auto cur = std::chrono::system_clock::now();
time_t time = std::chrono::system_clock::to_time_t(cur);
char* buf = ctime(&time);
return std::string(buf);
}
void WriteToLog(const std::string &str) {
if (logOut.is_open()) {
logOut << GetCurDateTime() << " - " << str << std::endl;
}
}
void WriteToLog(const std::string &str, int n) {
if (logOut.is_open()) {
logOut << GetCurDateTime() << " - " << str << n << std::endl;
}
}
void WriteToLog(const std::string &str, double d) {
if (logOut.is_open()) {
logOut << GetCurDateTime() << " - " << str << d << std::endl;
}
}
} // namespace MyTools

19
SBomber/src/Plane.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
#include "Plane.h"
#include "MyTools.h"
#include "ScreenSingleton.h"
void Plane::Draw() const
{
ScreenSingleton::getInstance().SetColor(CC_LightBlue);
ScreenSingleton::getInstance().GotoXY(x, y);
std::cout << "=========>";
ScreenSingleton::getInstance().GotoXY(x - 2, y - 1);
std::cout << "===";
ScreenSingleton::getInstance().GotoXY(x + 3, y - 1);
std::cout << "\\\\\\\\";
ScreenSingleton::getInstance().GotoXY(x + 3, y + 1);
std::cout << "////";
}

311
SBomber/src/SBomber.cpp Normal file
View File

@ -0,0 +1,311 @@
#include "MyTools.h"
#include "SBomber.h"
#include "Bomb.h"
#include "Ground.h"
#include "Tank.h"
#include "House.h"
#include "ScreenSingleton.h"
#include "enums/CraterSize.h"
#include <chrono>
#include <thread>
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");
Plane* p = new Plane;
p->SetDirection(1, 0.1);
p->SetSpeed(4);
p->SetPos(5, 10);
vecDynamicObj.push_back(p);
LevelGUI* pGUI = new LevelGUI;
pGUI->SetParam(passedTime, fps, bombsNumber, score);
const uint16_t maxX = ScreenSingleton::getInstance().GetMaxX();
const uint16_t maxY = ScreenSingleton::getInstance().GetMaxY();
const uint16_t offset = 3;
const uint16_t width = maxX - 7;
pGUI->SetPos(offset, offset);
pGUI->SetWidth(width);
pGUI->SetHeight(maxY - 4);
pGUI->SetFinishX(offset + width - 4);
vecStaticObj.push_back(pGUI);
Ground* pGr = new Ground;
const uint16_t groundY = maxY - 5;
pGr->SetPos(offset + 1, groundY);
pGr->SetWidth(width - 2);
vecStaticObj.push_back(pGr);
Tank* pTank = new Tank;
pTank->SetWidth(13);
pTank->SetPos(30, groundY - 1);
vecStaticObj.push_back(pTank);
pTank = new Tank;
pTank->SetWidth(13);
pTank->SetPos(50, groundY - 1);
vecStaticObj.push_back(pTank);
House* pHouse = new House;
pHouse->SetWidth(13);
pHouse->SetPos(80, groundY - 1);
vecStaticObj.push_back(pHouse);
/*
Bomb* pBomb = new Bomb;
pBomb->SetDirection(0.3, 1);
pBomb->SetSpeed(2);
pBomb->SetPos(51, 5);
pBomb->SetSize(SMALL_CRATER_SIZE);
vecDynamicObj.push_back(pBomb);
*/
}
SBomber::~SBomber() {
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
if (vecDynamicObj[i] != nullptr) {
delete vecDynamicObj[i];
}
}
for (size_t i = 0; i < vecStaticObj.size(); i++) {
if (vecStaticObj[i] != nullptr) {
delete vecStaticObj[i];
}
}
}
void SBomber::MoveObjects() {
MyTools::WriteToLog(std::string(__func__) + " was invoked");
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
if (vecDynamicObj[i] != nullptr) {
vecDynamicObj[i]->Move(deltaTime);
}
}
};
void SBomber::CheckObjects() {
MyTools::WriteToLog(std::string(__func__) + " was invoked");
CheckPlaneAndLevelGUI();
CheckBombsAndGround();
};
void SBomber::CheckPlaneAndLevelGUI() {
if (FindPlane()->GetX() > FindLevelGUI()->GetFinishX()) {
exitFlag = true;
}
}
void SBomber::CheckBombsAndGround() {
std::vector<Bomb*> vecBombs = FindAllBombs();
Ground* pGround = FindGround();
const double y = pGround->GetY();
for (size_t i = 0; i < vecBombs.size(); i++) {
if (vecBombs[i]->GetY() >= y) {
pGround->AddCrater(vecBombs[i]->GetX());
CheckDestoyableObjects(vecBombs[i]);
DeleteDynamicObj(vecBombs[i]);
}
}
}
void SBomber::CheckDestoyableObjects(Bomb* pBomb) {
std::vector<DestroyableGroundObject*> vecDestoyableObjects =
FindDestoyableGroundObjects();
const double size = pBomb->GetWidth();
const double size_2 = size / 2;
for (size_t i = 0; i < vecDestoyableObjects.size(); i++) {
const double x1 = pBomb->GetX() - size_2;
const double x2 = x1 + size;
if (vecDestoyableObjects[i]->isInside(x1, x2)) {
score += vecDestoyableObjects[i]->GetScore();
DeleteStaticObj(vecDestoyableObjects[i]);
}
}
}
void SBomber::DeleteDynamicObj(DynamicObject* pObj) {
auto it = vecDynamicObj.begin();
for (; it != vecDynamicObj.end(); it++) {
if (*it == pObj) {
vecDynamicObj.erase(it);
break;
}
}
}
void SBomber::DeleteStaticObj(GameObject* pObj) {
auto it = vecStaticObj.begin();
for (; it != vecStaticObj.end(); it++) {
if (*it == pObj) {
vecStaticObj.erase(it);
break;
}
}
}
std::vector<DestroyableGroundObject*> SBomber::FindDestoyableGroundObjects() const {
std::vector<DestroyableGroundObject*> vec;
Tank* pTank;
House* pHouse;
for (size_t i = 0; i < vecStaticObj.size(); i++) {
pTank = dynamic_cast<Tank*>(vecStaticObj[i]);
if (pTank != nullptr) {
vec.push_back(pTank);
continue;
}
pHouse = dynamic_cast<House*>(vecStaticObj[i]);
if (pHouse != nullptr) {
vec.push_back(pHouse);
continue;
}
}
return vec;
}
Ground* SBomber::FindGround() const {
Ground* pGround;
for (size_t i = 0; i < vecStaticObj.size(); i++) {
pGround = dynamic_cast<Ground*>(vecStaticObj[i]);
if (pGround != nullptr) {
return pGround;
}
}
return nullptr;
}
std::vector<Bomb*> SBomber::FindAllBombs() const {
std::vector<Bomb*> vecBombs;
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
Bomb* pBomb = dynamic_cast<Bomb*>(vecDynamicObj[i]);
if (pBomb != nullptr) {
vecBombs.push_back(pBomb);
}
}
return vecBombs;
}
Plane* SBomber::FindPlane() const {
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
Plane* p = dynamic_cast<Plane*>(vecDynamicObj[i]);
if (p != nullptr) {
return p;
}
}
return nullptr;
}
LevelGUI* SBomber::FindLevelGUI() const {
for (size_t i = 0; i < vecStaticObj.size(); i++) {
LevelGUI* p = dynamic_cast<LevelGUI*>(vecStaticObj[i]);
if (p != nullptr) {
return p;
}
}
return nullptr;
}
void SBomber::ProcessKBHit() {
int c = getchar();
if (c == 224) {
c = getchar();
}
MyTools::WriteToLog(std::string(__func__) + " was invoked. key = ", c);
switch (c) {
case 27: // esc
exitFlag = true;
break;
case 72: // up
FindPlane()->ChangePlaneY(-0.25);
break;
case 80: // down
FindPlane()->ChangePlaneY(0.25);
break;
case 'b':
DropBomb();
break;
case 'B':
DropBomb();
break;
default:
break;
}
}
void SBomber::DrawFrame() {
MyTools::WriteToLog(std::string(__func__) + " was invoked");
for (size_t i = 0; i < vecDynamicObj.size(); i++) {
if (vecDynamicObj[i] != nullptr) {
vecDynamicObj[i]->Draw();
}
}
for (size_t i = 0; i < vecStaticObj.size(); i++) {
if (vecStaticObj[i] != nullptr) {
vecStaticObj[i]->Draw();
}
}
ScreenSingleton::getInstance().GotoXY(0, 0);
fps++;
FindLevelGUI()->SetParam(passedTime, fps, bombsNumber, score);
}
void SBomber::TimeStart() {
MyTools::WriteToLog(std::string(__func__) + " was invoked");
startTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
void SBomber::TimeFinish() {
finishTime = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
deltaTime = uint16_t(finishTime - startTime);
passedTime += deltaTime;
MyTools::WriteToLog(std::string(__func__) + " deltaTime = ", (int)deltaTime);
}
void SBomber::DropBomb() {
if (bombsNumber > 0) {
MyTools::WriteToLog(std::string(__func__) + " was invoked");
Plane* pPlane = FindPlane();
double x = pPlane->GetX() + 4;
double y = pPlane->GetY() + 2;
Bomb* pBomb = new Bomb;
pBomb->SetDirection(0.3, 1);
pBomb->SetSpeed(2);
pBomb->SetPos(x, y);
pBomb->SetWidth(SMALL_CRATER_SIZE);
vecDynamicObj.push_back(pBomb);
bombsNumber--;
score -= Bomb::BombCost;
}
}

View File

@ -0,0 +1,198 @@
#include "ScreenSingleton.h"
#include <stdint.h>
#include <time.h>
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
#include "MyTools.h"
#if defined(_WIN32) || defined(WIN32)
#include <conio.h>
#include <windows.h>
#else
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#endif
//
//
//
IScreen& getInternalInstance() {
static ScreenSingleton theInstance;
return theInstance;
}
//
//
//
class ScreenSingletonProxy : public IScreen {
public:
virtual void ClrScr() override {
MyTools::WriteToLog("ClrScr invoke begin");
getInternalInstance().ClrScr();
MyTools::WriteToLog("ClrScr invoke end");
}
virtual void GotoXY(double x, double y) override {
MyTools::WriteToLog("GotoXY invoke begin");
getInternalInstance().GotoXY(x, y);
MyTools::WriteToLog("GotoXY invoke end");
}
virtual uint16_t GetMaxX() override {
return getInternalInstance().GetMaxX();
}
virtual uint16_t GetMaxY() override {
return getInternalInstance().GetMaxY();
}
virtual void SetColor(ConsoleColor color) override {
return getInternalInstance().SetColor(color);
}
static IScreen& getInstance() {
static ScreenSingletonProxy theInstance;
return theInstance;
}
private:
ScreenSingletonProxy() {
}
~ScreenSingletonProxy() {
}
ScreenSingletonProxy(const ScreenSingletonProxy& root) = delete;
ScreenSingletonProxy& operator=(const ScreenSingletonProxy&) = delete;
ScreenSingletonProxy(ScreenSingletonProxy&& root) = delete;
ScreenSingletonProxy& operator=(ScreenSingletonProxy&&) = delete;
};
//
//
//
#if defined(_WIN32) || defined(WIN32)
void ScreenSingleton::ClrScr() {
system("cls");
}
void ScreenSingleton::GotoXY(double x, double y) {
const COORD cc = {short(x), short(y)};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cc);
}
uint16_t ScreenSingleton::GetMaxX() {
HANDLE hWndConsole;
if (hWndConsole = GetStdHandle(-12)) {
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
if (GetConsoleScreenBufferInfo(hWndConsole, &consoleInfo)) {
return consoleInfo.srWindow.Right;
int height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
}
}
return 0;
}
uint16_t ScreenSingleton::GetMaxY() {
HANDLE hWndConsole;
if (hWndConsole = GetStdHandle(-12)) {
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
if (GetConsoleScreenBufferInfo(hWndConsole, &consoleInfo)) {
return consoleInfo.srWindow.Bottom;
}
}
return 0;
}
void ScreenSingleton::SetColor(ConsoleColor color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
#else
void ScreenSingleton::ClrScr() {
system("clear");
}
void ScreenSingleton::GotoXY(double x, double y) {
printf("\033[%d;%dH", (int)y + 1, (int)x + 1);
}
uint16_t ScreenSingleton::GetMaxX() {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_col;
}
uint16_t ScreenSingleton::GetMaxY() {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
return w.ws_row;
}
int convertColorToCode(const ConsoleColor color) {
switch (color) {
case CC_Black: {
return 30;
} break;
case CC_Blue: {
return 34;
} break;
case CC_Green: {
return 32;
} break;
case CC_Cyan: {
return 36;
} break;
case CC_Red: {
return 31;
} break;
case CC_Magenta: {
return 35;
} break;
case CC_LightBlue: {
return 94;
} break;
case CC_LightGreen: {
return 92;
} break;
case CC_LightCyan: {
return 96;
} break;
case CC_LightRed: {
return 91;
} break;
case CC_LightMagenta: {
return 95;
} break;
case CC_Yellow: {
return 93;
} break;
case CC_White: {
return 97;
} break;
default: {
throw std::runtime_error("not handled");
}
}
}
void ScreenSingleton::SetColor(ConsoleColor color) {
std::cout << "\033[" << convertColorToCode(color) << "m";
}
#endif
IScreen& ScreenSingleton::getInstance() {
return ScreenSingletonProxy::getInstance();
}

45
SBomber/src/Tank.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
#include "Tank.h"
#include "MyTools.h"
#include "ScreenSingleton.h"
using namespace std;
using namespace MyTools;
bool Tank::isInside(double x1, double x2) const
{
const double XBeg = x + 2;
const double XEnd = x + width - 1;
if (x1 < XBeg && x2 > XEnd)
{
return true;
}
if (x1 > XBeg && x1 < XEnd)
{
return true;
}
if (x2 > XBeg && x2 < XEnd)
{
return true;
}
return false;
}
void Tank::Draw() const
{
ScreenSingleton::getInstance().SetColor(CC_Cyan);
ScreenSingleton::getInstance().GotoXY(x, y - 3);
cout << " #####";
ScreenSingleton::getInstance().GotoXY(x-2, y - 2);
cout << "####### #";
ScreenSingleton::getInstance().GotoXY(x, y - 1);
cout << " #####";
ScreenSingleton::getInstance().GotoXY(x,y);
cout << " ###########";
}