JSFiddle - React, Tailwind, and code Playground

by coryphoenixxx

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
    <title>Aim Training | Проект 5</title>
</head>
    <body>
    <div class="screen">
        <h1>Aim Training</h1>
        <a href="#" class="start" id="start">Начать игру</a>
    </div>

    <div class="screen">
        <h1>Выберите время</h1>
        <ul class="time-list" id="time-list">
            <li>
                <button class="time-btn" data-time="10">
                    10 сек
                </button>
            </li>
            <li>
                <button class="time-btn" data-time="20">
                    20 сек
                </button>
            </li>
            <li>
                <button class="time-btn" data-time="30">
                    30 сек
                </button>
            </li>
            <li>
                <button class="time-btn" data-time="40">
                    40 сек
                </button>
            </li>
        </ul>
    </div>

    <div class="screen">
        <h3>Осталось <span id="time">00:00</span></h3>
        <div class="board" id="board"></div>
    </div>


    <script src="script.js"></script>
    </body>
</html>

CSS

@import url('https://fonts.googleapis.com/css?family=Khula&display=swap');

* {
    box-sizing: border-box;
}

body {
    color: #fff;
    font-family: 'Khula', sans-serif;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    text-align: center;
}

a {
    color: #fff;
    text-decoration: none;
}

a:hover {
    color: #16D9E3;
}

.start {
    font-size: 1.5rem;
}

h1 {
    line-height: 1.4;
    font-size: 4rem;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    transition: margin 0.5s ease-out;
    background: linear-gradient(90deg, #29323C 0%, #485563 100%);
}

.screen.up {
    margin-top: -100vh;
}

.time-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    list-style: none;
    padding: 0;
}

.time-list li {
    margin: 10px;
}

.time-btn {
    background-color: transparent;
    border: 2px solid #C0C0C0;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
    padding: .5rem 1rem;
    font-size: 1.5rem;
}

.time-btn:hover {
    border: 2px solid #16D9E3;
    color: #16D9E3;
}

.hide {
    opacity: 0;
}

.primary {
    color: #16D9E3;
}

.board {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 500px;
    height: 500px;
    background: linear-gradient(118.38deg, #29323C -4.6%, #485563 200.44%);
    box-shadow: -8px -8px 20px #2A333D, 10px 7px 20px #475462;
    border-radius: 30px;
    overflow: hidden;
}

.circle {
    background: linear-gradient(90deg, #16D9E3 0%, #30C7EC 47%, #46AEF7 100%);
    position: absolute;
    border-radius: 50%;
    cursor: pointer;
}

JavaScript

const startBtn = document.querySelector('#start')
const screens = document.querySelectorAll('.screen')
const timeList = document.querySelector('#time-list')
const timeEl = document.querySelector('#time')
const board = document.querySelector('#board')

let time = 0
let score = 0

startBtn.addEventListener('click', (event) => {
    event.preventDefault()
    screens[0].classList.add('up')
})

timeList.addEventListener('click', (event) => {
    if (event.target.classList.contains('time-btn')) {
        time = parseInt(event.target.getAttribute('data-time'))
        screens[1].classList.add('up')
        startGame()
    }
})

board.addEventListener('click', (event) => {
    if (event.target.classList.contains('circle')) {
        score++
        event.target.remove()
        createRandomCircle()
    }
})


function startGame() {
    setInterval(decreaseTime, 1000)
    createRandomCircle()
    setTime(time)
}

function decreaseTime() {
    if (time === 0) {
        finishGame()
    } else {
        let current = --time
        if (current < 10) { current = `0${current}` }
        setTime(current)
    }
}

function setTime(value) {
    timeEl.innerHTML = `00:${value}`
}

function finishGame() {
    timeEl.parentNode.classList.add('hide')
    board.innerHTML = `<h1>Ваш счет: <span class="primary">${score}</span></h1>`
}

function createRandomCircle() {
    const circle = document.createElement('div')
    const size = getRandomNumber(10, 60)
    const {width, height} = board.getBoundingClientRect()
    const x = getRandomNumber(size, width - size)
    const y = getRandomNumber(size, height - size)
    const color = getRandomColor()

    circle.classList.add('circle')
    circle.style.background = color
    circle.style.width = `${size}px`
    circle.style.height = `${size}px`
    circle.style.top = `${y}px`
    circle.style.left = `${x}px`
    board.append(circle)
}

function getRandomNumber(min, max) {
    return Math.round(Math.random() * (max-min) + min)
}

function...