Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Learning JavaScript
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
MohammadAli Keshavarz
Learning JavaScript
Commits
c5c021b2
Commit
c5c021b2
authored
Oct 28, 2019
by
MohammadAli Keshavarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create function for change player
parent
b519acd5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
30 deletions
+24
-30
app.js
section3/app.js
+24
-30
No files found.
section3/app.js
View file @
c5c021b2
...
@@ -29,6 +29,23 @@ document.getElementById("current-1").textContent = "0";
...
@@ -29,6 +29,23 @@ document.getElementById("current-1").textContent = "0";
document
.
getElementById
(
"score-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-1"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-1"
).
textContent
=
"0"
;
function
changePlayer
()
{
roundScore
=
0
;
if
(
activePlayer
===
0
)
{
activePlayer
=
1
;
document
.
querySelector
(
"#current-0"
).
textContent
=
0
;
}
else
{
activePlayer
=
0
;
document
.
querySelector
(
"#current-1"
).
textContent
=
0
;
}
// make dice invisible
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
//change active theme
document
.
querySelector
(
".player-0-panel"
).
classList
.
toggle
(
"active"
);
document
.
querySelector
(
".player-1-panel"
).
classList
.
toggle
(
"active"
);
}
// add functionality for roll btn
// add functionality for roll btn
document
.
querySelector
(
".btn-roll"
).
addEventListener
(
"click"
,
function
()
{
document
.
querySelector
(
".btn-roll"
).
addEventListener
(
"click"
,
function
()
{
//create random number
//create random number
...
@@ -41,22 +58,7 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
...
@@ -41,22 +58,7 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
if
(
dice
!==
1
)
{
if
(
dice
!==
1
)
{
roundScore
+=
dice
;
roundScore
+=
dice
;
}
else
{
}
else
{
roundScore
=
0
;
changePlayer
();
if
(
activePlayer
===
0
)
{
activePlayer
=
1
;
document
.
querySelector
(
"#current-0"
).
textContent
=
0
;
}
else
{
activePlayer
=
0
;
document
.
querySelector
(
"#current-1"
).
textContent
=
0
;
}
// make dice invisible
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
//change active theme
document
.
querySelector
(
".player-0-panel"
).
classList
.
toggle
(
"active"
);
document
.
querySelector
(
".player-1-panel"
).
classList
.
toggle
(
"active"
);
}
}
// change current score in user inteface
// change current score in user inteface
document
.
querySelector
(
"#current-"
+
activePlayer
).
textContent
=
roundScore
;
document
.
querySelector
(
"#current-"
+
activePlayer
).
textContent
=
roundScore
;
...
@@ -64,22 +66,14 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
...
@@ -64,22 +66,14 @@ document.querySelector(".btn-roll").addEventListener("click", function() {
// add functionality for hold btn
// add functionality for hold btn
document
.
querySelector
(
".btn-hold"
).
addEventListener
(
"click"
,
function
()
{
document
.
querySelector
(
".btn-hold"
).
addEventListener
(
"click"
,
function
()
{
//update score
scores
[
activePlayer
]
+=
roundScore
;
scores
[
activePlayer
]
+=
roundScore
;
//change score in user interface
document
.
getElementById
(
"score-"
+
activePlayer
).
textContent
=
document
.
getElementById
(
"score-"
+
activePlayer
).
textContent
=
scores
[
activePlayer
];
scores
[
activePlayer
];
roundScore
=
0
;
//change player
if
(
activePlayer
===
0
)
{
changePlayer
();
activePlayer
=
1
;
document
.
querySelector
(
"#current-0"
).
textContent
=
0
;
}
else
{
activePlayer
=
0
;
document
.
querySelector
(
"#current-1"
).
textContent
=
0
;
}
// make dice invisible
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
//change active theme
document
.
querySelector
(
".player-0-panel"
).
classList
.
toggle
(
"active"
);
document
.
querySelector
(
".player-1-panel"
).
classList
.
toggle
(
"active"
);
});
});
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