Skip to content

Commit

Permalink
merge: ass
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbu committed Apr 7, 2024
2 parents 6af1b3e + e74cda9 commit 9c74289
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 151 deletions.
4 changes: 3 additions & 1 deletion Arcade/Arcade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ int gg::Arcade::run() const
auto game_instance = game->get<ass::IGame>();

for (bool running = true; running;) {
switch (game_instance->run(engine)) {
auto status = game_instance->run(engine);
// TODO: score
switch (status.first) {
case ass::RunStatus::Exit:
running = false;
break;
Expand Down
11 changes: 6 additions & 5 deletions Games/snake/Snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ Snake::Snake()

Snake::~Snake() = default;

ass::RunStatus Snake::run(ass::IEngine &engine)
std::pair<ass::RunStatus, size_t> Snake::run(ass::IEngine &engine)
{
const auto interval = std::chrono::milliseconds(100);
size_t score = 0;

Player snake{engine};
Fruit fruit{engine};
Expand All @@ -41,11 +42,11 @@ ass::RunStatus Snake::run(ass::IEngine &engine)
continue;
switch (event.key) {
case ass::EventKey::KeyQ:
return ass::RunStatus::Exit;
return {ass::RunStatus::Exit, score};
case ass::EventKey::KeyR:
return ass::RunStatus::Restart;
return {ass::RunStatus::Restart, score};
case ass::EventKey::KeyM:
return ass::RunStatus::ShowMenu;
return {ass::RunStatus::ShowMenu, score};
case ass::EventKey::KeyN:
engine.next_renderer();
break;
Expand All @@ -69,7 +70,7 @@ ass::RunStatus Snake::run(ass::IEngine &engine)

// Check if the player is dead
if (snake.is_dead(engine))
return ass::RunStatus::Exit;
return {ass::RunStatus::Exit, score};

// The snake touches the fruit
auto fruit_pos = fruit.position();
Expand Down
2 changes: 1 addition & 1 deletion Games/snake/Snake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Snake : public ass::IGame
Snake();
~Snake() override;

ass::RunStatus run(ass::IEngine &engine) final;
std::pair<ass::RunStatus, size_t> run(ass::IEngine &engine) final;
};

enum class Direction {
Expand Down
1 change: 0 additions & 1 deletion lib/ASS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ project(ASS
LANGUAGES CXX
)


add_library(ass INTERFACE)
target_include_directories(ass INTERFACE include)
target_compile_options(ass INTERFACE "$<$<CXX_COMPILER_ID:Clang,GNU>:-Wno-return-type-c-linkage>")
Expand Down
92 changes: 4 additions & 88 deletions lib/ASS/README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,9 @@
# Arcade Standard Specifications

## The project

The goal of this repository is to set a standard for the implementation of our [arcade](https://gitlab.com/epitech-it-2027/arcade) project.

## Getting started
As the goal of the **arcade** is to do arcade game and engines compliant with an other group (go check the [arcade](https://gitlab.com/epitech-it-2027/arcade) for more info) the goal of this repo is to have always the same interfaces between the two groups.

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://gitlab.com/epitech-it-2027/arcade-standard-specifications.git
git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](https://gitlab.com/epitech-it-2027/arcade-standard-specifications/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
For more information about how to implement your libs, go check the doc on [mainpage](https://gitlab.com/epitech-it-2027/arcade-standard-specifications).
10 changes: 5 additions & 5 deletions lib/ASS/cmake/MakeLib.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_custom_target(renderers)
add_custom_target(games)
add_custom_target(ass_renderers)
add_custom_target(ass_games)

function(ass_add_library name TYPE)
if ((NOT TYPE STREQUAL "GAME") AND (NOT TYPE STREQUAL "RENDERER"))
Expand All @@ -11,9 +11,9 @@ function(ass_add_library name TYPE)
PREFIX arcade_
)
if (TYPE STREQUAL GAME)
add_dependencies(games ${name})
elseif ()
add_dependencies(renderers ${name})
add_dependencies(ass_games ${name})
else ()
add_dependencies(ass_renderers ${name})
endif ()
ass_add_tests(${name} ${TYPE})
endfunction()
32 changes: 17 additions & 15 deletions lib/ASS/cmake/MakeTests.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
option(MAKE_TESTS "Build tests" OFF)
option(BUILD_TESTING "Build tests" OFF)

if (MAKE_TESTS)
if (BUILD_TESTING)
enable_testing()
include(FetchContent)

fetchcontent_declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
fetchcontent_makeavailable(googletest)

include(GoogleTest)

add_custom_target(games_tests)
add_custom_target(renderers_tests)

add_custom_target(ass_tests DEPENDS games_tests renderers_tests)
add_custom_target(ass_games_tests)
add_custom_target(ass_renderers_tests)
add_custom_target(ass_tests DEPENDS ass_games_tests ass_renderers_tests)
else ()
message(STATUS "Tests not enabled")
endif ()

function(ass_add_tests name TYPE)
if (NOT MAKE_TESTS)
if (NOT BUILD_TESTING)
return()
endif ()
if ((NOT TYPE STREQUAL GAME) AND (NOT TYPE STREQUAL RENDERER))
Expand All @@ -40,13 +39,16 @@ function(ass_add_tests name TYPE)
"
)
if (TYPE STREQUAL GAME)
add_executable(${name}_test ${CMAKE_SOURCE_DIR}/test/test_game.cpp)
add_dependencies(games_tests ${name}_test)
add_executable(${name}_test ${ASS_SOURCE_DIR}/test/test_game.cpp)
add_dependencies(ass_games_tests ${name}_test)
else ()
add_executable(${name}_test ${CMAKE_SOURCE_DIR}/test/test_renderer.cpp)
add_dependencies(renderers_tests ${name}_test)
add_executable(${name}_test ${ASS_SOURCE_DIR}/test/test_renderer.cpp)
add_dependencies(ass_renderers_tests ${name}_test)
endif ()
target_include_directories(${name}_test PRIVATE ${CONFIG_PATH})
include(GoogleTest)
target_link_libraries(${name}_test PRIVATE GTest::gtest_main ass)
gtest_discover_tests(${name}_test)
gtest_discover_tests(${name}_test
XML_OUTPUT_DIR ${PROJECT_BINARY_DIR}/logs/
)
endfunction()
6 changes: 3 additions & 3 deletions lib/ASS/include/ASS/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace ass {
/**
* @brief Event Key enumeration
* @brief Event Key enumeration, any other key should be ignored
*/
enum class EventKey: u_int8_t {
KeyA,
Expand Down Expand Up @@ -56,15 +56,15 @@ enum class EventKey: u_int8_t {
};

/**
* @brief Event Key enumeration
* @brief Event State enumeration, either released or pressed.
*/
enum class EventState: int8_t {
KeyReleased, ///< State for Key release
KeyPressed, ///< State for Key press
};

/**
* @brief Event Container
* @brief Event Container. This contains an eventkey (key) and a state
*/
struct Event {
/// Key of the Event
Expand Down
37 changes: 26 additions & 11 deletions lib/ASS/include/ASS/IEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <memory>
#include <string>

#include "IRenderer.hpp"
#include "Events.hpp"
#include "IRenderer.hpp"
#include "ISprite.hpp"

namespace ass {
Expand All @@ -30,16 +30,20 @@ namespace ass {
* @exception IEngine::Exception
* @ingroup engine
* @brief Engine Interface
* @details Set of method to implement for the Engine Part of the Arcade project
* @details Set of method to implement for the Engine Part of the Arcade
* project. The engine handle the sprites data, and do the link between games
* and renderers.
*
*/
class IEngine {
public:
class IEngine
{
public:
/**
* @brief Engine Exception
* @details Base class for Engines’s scoped exceptions
*/
class Exception: public std::exception {};
class Exception : public std::exception
{};

IEngine() = default;
virtual ~IEngine() = default;
Expand All @@ -49,10 +53,10 @@ class IEngine {
*/
virtual void refresh() = 0;

/**
* @brief Create a new sprite
* @return Pointer to a new sprite
*/
/**
* @brief Create a new sprite
* @return Pointer to a new sprite
*/
virtual std::unique_ptr<ass::ISprite> create_sprite() = 0;

/**
Expand All @@ -74,19 +78,30 @@ class IEngine {
/**
* @copydoc IRenderer::draw_text
*/
virtual void draw_text(Vector2<float> pos, std::string text, uint size, TermColor color) = 0;
virtual void draw_text(
Vector2<float> pos, std::string text, uint size, TermColor color) = 0;

/**
* @brief sleep until the next frame
* @param fps frame rate per seconds
*/
virtual void wait_frame(u_int8_t fps) = 0;

/**
* @brief replace old renderer with a new one, do all the changes needed by the sprites
* @param renderer new renderer
*/
virtual void set_renderer(std::unique_ptr<ass::IRenderer> &&renderer) = 0;

/**
* @brief get access to the actual renderer
* @return ref to the actual renderer
*/
virtual ass::IRenderer &get_renderer() = 0;

/**
* @brief hot switch the renderer used
* @details this method should read the `lib` folder, and set the renderer to the next one in the folder.
*/
virtual void next_renderer() = 0;

Expand All @@ -95,4 +110,4 @@ class IEngine {
IEngine &operator=(const IEngine &) = default;
IEngine &operator=(IEngine &&) = delete;
};
} // namespace ass
} // namespace ass
Loading

0 comments on commit 9c74289

Please sign in to comment.