Giter Site home page Giter Site logo

rock-paper-scrissor-game's Introduction

author title id
Dua Tran
Rock-Paper-Scissor game
rock_paper_scissor_game_trancaodua

Rock Paper Scissors Game

Props are one of the most basic and important properties in React. The purpose of this project is to practice our skills with React props.

You must have played the "Rock Paper Scissors Game" at least once. And now, we are making a Rock Paper Scissors Game together on the web.

Rock Paper Scrissor Game

Go to demo website !

User Story

  • User play "Rock Paper Scissors game" with a computer.
  • User select "Rock" or "Paper" or "Scissors" and game start.
  • User selection trigger computer selection
  • Computer's selection is random. Result is display immediately.

Requirement

Fork this repo and read through the files. Often time , developers are required to work with an existing codebase and improve upon. This is one of that time.

Repository has 2 branches:

  • requirement: Has requirements. You will code on this branch.
  • solution: Has solutions for requirements.

Guide checkout requirement branch to code:

  • Step 1: Clone this repository. Run: git clone https://github.com/trancaodua/rock-paper-scrissor-game.git
  • Step 2: Checkout requirement branch to start coding. Run: git checkout requirement

Guide checkout solution branch to see answers:

  • Step 1: Checkout solution branch. Run: git checkout solution.

You should only code in the designinated area. Using the VSC search function for "Your code here", you will see a list of all the places that requires your attention.

Explain code

  • src/utils/index.js
# input: gamesItems is a list of items.
# return: a random item in the list.
# Description: get random item from gamesItems list.
export const getRandomGameItem = (gamesItems) => {
  const index = Math.floor(Math.random() * gamesItems.length); //create index random between 0 to gamesItems.length - 1
  return gamesItems[index]; //return item
};
# input: user1GameItem, user2GameItem - is object game, contains game item id and list can win.
Object example:
user1GameItem = {
    url: "/images/paper.png",
    id: 0,
    winItemIds: [1],
    name: "Paper",
}
# return: game result.
# Description: calculator result player.
export const calculatorUserWinner = (user1GameItem, user2GameItem) => {
  if (user1GameItem.id === user2GameItem.id) {
    return "Peace"; //return both player same.
  } else if (user1GameItem.winItemIds.includes(user2GameItem.id)) {
    return "Win"; //if player 1 winItemIds list contain game player 2 id => player 1 win player 2.
  } else {
    return "Lost"; //if winItemIds list not contain game player 2 id => player 1 lost, player 2 .
  }
};

rock-paper-scrissor-game's People

Contributors

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