Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CardGame
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Edvard Berdal Eek
CardGame
Merge requests
!4
Fix filpath in PlayingCard and implement code in DeckOfCards
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix filpath in PlayingCard and implement code in DeckOfCards
feat/model
into
dev
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Edvard Berdal Eek
requested to merge
feat/model
into
dev
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
dev
dev (base)
and
latest version
latest version
0fe36672
1 commit,
1 year ago
2 files
+
31
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/main/java/no/ntnu/idatt2002/a4/cardgame/model/DeckOfCards.java
+
30
−
1
Options
package
no.ntnu.idatt2002.a4.cardgame.model
;
import
java.util.
HashMap
;
import
java.util.
*
;
public
class
DeckOfCards
{
private
HashMap
<
Integer
,
PlayingCard
>
deck
;
private
final
char
[]
suits
=
{
'H'
,
'D'
,
'S'
,
'C'
};
public
DeckOfCards
()
{
deck
=
new
HashMap
<>();
int
iteration
=
0
;
for
(
char
suit
:
suits
)
{
for
(
int
i
=
1
;
i
<
14
;
i
++)
{
iteration
++;
deck
.
put
(
iteration
,
new
PlayingCard
(
suit
,
i
));
}
}
}
public
HashMap
<
Integer
,
PlayingCard
>
getDeck
()
{
return
deck
;
}
public
List
<
PlayingCard
>
dealHand
(
int
numberOfCards
)
{
Random
random
=
new
Random
();
List
<
PlayingCard
>
hand
=
new
ArrayList
<>(
numberOfCards
);
HashSet
<
Integer
>
dealtKeys
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
numberOfCards
;
i
++)
{
int
randomKey
=
random
.
nextInt
(
this
.
deck
.
size
());
while
(
dealtKeys
.
contains
(
randomKey
))
{
randomKey
=
random
.
nextInt
(
this
.
deck
.
size
());
}
hand
.
add
(
deck
.
get
(
randomKey
));
dealtKeys
.
add
(
randomKey
);
}
return
hand
;
}
}
Loading