Giter Club home page Giter Club logo

timer-game's Introduction

Timer Game Project

This repository contains a Timer Game project built with React, demonstrating the use of advanced React concepts such as useRef, ref forwarding, useImperativeHandle, and portals. The project serves as a practical example of how to apply these concepts in a real-world application, specifically a timing-based game.

Game Description

The Timer Game challenges players to stop a timer as close to a specified time as possible. Players enter their name and choose from four difficulty levels:

  • Easy (1 second)
  • Not Easy (5 seconds)
  • Getting Tough (10 seconds)
  • Pros Only (15 seconds)

The closer the player stops the timer to the target time, the higher their score.

Key Concepts and Implementation

useRef Hook

  • Accessing DOM Elements: The useRef hook is used to directly interact with and manipulate DOM elements, such as the timer display. This allows for efficient and direct updates without triggering re-renders.

Ref Forwarding

  • Passing Refs to Child Components: Ref forwarding allows parent components to pass refs to their children, enabling direct manipulation of child components.

useImperativeHandle Hook

  • Exposing Custom APIs: The useImperativeHandle hook defines custom methods that parent components can call, providing a controlled API for interaction.

Portals

  • Rendering Outside the Main DOM Tree: React portals render components outside the main DOM hierarchy, useful for modals and overlays.

Features

  • Name Entry: Players can enter their name before starting the game.
  • Timer Levels: Four difficulty levels with different target times (1, 5, 10, and 15 seconds).
  • Scoring System: Players earn points based on how close they stop the timer to the target time.
  • Modal Display: Game results and scores are shown in a modal, rendered using React portals.
  • Keyboard Interaction: The modal can be closed via the ESC key for enhanced user experience.

Getting Started

To run this project locally, follow these steps:

  1. Clone the repository:

    git clone https://github.com/trishna456/timer-game.git
  2. Navigate to the project directory:

cd timer-game
  1. Install dependencies:

    npm install
  2. Start the development server:

    npm start

timer-game's People

Contributors

trishna456 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.