Giter Site home page Giter Site logo

rock-paper-scissors's Introduction

Rock Paper Scissors Game (React)

A simple Rock Paper Scissors Game, with easily extendable game modes.

View Demo

Main Stack

  • React
  • Vite
  • Typescript
  • TailwindCSS
  • Jest

Browser Support

Latest stable versions of Chrome, Firefox, Edge, and Safari. Mobile and Desktop.

Description

Game Logic

The game logic is seperated from the UI Layer into the useGame hook. The Game is basically seperated into 5 stages.

Stages

  1. config Choose a config via setConfig
  2. player1Picking Player 1 chooses an action via pickAction
  3. player2Picking Player 2 chooses an action via pickAction
  4. showdown Wait until winner is determined via determineWinner
  5. reveal Reveal Winner and save game to history

resetGame puts you back at stage 2 resetConfig puts you back at stage 1

Game Configurations

All Configurations are in the config folder.

actionSets

The different actions a player can take, and which action beats which, are defined here. These can be easily extended beyond Rock, Paper and Scissors (see lizardSpockExtension).

players

The different kinds of Players and how they pick an action are defined here.

computer picks it by random.

human gets prompted the HumanPickingStage and picks from there.

A possible extension might be a smart ai with strategies or even an online human opponent.

Getting Started

Dependencies

In the project directory, you can run:

npm run dev

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

npm run test

Runs the Jest tests.

npm run build

Tests and builds for production, outputs by default to the dist folder.

npm run preview

After you have built the app, you can locally preview the production build with this command.

Things to optimize

  • add more tests (this is my first time trying out Jest)
  • save actions in the game history only by reference, right now a lot of unnecessary, duplicate data gets saved in local history
  • make useGame more robust, if the triggers for the next stages get called out of order, it will probably cause bugs
  • make the game more "playful" (animations, sounds, etc.)
  • add a tutorial
  • add a full viewable history

License

This project is licensed under the MIT License - see the LICENSE.md file for details

rock-paper-scissors's People

Contributors

ixam1 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.