feat: added game exit

This commit is contained in:
moonleay 2024-12-17 14:31:47 +01:00
parent 2076219c8c
commit 273e135762
Signed by: moonleay
GPG key ID: 82667543CCD715FB
3 changed files with 34 additions and 1 deletions

View file

@ -21,4 +21,5 @@ add_executable(epr24pr3_ojanssen2
Exceptions/MovementNotPossible.h
Exceptions/MalformedMaze.h
Exceptions/UnkownAction.h
Exceptions/ExitGame.h
)

26
Exceptions/ExitGame.h Normal file
View 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

View file

@ -6,6 +6,7 @@
#include "MazeParser.h"
#include "Player.h"
#include "Maze.h"
#include "Exceptions/ExitGame.h"
#include "Exceptions/MovementNotPossible.h"
#include "Exceptions/UnkownAction.h"
@ -13,6 +14,7 @@ using game::Player;
using game::Maze;
using game_exceptions::UnkownAction;
using game_exceptions::MovementNotPossible;
using game_exceptions::ExitGame;
namespace game // Namespace = Scope with name and no features
{
@ -50,6 +52,8 @@ namespace game // Namespace = Scope with name and no features
case 'd':
movement_vector.update(1, 0);
break;
case 'q':
throw ExitGame("Schoenen Tag noch!");
case 'h':
// Schreibe hilfsreiche Tipps in die Konsole
cout <<
@ -102,11 +106,13 @@ namespace game // Namespace = Scope with name and no features
{
movement_vector = handle_user_input(game_input);
} catch (UnkownAction& err)
{
cout << err.what() << "\n";
} catch (ExitGame& err)
{
cout << err.what() << "\n";
}
// Kontrolliere gewollte Bewegung und setze sie um.
try
{