Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
oop
project
Commits
6594a3b0
Commit
6594a3b0
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
refacto: moved display hand method to IPlayer interface
parent
db4155de
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/hepia/GameManager.java
+10
-16
10 additions, 16 deletions
src/main/java/hepia/GameManager.java
src/main/java/hepia/HumanPlayer.java
+6
-0
6 additions, 0 deletions
src/main/java/hepia/HumanPlayer.java
src/main/java/hepia/IPlayer.java
+2
-0
2 additions, 0 deletions
src/main/java/hepia/IPlayer.java
with
18 additions
and
16 deletions
src/main/java/hepia/GameManager.java
+
10
−
16
View file @
6594a3b0
...
@@ -238,18 +238,6 @@ public class GameManager {
...
@@ -238,18 +238,6 @@ public class GameManager {
}
while
(
true
);
}
while
(
true
);
}
}
private
void
displayPlayerHand
(
IPlayer
player
)
{
System
.
out
.
println
();
if
(
player
instanceof
CroupierPlayer
)
{
System
.
out
.
println
(
"Croupier's hand is: "
+
((
CroupierPlayer
)
player
).
getHand
());
}
else
if
(
player
instanceof
HumanPlayer
)
{
System
.
out
.
println
(
"Your current hand is: "
+
((
HumanPlayer
)
player
).
getHand
());
}
else
if
(
player
instanceof
AIPlayer
)
{
System
.
out
.
println
(
"AI's hand is: "
+
((
AIPlayer
)
player
).
getHand
());
}
System
.
out
.
println
(
"Its value is: "
+
player
.
getHand
().
computeHandValue
());
}
public
GameManager
(
public
GameManager
(
Game
game
,
Game
game
,
int
nbHumanPlayers
,
int
nbHumanPlayers
,
...
@@ -332,7 +320,7 @@ public class GameManager {
...
@@ -332,7 +320,7 @@ public class GameManager {
System
.
out
.
println
(
"======= Player's n°"
+
(
i
+
1
)
+
" hand ======="
);
System
.
out
.
println
(
"======= Player's n°"
+
(
i
+
1
)
+
" hand ======="
);
while
(
turnContinues
)
{
while
(
turnContinues
)
{
player
.
setHand
(
player
.
getSplittedHand
().
get
(
i
));
player
.
setHand
(
player
.
getSplittedHand
().
get
(
i
));
displayPlayerHand
(
player
);
player
.
displayPlayerHand
();
turnContinues
=
drawCardOrStop
(
player
);
turnContinues
=
drawCardOrStop
(
player
);
...
@@ -349,7 +337,7 @@ public class GameManager {
...
@@ -349,7 +337,7 @@ public class GameManager {
}
else
{
}
else
{
askPlayerForDoubleBet
(
player
);
askPlayerForDoubleBet
(
player
);
while
(
turnContinues
)
{
while
(
turnContinues
)
{
displayPlayerHand
(
player
);
player
.
displayPlayerHand
();
turnContinues
=
drawCardOrStop
(
player
);
turnContinues
=
drawCardOrStop
(
player
);
...
@@ -364,11 +352,17 @@ public class GameManager {
...
@@ -364,11 +352,17 @@ public class GameManager {
}
}
}
}
for
(
AIPlayer
aiPlayer
:
this
.
aiPlayers
)
{
System
.
out
.
println
(
aiPlayer
);
aiPlayer
.
basicStrategy
(
this
.
currentGame
);
}
// Croupier's turn
// Croupier's turn
System
.
out
.
println
(
this
.
croupier
);
System
.
out
.
println
(
this
.
croupier
);
while
(
this
.
croupier
.
getHand
().
computeHandValue
()
<
17
)
{
while
(
this
.
croupier
.
getHand
().
computeHandValue
()
<
17
)
{
displayPlayerHand
(
this
.
croupier
);
this
.
croupier
.
displayPlayerHand
();
for
(
Card
card
:
this
.
croupier
.
getHand
())
{
for
(
Card
card
:
this
.
croupier
.
getHand
())
{
...
@@ -398,7 +392,7 @@ public class GameManager {
...
@@ -398,7 +392,7 @@ public class GameManager {
this
.
bustedPlayers
.
add
(
this
.
croupier
);
this
.
bustedPlayers
.
add
(
this
.
croupier
);
}
}
displayPlayerHand
(
this
.
croupier
);
this
.
croupier
.
displayPlayerHand
();
}
}
private
void
compareHandsAssignGainsLosses
(
IPlayer
player
)
{
private
void
compareHandsAssignGainsLosses
(
IPlayer
player
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/hepia/HumanPlayer.java
+
6
−
0
View file @
6594a3b0
...
@@ -125,4 +125,10 @@ public class HumanPlayer implements IPlayer {
...
@@ -125,4 +125,10 @@ public class HumanPlayer implements IPlayer {
return
str
;
return
str
;
}
}
@Override
public
void
displayPlayerHand
()
{
System
.
out
.
println
(
"Human's hand is: "
+
this
.
getHand
());
System
.
out
.
println
(
"Its value is: "
+
this
.
getHand
().
computeHandValue
());
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/hepia/IPlayer.java
+
2
−
0
View file @
6594a3b0
...
@@ -31,4 +31,6 @@ public interface IPlayer {
...
@@ -31,4 +31,6 @@ public interface IPlayer {
@Override
@Override
String
toString
();
String
toString
();
void
displayPlayerHand
();
}
}
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