forked from University/epr24pr42-ojanssen2
fix: compile
This commit is contained in:
parent
b49868a8ef
commit
0991f86614
20 changed files with 0 additions and 0 deletions
15
Util/GameState.h
Normal file
15
Util/GameState.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
namespace game
|
||||
{
|
||||
/// Beschreibt den aktuellen GameState
|
||||
enum class GameState
|
||||
{
|
||||
RUNNING,
|
||||
HIT_BY_GHOST,
|
||||
QUITTING,
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //GAMESTATE_H
|
11
Util/MathUtil.cpp
Normal file
11
Util/MathUtil.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "MathUtil.h"
|
||||
|
||||
namespace game {
|
||||
int MathUtil::get_min(const vector<int>& numbers) {
|
||||
int i = numbers[0];
|
||||
for (const int j : numbers)
|
||||
if (j < i)
|
||||
i = j;
|
||||
return i;
|
||||
}
|
||||
} // game
|
16
Util/MathUtil.h
Normal file
16
Util/MathUtil.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "../std_lib_inc.h"
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
namespace game
|
||||
{
|
||||
class MathUtil{
|
||||
public:
|
||||
/// Gebe die minimale Nummer aus einer Liste zurück
|
||||
/// @param numbers Eine liste an nummern
|
||||
/// @returns Die kleinste Nummer
|
||||
static int get_min(const vector<int>& numbers);
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //UTIL_H
|
85
Util/MazeParser.cpp
Normal file
85
Util/MazeParser.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
#include "MazeParser.h"
|
||||
#include "../Environment/Maze.h"
|
||||
#include "../Exceptions/MalformedMaze.h"
|
||||
#include "../Entities/Entity.h"
|
||||
|
||||
using game_exceptions::MalformedMaze;
|
||||
using game::Entity;
|
||||
|
||||
namespace game
|
||||
{
|
||||
vector<int> MazeParser::request_numbers_from_user(const int& amount_of_numbers)
|
||||
{
|
||||
int input;
|
||||
vector<int> list;
|
||||
|
||||
for (int i = 0; i < amount_of_numbers; ++i)
|
||||
{
|
||||
cin >> input;
|
||||
if (!cin)
|
||||
throw MalformedMaze("Cin failed while reading numbers!");
|
||||
|
||||
if (input > MAX_MAZE_SIZE)
|
||||
throw MalformedMaze("This maze is too big");
|
||||
list.push_back(input);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool MazeParser::validate_maze_element(const char& target)
|
||||
{
|
||||
for (const char c : valid_maze_elements)
|
||||
if (c == target)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MazeParser::is_valid_enemy(const char& target) {
|
||||
for (const char c : valid_enemies)
|
||||
if (c == target)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Maze MazeParser::request_maze_from_user()
|
||||
{
|
||||
vector<int> maze_size = request_numbers_from_user(2);
|
||||
|
||||
char input;
|
||||
vector<vector<char>> field;
|
||||
vector<Entity> enemies;
|
||||
|
||||
for (int y = 0; y < maze_size[0]; ++y)
|
||||
{
|
||||
vector<char> row;
|
||||
for (int x = 0; x < maze_size[1]; ++x)
|
||||
{
|
||||
cin >> input;
|
||||
if (!cin)
|
||||
throw MalformedMaze("Cin failed while reading chars!");
|
||||
|
||||
// I don't think that this is needed. I doubt that they test the check for this one ~Eric
|
||||
// if (input == 'q')
|
||||
// throw ExitGame("Schoenen Tag noch!");
|
||||
|
||||
if (!validate_maze_element(input))
|
||||
throw MalformedMaze("The given input is not a valid element of a maze!");
|
||||
if (is_valid_enemy(input))
|
||||
{
|
||||
enemies.push_back(Entity({x, y}, input));
|
||||
row.push_back('.');
|
||||
}
|
||||
else {
|
||||
row.push_back(input);
|
||||
}
|
||||
}
|
||||
|
||||
field.push_back(row);
|
||||
}
|
||||
|
||||
vector<int> player_start_pos = request_numbers_from_user(2);
|
||||
|
||||
return {field, player_start_pos, enemies};
|
||||
} // Beispieleingabe: `4 3 #.# #.K #T# #Z# 0 1`
|
||||
} // game
|
54
Util/MazeParser.h
Normal file
54
Util/MazeParser.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "../std_lib_inc.h"
|
||||
|
||||
#ifndef MAZEPARSER_H
|
||||
#define MAZEPARSER_H
|
||||
|
||||
/* Legende
|
||||
* S - Spieler
|
||||
* Z - Ziel
|
||||
* . - Leerer Raum (begehbar)
|
||||
* # - Wand
|
||||
* A - Animaltronic
|
||||
* K - Schlüssel
|
||||
* T - Tür
|
||||
* B - Bowie
|
||||
* C - Connellys
|
||||
*/
|
||||
namespace game
|
||||
{
|
||||
/// Erlaubte Zeichen in einem Labyrinth
|
||||
/// Ist eine Konstante, darf also in global scope
|
||||
static const vector<char> valid_maze_elements = {'Z', '.', '#', 'A', 'K', 'T', 'B', 'C'};
|
||||
/// Welche Geistertypen es gibt
|
||||
static const vector<char> valid_enemies = {'A', 'B', 'C'};
|
||||
/// Die Maximale Labyrinthgröße
|
||||
static constexpr int MAX_MAZE_SIZE = 20;
|
||||
|
||||
class Maze;
|
||||
class MazeParser
|
||||
{
|
||||
private:
|
||||
/// Lese eine bestimmte Anzahl an Nummern aus der Konsole
|
||||
/// @param amount_of_numbers Wie viele Nummern eingelesen werden sollen
|
||||
/// @return Die eingelesenen Nummern
|
||||
static vector<int> request_numbers_from_user(const int& amount_of_numbers);
|
||||
|
||||
/// Kontrolliere, ob ein Zeichen im Labyrinth vorkommen darf
|
||||
/// @param target Das Zeichen, welches Kontrolliert werden soll
|
||||
/// @return Ob das gegebene Zeichen in einem Labyrinth vorkommen darf
|
||||
static bool validate_maze_element(const char& target);
|
||||
|
||||
/// Ob der angegebene char in valider Geist ist
|
||||
/// @param target Der zu kontrollierende Wert
|
||||
/// @returns Ob der Wert ein Valider Geist ist
|
||||
static bool is_valid_enemy(const char& target);
|
||||
|
||||
public:
|
||||
/// Lese ein Labyrinth aus der Konsole
|
||||
/// @return Das Labyrinth
|
||||
/// @throws runtime_exception Falls die Eingabe nicht korrekt verlaufen ist.
|
||||
static Maze request_maze_from_user();
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //MAZEPARSER_H
|
47
Util/Vector2d.cpp
Normal file
47
Util/Vector2d.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "Vector2d.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
Vector2d::Vector2d(const int x, const int y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void Vector2d::update(const int& x, const int& y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void Vector2d::change_x(const int& amount) {
|
||||
this->x += amount;
|
||||
}
|
||||
|
||||
void Vector2d::change_y(const int& amount) {
|
||||
this->y += amount;
|
||||
}
|
||||
|
||||
Vector2d Vector2d::normalize() {
|
||||
Vector2d v = *this;
|
||||
if (v.x < 0)
|
||||
v.x *= -1;
|
||||
if (v.y < 0)
|
||||
v.y *= -1;
|
||||
return v;
|
||||
}
|
||||
|
||||
bool Vector2d::eq(const Vector2d& position) const {
|
||||
return this->x == position.x && this->y == position.y;
|
||||
}
|
||||
|
||||
|
||||
Vector2d Vector2d::get_new_updated(const int& diff_x, const int& diff_y) const {
|
||||
Vector2d new_position = *this;
|
||||
new_position.change_x(diff_x);
|
||||
new_position.change_y(diff_y);
|
||||
|
||||
return new_position;
|
||||
}
|
||||
|
||||
} // game
|
51
Util/Vector2d.h
Normal file
51
Util/Vector2d.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef POSITION_H
|
||||
#define POSITION_H
|
||||
|
||||
namespace game
|
||||
{
|
||||
/// Ein Vector aus zwei zahlen.
|
||||
/// Kann eine Position oder eine Differenz zwischen zwei Positionen darstellen.
|
||||
struct Vector2d
|
||||
{
|
||||
// struct -> members public by default
|
||||
// Die beiden Variablen des Vectors
|
||||
int x;
|
||||
int y;
|
||||
|
||||
/// Ein Vector aus zwei zahlen.
|
||||
/// Kann eine Position oder eine Differenz zwischen zwei Positionen darstellen.
|
||||
/// @param x Die 'X'-Koordinate
|
||||
/// @param y Die 'Y'-Koordinate
|
||||
Vector2d(int x, int y);
|
||||
|
||||
/// Aktualisiere die Werte des Vectors
|
||||
/// @param x Die neue 'X'-Koordinate
|
||||
/// @param y Die neue 'Y'-Koordinate
|
||||
void update(const int& x, const int& y);
|
||||
|
||||
/// Verschiebe den X Wert des Vektors um eine Anzahl
|
||||
/// @param amount Die zu verschiebene Anzahl
|
||||
void change_x(const int& amount);
|
||||
|
||||
/// Verschiebe den Y Wert des Vektors um eine Anzhal
|
||||
/// @param amount Die zu verschiebene Anzahl
|
||||
void change_y(const int& amount);
|
||||
|
||||
/// Kriege einen normalisierten Vektor zurück
|
||||
/// @returns Den aktuellen Vektor als normalisierter Vektor
|
||||
Vector2d normalize();
|
||||
|
||||
/// Kontrolliere, ob ein Vektor einem anderen Enspricht
|
||||
/// @param position Die Position mit der verglichen werden soll
|
||||
/// @returns Ob die Position die gleiche ist
|
||||
bool eq(const Vector2d& position) const;
|
||||
|
||||
/// Kriege einen Vektor, der mit den gegebenen Werten verschoben worden ist
|
||||
/// @param diff_x Die Verschiebung auf der X-Achse
|
||||
/// @param diff_y Die Verschiebung auf der Y-Achse
|
||||
/// @returns Den berrechneten Vektor
|
||||
Vector2d get_new_updated(const int& diff_x, const int& diff_y) const;
|
||||
};
|
||||
} // game
|
||||
|
||||
#endif //POSITION_H
|
Loading…
Add table
Add a link
Reference in a new issue