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
02f818e35562f63b55997602c20e779170b57378 to aa2fc6139bcdd90a987a97cbfc96013277d5c531
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
aa2fc6139bcdd90a987a97cbfc96013277d5c531
Select Git revision
Branches
dev
master
online_gameplay
Swap
Target
ost/we1/testat-rockpaperscissoirs
Select target project
ost/we1/testat-rockpaperscissoirs
1 result
02f818e35562f63b55997602c20e779170b57378
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)
fixup! button to change between online and local mode
· 37a5cf7c
Andri Joos
authored
2 years ago
37a5cf7c
css online mode
· 9d0335ae
Andri Joos
authored
2 years ago
9d0335ae
fixup! main.js online mode
· aa2fc613
Andri Joos
authored
2 years ago
aa2fc613
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TestatVorlage/schere-stein-papier.html
+7
-5
7 additions, 5 deletions
TestatVorlage/schere-stein-papier.html
TestatVorlage/scripts/main.js
+34
-7
34 additions, 7 deletions
TestatVorlage/scripts/main.js
TestatVorlage/styles/global.css
+10
-0
10 additions, 0 deletions
TestatVorlage/styles/global.css
with
51 additions
and
12 deletions
TestatVorlage/schere-stein-papier.html
View file @
aa2fc613
...
...
@@ -9,8 +9,8 @@
<body>
<h1>
Rock Paper Scissors Well Matchstick
</h1>
<
div
id=
"login"
>
<button
id=
"change-online-mode"
></button>
<
section
id=
"login"
>
<button
id=
"change-online-mode
-button"
class=
"mode-change-enabled
"
></button>
<form
id=
"login-form"
>
<label
for=
"username-input"
>
Username:
</label>
<input
id=
"username-input"
placeholder=
"Please enter an username"
>
...
...
@@ -28,9 +28,9 @@
</thead>
<tbody
id=
"ranking-table"
></tbody>
</table>
</
div
>
</
section
>
<
div
id=
"game"
>
<
section
id=
"game"
>
<label
id=
"username-display"
></label>
<div
id=
"options"
class=
"options-enabled"
>
<button
class=
"option"
id=
"rock"
>
Rock
</button>
...
...
@@ -40,6 +40,8 @@
<button
class=
"option"
id=
"matchstick"
>
Matchstick
</button>
</div>
<label
id=
"wait-label"
>
</label>
<table
id=
"game-table"
>
<tbody>
<tr><td
class=
"hand-row-entry"
><label
id=
"player-hand"
class=
"hand"
></label></td></tr>
...
...
@@ -61,7 +63,7 @@
</thead>
<tbody
id=
"history"
></tbody>
</table>
</
div
>
</
section
>
</body>
</html>
This diff is collapsed.
Click to expand it.
TestatVorlage/scripts/main.js
View file @
aa2fc613
...
...
@@ -8,8 +8,9 @@ const loginScreen = document.querySelector('#login');
const
gameScreen
=
document
.
querySelector
(
'
#game
'
);
const
options
=
document
.
querySelector
(
'
#options
'
);
const
waitLabel
=
document
.
querySelector
(
'
#wait-label
'
);
const
changeModeButton
=
document
.
querySelector
(
'
#change-online-mode
'
);
const
changeModeButton
=
document
.
querySelector
(
'
#change-online-mode
-button
'
);
const
loginForm
=
document
.
querySelector
(
'
#login-form
'
);
const
usernameInput
=
document
.
querySelector
(
'
#username-input
'
);
const
rankingTable
=
document
.
querySelector
(
'
#ranking-table
'
);
...
...
@@ -29,6 +30,8 @@ const visibleClass = 'visible';
const
hiddenClass
=
'
hidden
'
;
const
optionsDisabledClass
=
'
options-disabled
'
;
const
optionsEnabledClass
=
'
options-enabled
'
;
const
modeChangeDisabledClass
=
'
mode-change-disabled
'
;
const
modeChangeEnabledClass
=
'
mode-change-enabled
'
;
function
addToHistory
(
userHand
,
opponentHand
,
winText
)
{
historyTableBody
.
innerHTML
=
`<tr><td>
${
winText
}
</td>\t<td>
${
userHand
}
</td>\t<td>
${
opponentHand
}
\n</td></tr>
${
historyTableBody
.
innerHTML
}
`
;
...
...
@@ -51,7 +54,22 @@ function handleOpponentPicked(userHand, opponentHand, gameEval) {
addToHistory
(
userHand
,
opponentHand
,
winText
);
options
.
classList
.
replace
(
optionsDisabledClass
,
optionsEnabledClass
);
let
timeout
=
3
;
waitLabel
.
innerText
=
'
Next round starts in soon
'
;
const
countdown
=
setInterval
(()
=>
{
if
(
timeout
>
0
)
{
waitLabel
.
innerText
=
`Next round starts in
${
timeout
}
`
;
timeout
--
;
}
else
{
clearTimeout
(
countdown
);
waitLabel
.
innerText
=
'
\n
'
;
options
.
classList
.
replace
(
optionsDisabledClass
,
optionsEnabledClass
);
}
},
1000
);
}
function
sanitizePlayername
(
playerName
)
{
return
playerName
.
replaceAll
(
'
<
'
,
'
<
'
).
replaceAll
(
'
>
'
,
'
>
'
);
}
function
showRankings
(
rankings
)
{
...
...
@@ -59,16 +77,23 @@ function showRankings(rankings) {
for
(
const
ranking
of
rankings
)
{
rankingsHtml
+=
`<tr><td>
${
ranking
.
rank
}
</td><td>
${
ranking
.
wins
}
</td><td>`
;
for
(
let
i
=
0
;
i
<
ranking
.
players
.
length
-
1
;
i
++
)
{
rankingsHtml
+=
`
${
ranking
.
players
[
i
]}
, `
;
const
playerName
=
sanitizePlayername
(
ranking
.
players
[
i
]);
rankingsHtml
+=
`
${
playerName
}
, `
;
}
let
playerName
=
ranking
.
players
[
ranking
.
players
.
length
-
1
];
playerName
=
playerName
.
replace
(
/</g
,
'
<
'
).
replace
(
/>/g
,
'
>
'
);
const
playerName
=
sanitizePlayername
(
ranking
.
players
[
ranking
.
players
.
length
-
1
]);
rankingsHtml
+=
`
${
playerName
}
</td></tr>`
;
}
rankingTable
.
innerHTML
=
rankingsHtml
;
}
function
updateRankings
(
rankings
)
{
if
(
changeModeButton
.
classList
.
contains
(
modeChangeDisabledClass
))
{
changeModeButton
.
classList
.
replace
(
modeChangeDisabledClass
,
modeChangeEnabledClass
);
}
showRankings
(
rankings
);
}
function
onOptionClick
(
event
)
{
const
userHand
=
event
.
target
.
innerText
;
playerHandLabel
.
innerText
=
userHand
;
...
...
@@ -163,9 +188,11 @@ function updateOnlineButton() {
}
function
triggerOnlineState
()
{
changeModeButton
.
classList
.
replace
(
modeChangeEnabledClass
,
modeChangeDisabledClass
);
setConnected
(
!
isConnected
());
updateOnlineButton
();
getRankings
(
show
Rankings
);
getRankings
(
update
Rankings
);
}
options
.
addEventListener
(
'
click
'
,
(
event
)
=>
onOptionClick
(
event
));
...
...
@@ -174,5 +201,5 @@ mainMenuButton.addEventListener('click', onMainMenuClick);
changeModeButton
.
addEventListener
(
'
click
'
,
triggerOnlineState
);
window
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
setScreenVisible
(
false
));
window
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
getRankings
(
show
Rankings
));
window
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
getRankings
(
update
Rankings
));
window
.
addEventListener
(
'
DOMContentLoaded
'
,
updateOnlineButton
);
This diff is collapsed.
Click to expand it.
TestatVorlage/styles/global.css
View file @
aa2fc613
...
...
@@ -68,3 +68,13 @@ td {
.options-enabled
{
pointer-events
:
auto
;
}
.mode-change-enabled
{
pointer-events
:
auto
;
color
:
black
;
}
.mode-change-disabled
{
pointer-events
:
none
;
color
:
gray
;
}
This diff is collapsed.
Click to expand it.