feature/MAPG-235-basic-challenge-mode #48
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/MAPG-235-basic-challenge-mode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -296,0 +382,4 @@
var roundContainer = document.getElementById('roundContainer');
var header = roundContainer.parentNode;
header.insertBefore(restrictions, roundContainer);
I had to create span from javascript, because I didn't know, how else to control the display css attribute from both css (depending on screen size) and javascript (depending on the game type). Javascript overrides the css attribute even for narrow screens. Is there a more elegant solution?
It could be solved with a hidden element, for example with class
hidden
which can be removed by JavaScript when it should be shown (it still can have classhideOnNarrowScreen
). But I think it is also a good solution.@ -32,0 +67,4 @@
</div>
<div>
<input type="checkbox" id="noZoom" name="noZoom" value="noZoom" />
<label for="noMove">No zoom allowed</label>
@ -13,1 +13,4 @@
<button id="multiButton" class="fullWidth green" data-map-id="">Multiplayer (beta)</button>
<?php if ($isLoggedIn): ?>
<p class="bold center marginTop marginBottom">OR</p>
<button id="challengeButton" class="fullWidth yellow" data-map-id="" data-timer="">Challenge (gamma)</button>
Gamma :D
@ -88,0 +112,4 @@
public function createNewChallenge(): IContent
{
// create Challenge
$challengeToken = rand();
Maybe a do..while would be better here because the token calculation should not be repeated.
My eye is twitching when variables are used outside of the scope of {}, but it's different in PHP, so it can be refactored.
@ -88,0 +115,4 @@
$challengeToken = rand();
while ($this->challengeRepository->getByToken($challengeToken)) {
// if a challenge with the same token already exists
$challengeToken = rand();
I think rand() should be called with explicit arguments, otherwise a number is returned between 0 and getrandmax() and getrandmax() is platform-dependent.
On the other hand maybe the token could be generated as the room ID for multiplayer. Then a fixed length string would be generated - I used bin2hex(random_bytes(3)) for room ID. I guess it was intentional to use integer indexes in the DB, it could be be more efficient but I already used string indexes for other purpose.
Good point. However I don't think it would cause any problems. I thought it would be better to use 4 byte length integers instead of 3 bytes for more possible ids, because challenges are normally not getting deleted.
I've read your comment again, and I see that bin2hex returns a string. Yes I thought it would perform better just to use an integer instead.
I can also see now, that on Windows the getrandmax() is only 32767, which is far too small. I am going to replace it with mt_rand() if that's fine for you.
@ -0,0 +57,4 @@
}
// validate token string
foreach (str_split($token_str) as $char) {
PHP's builtin ctype_xdigit could be used for that.
@ -1,10 +1,13 @@
'use strict';
This file should be refactored sometime because it is very spaghetti :D
I know, but I already put a lot of changes into this PR. I think we should refactor it in a separate story.
Yes, I meant later, it will be a bigger task.
@ -535,0 +713,4 @@
if (Game.timeoutEnd) {
var timeLeft = Math.ceil((Game.timeoutEnd - new Date()) / 1000);
data.append('timeLeft', timeLeft);
So actually users can cheat with this if they send a bigger number back :D
Users can even cheat, if they just reload the page, because that resets the timer, or just by pausing the script. That's a bigger issue. But because PHP doesn't support websockets and I didn't want to create a request every second to the server to update the time, it's still an open topic. That's why I think, we should discuss an appropiate solution in a future story for it. I think most people won't figure this out anyway.
I think Websocket is not really necessary for that, it could be implemented without "active" connection. For example we could store a timestamp for each guess and calculate the difference between the current timestamp and the timestamp of the last guess (or challange start). So when user refreshes the page the timer is not restarted (and guesses can be rejected if time is up). But it could be done later.
That's a good idea. I'll write it into the ticket.
@ -732,0 +963,4 @@
var summaryInfo = document.getElementById('summaryInfo');
if (highscores.length > 2) {
var table = document.getElementById('highscoresTable');
This highscore table could be implemented for multiplayer in the future.
Yes, that was my intention as well. I just couldn't find the time for implementing and properly testing it, and it's also isn't really part of this story.
@ -75,6 +75,31 @@ div.mapItem>div.buttonContainer {
grid-auto-flow: column;
}
#restrictions {
I think some of the rules should be handled on higher level, for example
font-family
in mapguesser.css line 34,margin-top
andmargin-bottom
could be handled by classesmarginTop
andmarginBottom
, etc.But it is fine for now because some rules would require refactoring (for example for inputs).