feat: added game exit
This commit is contained in:
parent
2076219c8c
commit
273e135762
3 changed files with 34 additions and 1 deletions
|
@ -21,4 +21,5 @@ add_executable(epr24pr3_ojanssen2
|
||||||
Exceptions/MovementNotPossible.h
|
Exceptions/MovementNotPossible.h
|
||||||
Exceptions/MalformedMaze.h
|
Exceptions/MalformedMaze.h
|
||||||
Exceptions/UnkownAction.h
|
Exceptions/UnkownAction.h
|
||||||
|
Exceptions/ExitGame.h
|
||||||
)
|
)
|
||||||
|
|
26
Exceptions/ExitGame.h
Normal file
26
Exceptions/ExitGame.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// Created by moonleay on 12/17/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef EXITGAME_H
|
||||||
|
#define EXITGAME_H
|
||||||
|
|
||||||
|
namespace game_exceptions
|
||||||
|
{
|
||||||
|
class ExitGame
|
||||||
|
{
|
||||||
|
string why;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExitGame(string why): why(why)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
string what()
|
||||||
|
{
|
||||||
|
return this->why;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // game_exceptions
|
||||||
|
|
||||||
|
#endif //EXITGAME_H
|
8
Game.cpp
8
Game.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include "MazeParser.h"
|
#include "MazeParser.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Maze.h"
|
#include "Maze.h"
|
||||||
|
#include "Exceptions/ExitGame.h"
|
||||||
#include "Exceptions/MovementNotPossible.h"
|
#include "Exceptions/MovementNotPossible.h"
|
||||||
#include "Exceptions/UnkownAction.h"
|
#include "Exceptions/UnkownAction.h"
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ using game::Player;
|
||||||
using game::Maze;
|
using game::Maze;
|
||||||
using game_exceptions::UnkownAction;
|
using game_exceptions::UnkownAction;
|
||||||
using game_exceptions::MovementNotPossible;
|
using game_exceptions::MovementNotPossible;
|
||||||
|
using game_exceptions::ExitGame;
|
||||||
|
|
||||||
namespace game // Namespace = Scope with name and no features
|
namespace game // Namespace = Scope with name and no features
|
||||||
{
|
{
|
||||||
|
@ -50,6 +52,8 @@ namespace game // Namespace = Scope with name and no features
|
||||||
case 'd':
|
case 'd':
|
||||||
movement_vector.update(1, 0);
|
movement_vector.update(1, 0);
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
throw ExitGame("Schoenen Tag noch!");
|
||||||
case 'h':
|
case 'h':
|
||||||
// Schreibe hilfsreiche Tipps in die Konsole
|
// Schreibe hilfsreiche Tipps in die Konsole
|
||||||
cout <<
|
cout <<
|
||||||
|
@ -102,11 +106,13 @@ namespace game // Namespace = Scope with name and no features
|
||||||
{
|
{
|
||||||
movement_vector = handle_user_input(game_input);
|
movement_vector = handle_user_input(game_input);
|
||||||
} catch (UnkownAction& err)
|
} catch (UnkownAction& err)
|
||||||
|
{
|
||||||
|
cout << err.what() << "\n";
|
||||||
|
} catch (ExitGame& err)
|
||||||
{
|
{
|
||||||
cout << err.what() << "\n";
|
cout << err.what() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Kontrolliere gewollte Bewegung und setze sie um.
|
// Kontrolliere gewollte Bewegung und setze sie um.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue