Giter VIP home page Giter VIP logo

twohue's Introduction

About TwoHue

Twohue is a one-player color mixing game. Players are presented with a color sample that they must recreate using two transparent color swatches from a set of several swatches.

The front end twohue is created with React. The back end leaderboard server is created with Node/Express. See the repo for the server here: https://github.com/snphillips/twohue-leaderboard-server

I use the color library chroma.js to dynamically create unlimmited game rounds,

View deployed game here: http://twohue.surge.sh

How to Play

The player is presented with a brief introduction to the game and a "start" button.

The player is shown:

  • a circle containing the target color,
  • a set of smaller color swatches, two of which are the solution,
  • outlines of two overlapping large circles(like a Venn diagram).

The player selects the two colors they believe mix to create the target color. Points are assigned based on how few attempts the player solves the round in. Fewer tries = more points. The goal of the game is to win as many points as the player can before loosing six rounds.

Getting Started

note: the backend server for the leaderboard can be found here: https://github.com/snphillips/twohue-leaderboard-server

clone this repo:

git clone https://github.com/snphillips/twohue.git

get into the correct directory:

cd twohue

run npm to install all the dependencies:

npm install

start the server:

npm start

your browser should open to http://localhost:3000/ !

Made With

twohue's People

Contributors

snphillips avatar

Watchers

 avatar  avatar

twohue's Issues

"play again" button leads to issues during game over transition

If user clicks on "play again" button before the leaderboard displays, the game resets for a second, THEN the leaderboard displays (which hides the game). The button disappears too. Player is stuck.

Possible Solutions:

  • hide button during game over transition
  • skip the whole game over transition and go straight to leaderboard

Reconsider how you're using useEffect - refactor to use fewer of them

Many times in the app I am using useEffect as a 'subscription'. This ticket involves reconsidering all times I am using it, and finding other solutions.

  1. when round changes
  2. when attempt changes
  3. when lostRounds changes
  4. when gameState changes

"useEffect is best used for side-effects, but here you're using it as a sort of "subscription" concept, like: "do X when Y changes". That does sort of work functionally, due to the mechanics of the deps array, but it's not the intended purpose."
https://stackoverflow.com/questions/58866796/understanding-the-react-hooks-exhaustive-deps-lint-rule]

Further reading:
https://react.dev/learn/you-might-not-need-an-effect

How to remove unnecessary Effects
There are two common cases in which you don’t need Effects:

You don’t need Effects to transform data for rendering. For example, let’s say you want to filter a list before displaying it. You might feel tempted to write an Effect that updates a state variable when the list changes. However, this is inefficient. When you update the state, React will first call your component functions to calculate what should be on the screen. Then React will “commit” these changes to the DOM, updating the screen. Then React will run your Effects. If your Effect also immediately updates the state, this restarts the whole process from scratch! To avoid the unnecessary render passes, transform all the data at the top level of your components. That code will automatically re-run whenever your props or state change.
You don’t need Effects to handle user events. For example, let’s say you want to send an /api/buy POST request and show a notification when the user buys a product. In the Buy button click event handler, you know exactly what happened. By the time an Effect runs, you don’t know what the user did (for example, which button was clicked). This is why you’ll usually handle user events in the corresponding event handlers.

Add error handling to leaderboard POST (new inductee)

Nothing happens if user can't add a new inductee to the leaderboard. User just hammers away at submit button.
Come up with and implement a solution. This happens when Heroku is doing maintenance or when user tries to add name longer than 12 characters

To replicate:

  • play game get a high score
  • when presented with leaderboard, try to add name longer than 13 characters

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.