-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved over everything and deleted curses content
- Loading branch information
Showing
10 changed files
with
387 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2022-2024 r3w0p | ||
// The following code can be redistributed and/or | ||
// modified under the terms of the GPL-3.0 License. | ||
|
||
#ifndef CARAVAN_CONTROLLER_H | ||
#define CARAVAN_CONTROLLER_H | ||
|
||
#include <array> | ||
#include "caravan/core/common.h" | ||
#include "caravan/model/game.h" | ||
#include "caravan/user/user.h" | ||
#include "caravan/view/view.h" | ||
|
||
|
||
class Controller { | ||
protected: | ||
Game *game_ptr; | ||
View *view_ptr; | ||
User *user_a_ptr; | ||
User *user_b_ptr; | ||
public: | ||
explicit Controller(Game *g, View *v, User *ua, User *ub) : | ||
game_ptr(g), view_ptr(v), user_a_ptr(ua), user_b_ptr(ub) {}; | ||
|
||
void run(); | ||
}; | ||
|
||
#endif //CARAVAN_CONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2022-2024 r3w0p | ||
// The following code can be redistributed and/or | ||
// modified under the terms of the GPL-3.0 License. | ||
|
||
#ifndef CARAVAN_BOT_EASY_H | ||
#define CARAVAN_BOT_EASY_H | ||
|
||
|
||
#include "caravan/user/user.h" | ||
|
||
class UserBotEasy : public UserBot { | ||
public: | ||
explicit UserBotEasy(PlayerName pn) : UserBot(pn) {}; | ||
|
||
GameOption generate_option(Game *g) override; | ||
}; | ||
|
||
#endif //CARAVAN_BOT_EASY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2022-2024 r3w0p | ||
// The following code can be redistributed and/or | ||
// modified under the terms of the GPL-3.0 License. | ||
|
||
#ifndef CARAVAN_USER_H | ||
#define CARAVAN_USER_H | ||
|
||
#include "caravan/core/common.h" | ||
#include "caravan/model/game.h" | ||
|
||
class User { | ||
protected: | ||
PlayerName name; | ||
public: | ||
explicit User(PlayerName pn) : name(pn) {}; | ||
|
||
PlayerName get_name() { return name; } | ||
|
||
virtual bool is_human() = 0; | ||
}; | ||
|
||
class UserHuman : public User { | ||
public: | ||
explicit UserHuman(PlayerName pn) : User(pn) {}; | ||
|
||
bool is_human() override; | ||
}; | ||
|
||
class UserBot : public User { | ||
public: | ||
explicit UserBot(PlayerName pn) : User(pn) {}; | ||
|
||
bool is_human() override; | ||
virtual GameOption generate_option(Game *g) = 0; | ||
}; | ||
|
||
#endif //CARAVAN_USER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2022-2024 r3w0p | ||
// The following code can be redistributed and/or | ||
// modified under the terms of the GPL-3.0 License. | ||
|
||
#ifndef CARAVAN_VIEW_H | ||
#define CARAVAN_VIEW_H | ||
|
||
#include <string> | ||
#include "caravan/model/game.h" | ||
#include "caravan/user/user.h" | ||
|
||
class View { | ||
public: | ||
virtual void update(Game *g, User *ubottom, User *utop, GameOption* go_bottom, GameOption* go_top) = 0; | ||
virtual GameOption option(Game *g, User *u) = 0; | ||
virtual void close() = 0; | ||
virtual void error_message(std::string msg) = 0; | ||
}; | ||
|
||
#endif //CARAVAN_VIEW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2022-2024 r3w0p | ||
// The following code can be redistributed and/or | ||
// modified under the terms of the GPL-3.0 License. | ||
|
||
#include "caravan/controller/controller.h" | ||
#include <string> | ||
|
||
|
||
void Controller::run() { | ||
GameOption go_bottom; | ||
GameOption go_top; | ||
GameOption go_temp; | ||
User *user_turn; | ||
PlayerCaravanNames cvns; | ||
|
||
go_bottom = {NO_OPTION}; | ||
go_top = {NO_OPTION}; | ||
|
||
do { | ||
user_turn = game_ptr->get_player_turn() == user_a_ptr->get_name() ? | ||
user_a_ptr : user_b_ptr; | ||
|
||
// Only update view if current user is a human | ||
if (user_turn->is_human()) | ||
view_ptr->update(game_ptr, user_a_ptr, user_b_ptr, | ||
&go_bottom, &go_top); | ||
|
||
try { | ||
// Get user's next move | ||
if (user_turn->get_name() == PLAYER_BOTTOM) { | ||
go_temp = go_bottom; | ||
go_bottom = view_ptr->option(game_ptr, user_turn); | ||
|
||
// Immediately quit on exit request | ||
if (go_bottom.type == OPTION_EXIT) | ||
return; | ||
|
||
// Attempt to play user's desired move | ||
game_ptr->play_option(&go_bottom); | ||
|
||
} else { | ||
go_temp = go_top; | ||
go_top = view_ptr->option(game_ptr, user_turn); | ||
|
||
// Immediately quit on exit request | ||
if (go_top.type == OPTION_EXIT) | ||
return; | ||
|
||
// Attempt to play user's desired move | ||
game_ptr->play_option(&go_top); | ||
} | ||
|
||
} catch (CaravanException &e) { | ||
view_ptr->error_message(e.what()); | ||
|
||
if (user_turn->get_name() == PLAYER_BOTTOM) | ||
go_bottom = go_temp; | ||
else | ||
go_top = go_temp; | ||
} | ||
|
||
} while (game_ptr->get_winner() == NO_PLAYER); | ||
|
||
// Update one last time in order to display the winner | ||
view_ptr->update(game_ptr, user_a_ptr, user_b_ptr, &go_bottom, &go_top); | ||
} |
Oops, something went wrong.