Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw-49
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chingiz
hw-49
Commits
531876c5
Commit
531876c5
authored
Mar 20, 2024
by
Chingiz
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Class Deck and RandomNumber func has been created
parent
781db860
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
Deck.ts
src/Modules/Deck.ts
+32
-0
RandomNumber.ts
src/Modules/RandomNumber.ts
+3
-0
No files found.
src/Modules/Deck.ts
0 → 100644
View file @
531876c5
import
{
Card
}
from
"./Card"
;
import
{
getRandomNumber
}
from
"./RandomNumber"
;
export
class
Deck
{
private
RANKS
:
string
[]
=
[
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"J"
,
"Q"
,
"K"
,
"A"
]
private
SUITS
:
string
[]
=
[
"♠"
,
"♥"
,
"♦"
,
"♣"
]
private
_cards
:
Card
[]
=
[];
private
tookedCardIndexes
:
number
[]
=
[];
constructor
()
{
for
(
let
i
=
0
;
i
<
this
.
SUITS
.
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
this
.
RANKS
.
length
;
j
++
)
{
this
.
_cards
.
push
(
new
Card
(
this
.
RANKS
[
j
],
this
.
SUITS
[
i
]))
}
}
}
shuffleDeck
()
{
for
(
let
i
=
this
.
_cards
.
length
-
1
;
i
>
0
;
i
--
)
{
const
j
=
Math
.
floor
(
Math
.
random
()
*
(
i
+
1
));
[
this
.
_cards
[
i
],
this
.
_cards
[
j
]]
=
[
this
.
_cards
[
j
],
this
.
_cards
[
i
]];
}
}
takeACard
(){
const
ranNum
:
number
=
getRandomNumber
(
0
,
this
.
_cards
.
length
+
1
);
if
(
!
this
.
tookedCardIndexes
.
includes
(
ranNum
)){
return
this
.
_cards
[
ranNum
];
this
.
tookedCardIndexes
.
push
(
ranNum
);
}
this
.
takeACard
();
}
}
\ No newline at end of file
src/Modules/RandomNumber.ts
0 → 100644
View file @
531876c5
export
function
getRandomNumber
(
min
:
number
,
max
:
number
)
{
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
))
+
min
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment