Git Product home page Git Product logo

betting-game's Introduction

Betting Game

It is web app made with Golang server (no database) with websockets and rest API. Frontend is done in VueJs. Golang API serves the static files from frontend.
It is a betting game, where player inputs his name and chooses 2 numbers.
One number is drawn every 1s. Score is calculated and ranking between players is shown. Game lasts max 30 rounds.
It is a multiplayer game, and minimum 2 players are needes to start the game.
More info below.

Starting the game

  • 2 players are needed to start the game (1 browser tab one player)
  1. On the initial page click "Play"
  2. Then fill your name
  3. Click on 2 numbers of your choice (1 to 10)
  4. Click "Join"
  5. Open another tab/window of this link in your browser
  6. Repeat in this other tab the steps 1 to 4
  7. Game will start
  • When new players join in a running game they will only observe until next game starts, then they will join automatically.

Game Mechanics:

  • New random number generated every 1 second
  • Maximum 30 rounds
  • Ends if any player reaches exactly 21 points
  • 10 seconds of interval between games

Score:

  • Exact match
    • +5 points if there is exact match with one of the chosen number
  • Inside bounds
    • +5-(upper bound - lower bound); e.g.: 3 and 8 chosen, 7 is the round number, then 5-(8-3)=0
  • Out of bounds
    • -1 point; e.g.: 3 and 8 chosen, 9 is the round number

Winner criteria (in this order):

  • Points
  • Highest upper number chosen
  • Highest lower number chosen
  • Name ascending

Assumptions/Constraints:

  • Players cannot have the same name
  • Player names are saved in lowercase and cannot be edited
  • Players cannot leave the game
  • Numbers chosen cannot be changed
  • New browser tab, means new player (player saved on session storage)

Run project

Below are 2 options to run the project locally:

Option 1 (recommended):

Prerequisites

Running locally on Docker

It will build frontend and backend, generate a single docker image and run it on port 8888:

make run-docker
# Open in the browser: http://localhost:8888

Option 2:

Prerequisites

Running locally

# Run server locally on port 8787
make run-local

# Install Vue frontend dependencies and run it locally
make run-frontend
# Open in the browser: http://localhost:8080

Unit Tests

# It will run tests locally
make test

# or

# It will run the same tests on docker
make test-docker

Lint

# It will run linting on docker
make lint-docker

Environment variables

HOST
PORT
LOGGER_LEVEL

Deployment

The command below will build frontend Vue app for production(generate static files) and will build Go backend and generate the server binary. Afterwards it generates a small Alpine docker image that it is deployable

make image

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.