Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Blackjack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
Blackjack
Commits
5a580bd0
Commit
5a580bd0
authored
2 years ago
by
spiasecki
Browse files
Options
Downloads
Patches
Plain Diff
Added comments + changes in color and window size
parent
589bc37f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
source/client/GameController.cpp
+9
-70
9 additions, 70 deletions
source/client/GameController.cpp
source/client/GameController.hpp
+0
-1
0 additions, 1 deletion
source/client/GameController.hpp
source/client/windows/GameWindow.cpp
+3
-3
3 additions, 3 deletions
source/client/windows/GameWindow.cpp
with
12 additions
and
74 deletions
source/client/GameController.cpp
+
9
−
70
View file @
5a580bd0
...
@@ -23,6 +23,8 @@ game_state* GameController::_previous_game_state = nullptr;
...
@@ -23,6 +23,8 @@ game_state* GameController::_previous_game_state = nullptr;
void
GameController
::
init
(
GameWindow
*
gameWindow
)
{
void
GameController
::
init
(
GameWindow
*
gameWindow
)
{
GameController
::
_gameWindow
=
gameWindow
;
GameController
::
_gameWindow
=
gameWindow
;
// resizing after start makes panels appear without manual resizing
GameController
::
_gameWindow
->
SetSize
(
wxSize
(
1250
,
900
));
// Set up main panels
// Set up main panels
GameController
::
_connectionPanel
=
new
ConnectionPanel
(
gameWindow
);
GameController
::
_connectionPanel
=
new
ConnectionPanel
(
gameWindow
);
...
@@ -87,11 +89,13 @@ void GameController::connectToServer() {
...
@@ -87,11 +89,13 @@ void GameController::connectToServer() {
}
}
// checks if input of player is a valid bet
bool
GameController
::
_is_number
(
const
wxString
s
){
bool
GameController
::
_is_number
(
const
wxString
s
){
return
!
s
.
empty
()
&&
std
::
find_if
(
s
.
begin
(),
return
!
s
.
empty
()
&&
std
::
find_if
(
s
.
begin
(),
s
.
end
(),
[](
unsigned
char
c
)
{
return
!
std
::
isdigit
(
c
);
})
==
s
.
end
();
s
.
end
(),
[](
unsigned
char
c
)
{
return
!
std
::
isdigit
(
c
);
})
==
s
.
end
();
}
}
// sends bet request to server after making bet by player
void
GameController
::
makeBet
()
{
void
GameController
::
makeBet
()
{
int
bet_int
;
int
bet_int
;
...
@@ -103,7 +107,6 @@ void GameController::makeBet() {
...
@@ -103,7 +107,6 @@ void GameController::makeBet() {
return
;
return
;
}
}
// recovery?
if
(
inputPlayerBet
.
IsEmpty
())
{
if
(
inputPlayerBet
.
IsEmpty
())
{
GameController
::
showError
(
"Input error"
,
"Please enter your bet"
);
GameController
::
showError
(
"Input error"
,
"Please enter your bet"
);
bet_int
=
0
;
bet_int
=
0
;
...
@@ -115,7 +118,7 @@ void GameController::makeBet() {
...
@@ -115,7 +118,7 @@ void GameController::makeBet() {
bet_int
=
std
::
stoi
(
bet_string
);
bet_int
=
std
::
stoi
(
bet_string
);
}
}
// check to make sure this in a logical integer
+ ADD RECOVERY (SHOW BET PANEL AGAIN)
// check to make sure this in a logical integer
if
(
bet_int
<
game_state
::
_min_bet
&&
bet_int
>
4096
)
{
if
(
bet_int
<
game_state
::
_min_bet
&&
bet_int
>
4096
)
{
GameController
::
showError
(
"Input error"
,
"Invalid value given as bet"
);
GameController
::
showError
(
"Input error"
,
"Invalid value given as bet"
);
return
;
return
;
...
@@ -129,7 +132,6 @@ void GameController::makeBet() {
...
@@ -129,7 +132,6 @@ void GameController::makeBet() {
}
}
void
GameController
::
continue_to_bet_panel
()
{
void
GameController
::
continue_to_bet_panel
()
{
//GameController::showNewRoundMessage(GameController::_previous_game_state, GameController::_current_game_state);
if
(
GameController
::
_current_game_state
->
is_finished
())
{
if
(
GameController
::
_current_game_state
->
is_finished
())
{
GameController
::
showGameOverMessage
();
GameController
::
showGameOverMessage
();
}
}
...
@@ -143,10 +145,9 @@ void GameController::continue_to_bet_panel() {
...
@@ -143,10 +145,9 @@ void GameController::continue_to_bet_panel() {
}
}
}
}
// THIS HAS TO BE EDITTED FOR SURE
void
GameController
::
updateGameState
(
game_state
*
newGameState
)
{
void
GameController
::
updateGameState
(
game_state
*
newGameState
)
{
// the existing game state is
now old
// the existing game state is
saved as previous
GameController
::
_previous_game_state
=
GameController
::
_current_game_state
;
GameController
::
_previous_game_state
=
GameController
::
_current_game_state
;
// save the new game state as our current game state
// save the new game state as our current game state
...
@@ -163,45 +164,16 @@ void GameController::updateGameState(game_state* newGameState) {
...
@@ -163,45 +164,16 @@ void GameController::updateGameState(game_state* newGameState) {
GameController
::
showError
(
"Game state error"
,
"Could not find this player among players of server game."
);
GameController
::
showError
(
"Game state error"
,
"Could not find this player among players of server game."
);
return
;
return
;
}
}
//previously
/*
// edit this to trigger when player is bankrupt
if(GameController::_current_game_state->is_finished()) {
GameController::showGameOverMessage();
}
if(_me->get_bet_size() == 0 && GameController::_current_game_state->is_started()) {
GameController::_betPanel = new BetPanel(_gameWindow, GameController::_current_game_state, GameController::_me);
GameController::_gameWindow->showPanel(GameController::_betPanel);
} else {
GameController::_gameWindow->showPanel(GameController::_mainGamePanel);
// command the main game panel to rebuild itself, based on the new game state
GameController::_mainGamePanel->buildGameState(GameController::_current_game_state, GameController::_me);
}
if(oldGameState != nullptr) {
// check if a new round started, and display message accordingly
if(oldGameState->get_round_number() > 0 && oldGameState->get_round_number() < newGameState->get_round_number()) {
//std::this_thread::sleep_for(std::chrono::seconds{10});
GameController::showNewRoundMessage(oldGameState, newGameState);
//std::this_thread::sleep_for(std::chrono::seconds{10});
}
// delete the old game state, we don't need it anymore
delete oldGameState;
}
*/
// now
// if game just started, show bet panel
if
(
GameController
::
_previous_game_state
!=
nullptr
&&
(
GameController
::
_previous_game_state
->
everyone_finished
()
&&
newGameState
->
round_begin
()))
{
if
(
GameController
::
_previous_game_state
!=
nullptr
&&
(
GameController
::
_previous_game_state
->
everyone_finished
()
&&
newGameState
->
round_begin
()))
{
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_mainGamePanel
);
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_mainGamePanel
);
GameController
::
_mainGamePanel
->
buildGameState
(
GameController
::
_previous_game_state
,
GameController
::
_me
);
GameController
::
_mainGamePanel
->
buildGameState
(
GameController
::
_previous_game_state
,
GameController
::
_me
);
// if you clicked continue, also show bet panel
}
else
if
(
_me
->
get_bet_size
()
==
0
&&
GameController
::
_current_game_state
->
is_started
()
&&
!
(
_me
->
is_broke
()))
{
}
else
if
(
_me
->
get_bet_size
()
==
0
&&
GameController
::
_current_game_state
->
is_started
()
&&
!
(
_me
->
is_broke
()))
{
GameController
::
_betPanel
=
new
BetPanel
(
_gameWindow
,
GameController
::
_current_game_state
,
GameController
::
_me
);
GameController
::
_betPanel
=
new
BetPanel
(
_gameWindow
,
GameController
::
_current_game_state
,
GameController
::
_me
);
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_betPanel
);
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_betPanel
);
// otherwise, show main panel
}
else
{
}
else
{
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_mainGamePanel
);
GameController
::
_gameWindow
->
showPanel
(
GameController
::
_mainGamePanel
);
// command the main game panel to rebuild itself, based on the new game state
// command the main game panel to rebuild itself, based on the new game state
...
@@ -243,39 +215,6 @@ void GameController::showStatus(const std::string& message) {
...
@@ -243,39 +215,6 @@ void GameController::showStatus(const std::string& message) {
}
}
void
GameController
::
showNewRoundMessage
(
game_state
*
oldGameState
,
game_state
*
newGameState
)
{
std
::
string
title
=
"Round Completed"
;
std
::
string
message
=
"The players have won following amounts of money:
\n
"
;
std
::
string
buttonLabel
=
"Start next round"
;
// add the point differences of all players to the messages
for
(
int
i
=
0
;
i
<
oldGameState
->
get_players
().
size
();
i
++
)
{
player
*
oldPlayerState
=
oldGameState
->
get_players
().
at
(
i
);
player
*
newPlayerState
=
newGameState
->
get_players
().
at
(
i
);
int
money_difference
=
newPlayerState
->
get_money
()
-
oldPlayerState
->
get_money
();
std
::
string
moneyText
=
std
::
to_string
(
money_difference
);
if
(
money_difference
>
0
)
{
moneyText
=
"+"
+
moneyText
;
}
std
::
string
playerName
=
newPlayerState
->
get_player_name
();
if
(
newPlayerState
->
get_id
()
==
GameController
::
_me
->
get_id
())
{
playerName
=
"You"
;
}
message
+=
"
\n
"
+
playerName
+
": "
+
moneyText
;
}
//std::this_thread::sleep_for(std::chrono::seconds{10});
wxMessageDialog
dialogBox
=
wxMessageDialog
(
nullptr
,
message
,
title
,
wxICON_NONE
);
//std::this_thread::sleep_for(std::chrono::seconds{10});
dialogBox
.
SetOKLabel
(
wxMessageDialog
::
ButtonLabel
(
buttonLabel
));
//std::this_thread::sleep_for(std::chrono::seconds{10});
dialogBox
.
ShowModal
();
//std::this_thread::sleep_for(std::chrono::seconds{10});
}
void
GameController
::
showGameOverMessage
()
{
void
GameController
::
showGameOverMessage
()
{
std
::
string
title
=
"Game Over!"
;
std
::
string
title
=
"Game Over!"
;
std
::
string
message
=
"Final score:
\n
"
;
std
::
string
message
=
"Final score:
\n
"
;
...
...
This diff is collapsed.
Click to expand it.
source/client/GameController.hpp
+
0
−
1
View file @
5a580bd0
...
@@ -27,7 +27,6 @@ public:
...
@@ -27,7 +27,6 @@ public:
static
wxEvtHandler
*
getMainThreadEventHandler
();
static
wxEvtHandler
*
getMainThreadEventHandler
();
static
void
showError
(
const
std
::
string
&
title
,
const
std
::
string
&
message
);
static
void
showError
(
const
std
::
string
&
title
,
const
std
::
string
&
message
);
static
void
showStatus
(
const
std
::
string
&
message
);
static
void
showStatus
(
const
std
::
string
&
message
);
static
void
showNewRoundMessage
(
game_state
*
oldGameState
,
game_state
*
newGameState
);
static
void
showGameOverMessage
();
static
void
showGameOverMessage
();
private:
private:
...
...
This diff is collapsed.
Click to expand it.
source/client/windows/GameWindow.cpp
+
3
−
3
View file @
5a580bd0
...
@@ -15,11 +15,11 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize&
...
@@ -15,11 +15,11 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize&
this
->
_statusBar
=
this
->
CreateStatusBar
(
1
);
this
->
_statusBar
=
this
->
CreateStatusBar
(
1
);
// Set background
// Set background
wxColor
light
Blue
=
wxColor
(
213
,
231
,
239
);
wxColor
light
Green
=
wxColor
(
50
,
205
,
50
);
this
->
SetBackgroundColour
(
light
Blue
);
this
->
SetBackgroundColour
(
light
Green
);
// Set the minimum size of the window. The user won't be able to resize the window to a size smaller than this
// Set the minimum size of the window. The user won't be able to resize the window to a size smaller than this
this
->
SetMinSize
(
wxSize
(
1
0
00
,
72
0
));
this
->
SetMinSize
(
wxSize
(
1
2
00
,
85
0
));
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment