-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathExceptions.hpp
More file actions
54 lines (42 loc) · 1.71 KB
/
Copy pathExceptions.hpp
File metadata and controls
54 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef EXCEPTIONS_HPP
#define EXCEPTIONS_HPP
#include <exception>
#include <string>
#include "Enums.hpp"
class GameException : public std::exception{
private:
GameErrorCode errorCode;
std::string errorMessage;
public:
GameException(GameErrorCode errorCode, const std::string& errorMessage) : errorCode(errorCode), errorMessage(errorMessage){}
GameErrorCode getErrorCode() const{
return errorCode;
}
std::string getErrorMessage() const{
return errorMessage;
}
const char* what() const noexcept override{
return errorMessage.c_str();
}
};
class NotEnoughMoneyException : public GameException{
public:
NotEnoughMoneyException(int have, int need, const std::string& context) : GameException( GameErrorCode::NOT_ENOUGH_MONEY, "Uang tidak cukup untuk: " + context + ". Punya: " + std::to_string(have) + ", Butuh: " + std::to_string(need)){}
};
class MaxCardLimitException : public GameException{
public:
MaxCardLimitException() : GameException(GameErrorCode::MAX_CARD_LIMIT, "Slot untuk kartu sudah limit! Maksimal 3"){}
};
class InvalidCommandException : public GameException{
public:
InvalidCommandException(const std::string command) : GameException(GameErrorCode::INVALID_COMMAND, "Command " + command + " tidak dikenali!"){}
};
class InvalidPropertyException : public GameException{
public:
InvalidPropertyException(const std::string kode) : GameException(GameErrorCode::INVALID_PROPERTY, "Kode petak " + kode + " tidak dikenali!"){}
};
class GameStateException : public GameException{
public:
GameStateException(const std::string& context) : GameException(GameErrorCode::GAME_STATE_ERROR, "Tidak diperbolehkan melakukan " + context + " sekarang"){}
};
#endif