Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ICT100_Tutorials_T3_2022
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
Jonathan Vitale
ICT100_Tutorials_T3_2022
Commits
2bebaeb5
Commit
2bebaeb5
authored
2 years ago
by
Jonathan Vitale
Browse files
Options
Downloads
Patches
Plain Diff
Add code for tutorial 3
parent
d2d7823f
No related branches found
Branches containing commit
Tags
tutorial-3
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game-logic.js
+18
-1
18 additions, 1 deletion
game-logic.js
with
18 additions
and
1 deletion
game-logic.js
+
18
−
1
View file @
2bebaeb5
const
gameState
=
{
const
gameState
=
{
playerWallet
:
100
,
playerWallet
:
100
,
currentBet
:
null
currentBet
:
null
,
cards
:
[[],
[]]
}
}
function
collectBet
(){
function
collectBet
(){
...
@@ -22,10 +23,26 @@ function collectBet(){
...
@@ -22,10 +23,26 @@ function collectBet(){
return
currentBet
;
return
currentBet
;
}
}
function
drawCard
(){
let
min
=
2
;
let
max
=
11
;
let
rndNum
=
min
+
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
));
return
rndNum
;
}
function
blackjack
(){
function
blackjack
(){
// decide the bet, collect it
// decide the bet, collect it
gameState
.
currentBet
=
collectBet
();
gameState
.
currentBet
=
collectBet
();
for
(
let
playerIndex
=
0
;
playerIndex
<
gameState
.
cards
.
length
;
playerIndex
++
){
for
(
let
cardIndex
=
0
;
cardIndex
<
2
;
cardIndex
++
){
gameState
.
cards
[
playerIndex
][
cardIndex
]
=
drawCard
();
}
}
console
.
log
(
gameState
.
cards
);
// we deal the first 2 cards for the player
// we deal the first 2 cards for the player
// check immediately that the player has blackjack
// check immediately that the player has blackjack
// if so, we need to pay 2.5 the bet -> end the game
// if so, we need to pay 2.5 the bet -> end the game
...
...
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