Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Testat RockPaperScissoirs
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OST
WE1
Testat RockPaperScissoirs
Commits
892e085b
Commit
892e085b
authored
2 years ago
by
Andri Joos
😊
Browse files
Options
Downloads
Plain Diff
Merge branch 'local_gameplay' into dev
parents
bbd9a9ce
3d545249
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TestatVorlage/schere-stein-papier.html
+2
-2
2 additions, 2 deletions
TestatVorlage/schere-stein-papier.html
TestatVorlage/scripts/main.js
+51
-25
51 additions, 25 deletions
TestatVorlage/scripts/main.js
TestatVorlage/styles/global.css
+25
-1
25 additions, 1 deletion
TestatVorlage/styles/global.css
with
78 additions
and
28 deletions
TestatVorlage/schere-stein-papier.html
+
2
−
2
View file @
892e085b
...
...
@@ -11,7 +11,7 @@
<div
id=
"login"
>
<form
id=
"login-form"
>
<label
for=
"username"
>
Username:
</label>
<label
for=
"username
-input
"
>
Username:
</label>
<input
id=
"username-input"
placeholder=
"Please enter an username"
>
<button
type=
"submit"
>
Let's Go!
</button>
</form>
...
...
@@ -31,7 +31,7 @@
<div
id=
"game"
>
<label
id=
"username-display"
></label>
<div
class=
"options"
>
<div
id=
"options"
class=
"options
-enabled
"
>
<button
class=
"option"
id=
"rock"
>
Rock
</button>
<button
class=
"option"
id=
"paper"
>
Paper
</button>
<button
class=
"option"
id=
"scissors"
>
Scissors
</button>
...
...
This diff is collapsed.
Click to expand it.
TestatVorlage/scripts/main.js
+
51
−
25
View file @
892e085b
...
...
@@ -7,12 +7,7 @@ import {getRankings, evaluateHand, createUserIfNotExists} from './game-service.j
const
loginScreen
=
document
.
querySelector
(
'
#login
'
);
const
gameScreen
=
document
.
querySelector
(
'
#game
'
);
const
rockButton
=
document
.
querySelector
(
'
#rock
'
);
const
paperButton
=
document
.
querySelector
(
'
#paper
'
);
const
scissorsButton
=
document
.
querySelector
(
'
#scissors
'
);
const
wellButton
=
document
.
querySelector
(
'
#well
'
);
const
matchstickButton
=
document
.
querySelector
(
'
#matchstick
'
);
const
optionsButtons
=
[
rockButton
,
paperButton
,
scissorsButton
,
wellButton
,
matchstickButton
];
const
options
=
document
.
querySelector
(
'
#options
'
);
const
loginForm
=
document
.
querySelector
(
'
#login-form
'
);
const
usernameInput
=
document
.
querySelector
(
'
#username-input
'
);
...
...
@@ -26,29 +21,36 @@ const historyTableBody = document.querySelector('#history');
const
usernameDisplay
=
document
.
querySelector
(
'
#username-display
'
);
let
username
=
''
;
const
notWonColor
=
'
black
'
;
const
notWonClass
=
'
lost-draw-color
'
;
const
wonClass
=
'
win-color
'
;
const
visibleClass
=
'
visible
'
;
const
hiddenClass
=
'
hidden
'
;
const
optionsDisabledClass
=
'
options-disabled
'
;
const
optionsEnabledClass
=
'
options-enabled
'
;
function
addToHistory
(
userHand
,
opponentHand
,
winText
)
{
historyTableBody
.
innerHTML
+
=
`<tr><td>
${
winText
}
</td>\t<td>
${
userHand
}
</td>\t<td>
${
opponentHand
}
\n</td></tr>`
;
historyTableBody
.
innerHTML
=
`<tr><td>
${
winText
}
</td>\t<td>
${
userHand
}
</td>\t<td>
${
opponentHand
}
\n</td></tr>
${
historyTableBody
.
innerHTML
}
`
;
}
function
handleOpponentPicked
(
userHand
,
opponentHand
,
gameEval
)
{
opponentHandLabel
.
innerText
=
opponentHand
;
const
winColor
=
'
green
'
;
let
winText
;
// eslint-disable-next-line @web-and-design/wed/use-action-map
if
(
gameEval
<
0
)
{
winText
=
'
Lost
'
;
opponentHandLabel
.
style
.
borderColor
=
w
i
nC
olor
;
opponentHandLabel
.
classList
.
replace
(
notWonClass
,
w
o
nC
lass
)
;
}
else
if
(
gameEval
>
0
)
{
winText
=
'
Won
'
;
playerHandLabel
.
style
.
borderColor
=
w
i
nC
olor
;
playerHandLabel
.
classList
.
replace
(
notWonClass
,
w
o
nC
lass
)
;
}
else
{
winText
=
'
Draw
'
;
}
addToHistory
(
userHand
,
opponentHand
,
winText
);
options
.
classList
.
replace
(
optionsDisabledClass
,
optionsEnabledClass
);
}
function
showRankings
(
rankings
)
{
...
...
@@ -64,13 +66,21 @@ function showRankings(rankings) {
rankingTable
.
innerHTML
=
rankingsHtml
;
}
function
onOptionClick
()
{
const
userHand
=
this
.
innerText
;
function
onOptionClick
(
event
)
{
const
userHand
=
event
.
target
.
innerText
;
playerHandLabel
.
innerText
=
userHand
;
opponentHandLabel
.
innerText
=
'
\n
'
;
playerHandLabel
.
style
.
borderColor
=
notWonColor
;
opponentHandLabel
.
style
.
borderColor
=
notWonColor
;
// eslint-disable-next-line @web-and-design/wed/use-action-map
if
(
playerHandLabel
.
classList
.
contains
(
wonClass
))
{
playerHandLabel
.
classList
.
replace
(
wonClass
,
notWonClass
);
}
if
(
opponentHandLabel
.
classList
.
contains
(
wonClass
))
{
opponentHandLabel
.
classList
.
replace
(
wonClass
,
notWonClass
);
}
options
.
classList
.
replace
(
optionsEnabledClass
,
optionsDisabledClass
);
evaluateHand
(
username
,
userHand
,
({
systemHand
,
...
...
@@ -78,24 +88,40 @@ function onOptionClick() {
})
=>
handleOpponentPicked
(
userHand
,
systemHand
,
gameEval
));
}
// used to switch between login screen and game screen
function
setScreenVisible
(
enablePlayScreen
)
{
const
hidden
=
'
none
'
;
const
visible
=
'
block
'
;
if
(
enablePlayScreen
)
{
loginScreen
.
style
.
display
=
hidden
;
gameScreen
.
style
.
display
=
visible
;
// eslint-disable-next-line @web-and-design/wed/use-action-map
if
(
loginScreen
.
classList
.
contains
(
visibleClass
))
{
loginScreen
.
classList
.
remove
(
visibleClass
);
}
if
(
gameScreen
.
classList
.
contains
(
hiddenClass
))
{
gameScreen
.
classList
.
remove
(
hiddenClass
);
}
loginScreen
.
classList
.
add
(
hiddenClass
);
gameScreen
.
classList
.
add
(
visibleClass
);
}
else
{
gameScreen
.
style
.
display
=
hidden
;
loginScreen
.
style
.
display
=
visible
;
// eslint-disable-next-line @web-and-design/wed/use-action-map
if
(
loginScreen
.
classList
.
contains
(
hiddenClass
))
{
loginScreen
.
classList
.
remove
(
hiddenClass
);
}
if
(
gameScreen
.
classList
.
contains
(
visibleClass
))
{
gameScreen
.
classList
.
remove
(
visibleClass
);
}
loginScreen
.
classList
.
add
(
visibleClass
);
gameScreen
.
classList
.
add
(
hiddenClass
);
}
}
function
resetGameScreen
()
{
historyTableBody
.
innerText
=
''
;
playerHandLabel
.
style
.
borderColor
=
notWonC
olor
;
opponentHandLabel
.
style
.
borderColor
=
notWonC
olor
;
playerHandLabel
.
classList
.
add
(
notWonC
lass
)
;
opponentHandLabel
.
classList
.
add
(
notWonC
lass
)
;
playerHandLabel
.
innerText
=
''
;
opponentHandLabel
.
innerText
=
''
;
...
...
@@ -124,7 +150,7 @@ function onMainMenuClick() {
getRankings
(
showRankings
);
}
options
Buttons
.
forEach
((
button
)
=>
button
.
addEventListener
(
'
click
'
,
onOptionClick
));
options
.
addEventListener
(
'
click
'
,
(
event
)
=>
onOptionClick
(
event
));
loginForm
.
addEventListener
(
'
submit
'
,
onLoginClick
);
mainMenuButton
.
addEventListener
(
'
click
'
,
onMainMenuClick
);
...
...
This diff is collapsed.
Click to expand it.
TestatVorlage/styles/global.css
+
25
−
1
View file @
892e085b
.
options
{
#
options
{
display
:
flex
;
width
:
50vw
;
justify-content
:
space-evenly
;
...
...
@@ -44,3 +44,27 @@ td {
#game-table
{
margin
:
auto
;
}
.win-color
{
border-color
:
green
;
}
.lost-draw-color
{
border-color
:
black
;
}
.hidden
{
display
:
none
;
}
.visible
{
display
:
block
;
}
.options-disabled
{
pointer-events
:
none
;
}
.options-enabled
{
pointer-events
:
auto
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
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