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
Compare revisions
54eac128714bbabb8c0f6b1fdd46d27a8b5863f9 to bb86681e267e1b90efefb5dbf2810febede2b01a
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
ost/we1/testat-rockpaperscissoirs
Select target project
No results found
bb86681e267e1b90efefb5dbf2810febede2b01a
Select Git revision
Branches
dev
master
online_gameplay
Swap
Target
ost/we1/testat-rockpaperscissoirs
Select target project
ost/we1/testat-rockpaperscissoirs
1 result
54eac128714bbabb8c0f6b1fdd46d27a8b5863f9
Select Git revision
Branches
dev
master
online_gameplay
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
main.js peer review fixups
· 7025cf0a
Andri Joos
authored
2 years ago
7025cf0a
html peer review fixups
· e825c0f8
Andri Joos
authored
2 years ago
e825c0f8
css peer review fixups
· bb86681e
Andri Joos
authored
2 years ago
bb86681e
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
+43
-24
43 additions, 24 deletions
TestatVorlage/scripts/main.js
TestatVorlage/styles/global.css
+17
-1
17 additions, 1 deletion
TestatVorlage/styles/global.css
with
62 additions
and
27 deletions
TestatVorlage/schere-stein-papier.html
View file @
bb86681e
...
...
@@ -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"
>
<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
View file @
bb86681e
...
...
@@ -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,7 +21,10 @@ 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
'
;
function
addToHistory
(
userHand
,
opponentHand
,
winText
)
{
historyTableBody
.
innerHTML
+=
`<tr><td>
${
winText
}
</td>\t<td>
${
userHand
}
</td>\t<td>
${
opponentHand
}
\n</td></tr>`
;
...
...
@@ -34,16 +32,15 @@ function addToHistory(userHand, opponentHand, winText) {
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
'
;
}
...
...
@@ -64,13 +61,19 @@ 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
);
}
evaluateHand
(
username
,
userHand
,
({
systemHand
,
...
...
@@ -78,24 +81,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 +143,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
View file @
bb86681e
.
options
{
#
options
{
display
:
flex
;
width
:
50vw
;
justify-content
:
space-evenly
;
...
...
@@ -44,3 +44,19 @@ td {
#game-table
{
margin
:
auto
;
}
.win-color
{
border-color
:
green
;
}
.lost-draw-color
{
border-color
:
black
;
}
.hidden
{
display
:
none
;
}
.visible
{
display
:
block
;
}
This diff is collapsed.
Click to expand it.