Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
briscola-con-vale
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
valeria.destasio@studenti.unimi.it
briscola-con-vale
Commits
eae3abe8
Commit
eae3abe8
authored
Nov 20, 2023
by
giovanni.novati@studenti.unimi.it
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/Player' into develop
parents
4b2af1cb
30e1936c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/it/unimi/di/sweng/briscola/Player.java
+14
-5
14 additions, 5 deletions
src/main/java/it/unimi/di/sweng/briscola/Player.java
src/test/java/it/unimi/di/sweng/briscola/PlayerTest.java
+43
-0
43 additions, 0 deletions
src/test/java/it/unimi/di/sweng/briscola/PlayerTest.java
with
57 additions
and
5 deletions
src/main/java/it/unimi/di/sweng/briscola/Player.java
+
14
−
5
View file @
eae3abe8
...
...
@@ -3,13 +3,11 @@ package it.unimi.di.sweng.briscola;
import
org.jetbrains.annotations.NotNull
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
Player
{
// TODO rendere la classe Comparable con altri Player confrontando i punteggi
// TODO rendere la classe Iterable sulle carte che ha in mano
public
class
Player
implements
Iterable
<
Card
>,
Comparable
<
Player
>
{
private
@NotNull
final
String
name
;
private
@NotNull
final
List
<
Card
>
cards
=
new
ArrayList
<>();
private
@NotNull
final
List
<
Card
>
personalDeck
=
new
ArrayList
<>();
...
...
@@ -82,4 +80,15 @@ public class Player {
public
void
shoutResult
()
{
System
.
out
.
printf
(
"Sono %s e ho vinto con %d punti%n"
,
getName
(),
getPoints
());
}
@NotNull
@Override
public
Iterator
<
Card
>
iterator
()
{
return
Collections
.
unmodifiableList
(
cards
).
iterator
();
}
@Override
public
int
compareTo
(
@NotNull
Player
player
)
{
return
getPoints
()
-
player
.
getPoints
();
}
}
This diff is collapsed.
Click to expand it.
src/test/java/it/unimi/di/sweng/briscola/PlayerTest.java
0 → 100644
+
43
−
0
View file @
eae3abe8
package
it.unimi.di.sweng.briscola
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mock
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
public
class
PlayerTest
{
@Test
void
iterablePlayerTest
(){
Player
pl1
=
new
Player
(
"Gio"
);
List
<
Card
>
cards
=
List
.
of
(
Card
.
get
(
Rank
.
ASSO
,
Suit
.
BASTONI
),
Card
.
get
(
Rank
.
ASSO
,
Suit
.
COPPE
),
Card
.
get
(
Rank
.
TRE
,
Suit
.
BASTONI
));
for
(
Card
card
:
cards
)
pl1
.
giveCard
(
card
);
Iterator
<
Card
>
it
=
pl1
.
iterator
();
for
(
Card
card
:
cards
)
assertThat
(
card
).
isEqualTo
(
it
.
next
());
}
@Test
void
comparePlayerTest
(){
Player
pl1
=
new
Player
(
"Gio"
);
Player
pl2
=
new
Player
(
"Vale"
);
pl1
.
addWonCardsToPersonalDeck
(
Card
.
get
(
Rank
.
TRE
,
Suit
.
BASTONI
),
Card
.
get
(
Rank
.
ASSO
,
Suit
.
DENARI
));
assertThat
(
pl1
.
compareTo
(
pl2
)).
isGreaterThan
(
0
);
pl2
.
addWonCardsToPersonalDeck
(
Card
.
get
(
Rank
.
ASSO
,
Suit
.
BASTONI
),
Card
.
get
(
Rank
.
ASSO
,
Suit
.
DENARI
));
assertThat
(
pl1
.
compareTo
(
pl2
)).
isLessThan
(
0
);
assertThat
(
pl2
.
compareTo
(
pl1
)).
isGreaterThan
(
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