From e982dc2c7b911e2076b694a00afb9cf34cfe5347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20Leroux?= Date: Tue, 7 Jun 2022 12:21:18 +0200 Subject: [PATCH] Add Users world resource Linked: #92 --- src/game/User.cpp | 29 +++++++++++++++++++++++++++++ src/game/User.hpp | 39 +++++++++++++++++++++++++++++++++++++++ src/game/Users.cpp | 22 ++++++++++++++++++++++ src/game/Users.hpp | 31 +++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 src/game/User.cpp create mode 100644 src/game/User.hpp create mode 100644 src/game/Users.cpp create mode 100644 src/game/Users.hpp diff --git a/src/game/User.cpp b/src/game/User.cpp new file mode 100644 index 00000000..020065ae --- /dev/null +++ b/src/game/User.cpp @@ -0,0 +1,29 @@ +/* +** EPITECH PROJECT, 2022 +** Bomberman +** File description: +** User +*/ + +#include "User.hpp" + +namespace game +{ + User::User(size_t id, int gamepadId) : _profile(id), _gamepadId(gamepadId) { setAvailable(false); } + + void User::setKeyboard() { _gamepadId = -1; } + + bool User::isKeyboard() const { return _gamepadId < 0; } + + void User::setGamepadId(int id) { _gamepadId = id; } + + int User::getGamepadId() const { return _gamepadId; } + + void User::setId(size_t id) { _profile.load(id); } + + size_t User::getId() const { return _profile.getId(); } + + void User::setAvailable(bool available) { _available = available; } + + bool User::isAvailable() const { return _available; } +} // namespace game \ No newline at end of file diff --git a/src/game/User.hpp b/src/game/User.hpp new file mode 100644 index 00000000..de3cef4c --- /dev/null +++ b/src/game/User.hpp @@ -0,0 +1,39 @@ +/* +** EPITECH PROJECT, 2022 +** Bomberman +** File description: +** User +*/ + +#ifndef GAME_USER_HPP_ +#define GAME_USER_HPP_ + +#include "settings/Profile.hpp" + +namespace game +{ + class User { + public: + User(size_t id = 0, int gamepadId = -1); + ~User() = default; + + void setKeyboard(); + bool isKeyboard() const; + + void setGamepadId(int id); + int getGamepadId() const; + + void setId(size_t id); + size_t getId() const; + + void setAvailable(bool available); + bool isAvailable() const; + + private: + int _gamepadId; + bool _available; + settings::Profile _profile; + }; +} // namespace game + +#endif /* !GAME_USER_HPP_ */ diff --git a/src/game/Users.cpp b/src/game/Users.cpp new file mode 100644 index 00000000..f8f8840b --- /dev/null +++ b/src/game/Users.cpp @@ -0,0 +1,22 @@ +/* +** EPITECH PROJECT, 2022 +** Bomberman +** File description: +** Users +*/ + +#include "Users.hpp" + +namespace game +{ + Users::Users() + { + for (size_t i = 0; i < UserId::PlayerCount; i++) + _users[i].setId(i); + } + + User &Users::operator[](UserId id) { return _users[id]; } + + const User &Users::operator[](UserId id) const { return _users[id]; } + +} // namespace game \ No newline at end of file diff --git a/src/game/Users.hpp b/src/game/Users.hpp new file mode 100644 index 00000000..5f5cc26c --- /dev/null +++ b/src/game/Users.hpp @@ -0,0 +1,31 @@ +/* +** EPITECH PROJECT, 2022 +** Bomberman +** File description: +** Users +*/ + +#ifndef GAME_USERS_HPP_ +#define GAME_USERS_HPP_ + +#include "User.hpp" +#include "ecs/resource/Resource.hpp" + +namespace game +{ + class Users : public ecs::Resource { + public: + enum UserId { Player1, Player2, Player3, Player4, PlayerCount }; + + Users(); + ~Users() = default; + + const User &operator[](UserId id) const; + User &operator[](UserId id); + + private: + User _users[UserId::PlayerCount]; + }; +} // namespace game + +#endif /* !GAME_USERS_HPP_ */