-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into refactor/#76-refactor-image-logo
- Loading branch information
Showing
10 changed files
with
138 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"edge": "17", | ||
"firefox": "60", | ||
"chrome": "67", | ||
"safari": "11.1" | ||
} | ||
} | ||
] | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"edge": "17", | ||
"firefox": "60", | ||
"chrome": "67", | ||
"safari": "11.1" | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import ef from '../utils/elementFactory'; | ||
import validateString from '../utils/validateString'; | ||
|
||
export default function gameMode(message) { | ||
function GameModeName(message) { | ||
const isAValidString = validateString(message); | ||
if (!isAValidString) { | ||
throw new Error('Not a valid string'); | ||
} | ||
|
||
const modeInfo = document.createElement('div'); | ||
const heading = document.createElement('h2'); | ||
const modeText = document.createElement('span'); | ||
const question = document.createElement('span'); | ||
const question = ef( | ||
'span', | ||
{ className: 'mode-info__question' }, | ||
message, | ||
); | ||
|
||
modeInfo.id = 'mode-info'; | ||
modeInfo.className = 'mode-info'; | ||
const modeText = ef( | ||
'span', | ||
{ className: 'mode-info__text' }, | ||
'mode: ', | ||
); | ||
|
||
heading.classList.add('mode-info__heading'); | ||
const heading = ef( | ||
'h2', | ||
{ className: 'mode-info__heading' }, | ||
modeText, | ||
question, | ||
); | ||
|
||
modeText.classList.add('mode-info__text'); | ||
modeText.innerText = 'mode: '; | ||
|
||
question.classList.add('mode-info__question'); | ||
question.innerText = message; | ||
|
||
heading.append(modeText, question); | ||
modeInfo.append(heading); | ||
const modeInfo = ef('div', { className: 'mode-info' }, heading); | ||
|
||
return modeInfo; | ||
} | ||
|
||
export default GameModeName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function handleTimeChange(element) { | ||
let timer = process.env.QUIZ_MAX_TIME_SECONDS; | ||
|
||
const idInterval = setInterval(() => { | ||
timer--; | ||
|
||
const min = Math.floor(timer / 60); | ||
const sec = timer % 60; | ||
let minToDisplay = min; | ||
let secToDisplay = sec; | ||
|
||
if (timer === 0) { | ||
clearInterval(idInterval); | ||
} | ||
|
||
if (min < 10) { | ||
minToDisplay = '0' + minToDisplay; | ||
} | ||
|
||
if (sec < 10) { | ||
secToDisplay = '0' + secToDisplay; | ||
} | ||
|
||
element.textContent = `Time Left: ${minToDisplay}m ${secToDisplay}s`; | ||
}, 1000); | ||
} | ||
|
||
function RemainingTime() { | ||
const parentElement = document.createElement('div'); | ||
const counter = document.createElement('div'); | ||
|
||
parentElement.classList.add('remaining-time'); | ||
counter.textContent = 'Time Left : 02 m 00 s'; | ||
counter.classList.add('remaining-time__counter'); | ||
|
||
parentElement.appendChild(counter); | ||
|
||
handleTimeChange(counter); | ||
|
||
return parentElement; | ||
} | ||
|
||
export default RemainingTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import getRandomInt from '../utils/getRandomInt'; | ||
import { Player } from './Player'; | ||
import isAnswerCorrect from './isAnswerCorrect'; | ||
|
||
export const ComputerPlayer = () => { | ||
const player = { | ||
askQuestion(question, callback) { | ||
if (!question) throw new Error('There is no question'); | ||
callback(question); | ||
}, | ||
class ComputerPlayer extends Player { | ||
getAnswer(answers, correctAnswer, callback) { | ||
if (answers.length === 0 || !correctAnswer) { | ||
throw new Error('There is no answers or correctAnswer'); | ||
} | ||
const randomAnswer = answers[getRandomInt(0, 3)]; | ||
if (isAnswerCorrect(randomAnswer, correctAnswer)) { | ||
this.correctAnswersCounter += 1; | ||
} | ||
this.allAnswers.push(randomAnswer); | ||
if (typeof callback === 'function') callback(randomAnswer); | ||
} | ||
} | ||
|
||
getAnswer(answers, callback) { | ||
if (!answers) throw new Error('There is no answers'); | ||
callback(answers[getRandomInt(0, 3)]); | ||
}, | ||
}; | ||
return player; | ||
}; | ||
function createComputerPlayer() { | ||
return new ComputerPlayer(); | ||
} | ||
|
||
export default ComputerPlayer; | ||
export default createComputerPlayer; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export class Player { | ||
constructor() { | ||
this.allAnswers = []; | ||
this.correctAnswersCounter = 0; | ||
} | ||
|
||
getModalData() { | ||
return { | ||
score: this.correctAnswersCounter, | ||
answers: this.allAnswers, | ||
}; | ||
} | ||
|
||
getAnswer(answer, isCorrect, callback) { | ||
if (!answer) throw new Error('There is no answer'); | ||
if (isCorrect) this.correctAnswersCounter += 1; | ||
this.allAnswers.push(answer); | ||
if (typeof callback === 'function') callback(answer); | ||
} | ||
} | ||
|
||
function createPlayer() { | ||
return new Player(); | ||
} | ||
|
||
export default createPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.remaining-time { | ||
justify-content: center; | ||
align-items: center; | ||
display: flex; | ||
|
||
&__counter { | ||
color: rgba(255, 0, 0, 0.8); | ||
text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25), | ||
4px 4px 40px rgba(255, 0, 0, 0.9); | ||
font-size: $font-size-primary; | ||
font-weight: bold; | ||
} | ||
} |