GithubHelp home page GithubHelp logo

lotto-game's Introduction

Italian lotto game

This is a software to simulate the Italian lotto game.

How to play

Once the game start the user is able to choose how many bills (ticket) he want to play, with the maximum amount of 5. For each bills he will choose the quantity of numbers to play, the type of bet he want to do with those numbers, the bet on the selected type and at the end select the cities rappresenting the wheels. The numbers the user is playing are choosen randomly.

Useful links

Requirement & installation process

  • Node JS, if you do not have it, install from this link: https://nodejs.org/en/download/current/
  • Download the game from Github > green button in the respository of the game, "Download ZIP"
  • From the terminal npm install, this will install all the dependencies of the project presents in the package.json
  • Now you can start to play: from the root folder, terminal npm start

Repository Structure

image

bill.js

In this file, there is the class to create the the user bill, in particular you find the follow:

  • constructor
    • id
    • numbers
    • type/s and bet/s
    • city/s
    • total bet
  • methods
    • select numbers (static)
    • select type/s and bet/s (static)
    • select city/s (static)
    • calculate the total bet
    • print bill
    • check win of the bill
    • print bill result (win or loose)

business-logic

This file is in the utils folder and includes all the most relevant logics of the game.

  • function play to be able to restart the game.
  • function billsGenerator to create the bill of the user that contain:
    • function howManyBills to be able to input the number of bills the user want to play. The user is able to choose a number between 0-5, if the the input is 0 the game stop.
    • function initilizeBills to be able to inizialize the object with the class bill and user input.
  • function lottoExtraction create a random extraction for all the cities of the game. Every city has 5 numbers between 1 and 90.
  • function checkWintBill to check all the bills initialized and output the object from the class method, comparing with the lotto extraction

prints

This file includes the function to print in a formatted way all the bills generated with the lotto extraction and the results.

  • function printBills to be able to print all the bills played in a presentable output.
  • function printLottoExtraction to print the extraction in a presentable output.
  • function printResultBills to print all the bills user result in a presentable output.

functionals

This file includes some function that simplify the business logic code

  • function currencyToNumber to be able to transform a formatted number (string) to a number.
  • function numberToCurrency is the opposite of the above function and give a formatted string as an output (with โ‚ฌ).
  • function nChooeK to be able to have the number of combination of an array with n element and k element together.
  • function calculateNetPrize to be able to calculate the net prize of a bill considerting the lotto rules.

global-variable

This file present the variable that are fixed with the ruels of the game

  • cities
  • types
  • prizes

index

This is the file to play the game! let's start!

Example of game

npm start

? Please enter the number of Bills you want to play (1-5, 0 to exit)

user choose 2

? Please enter the number of Bills you want to play (1-5, 0 to exit) 2

You are selecting data for Bill number 1
? Please enter the quanty of numbers to play (1-10)

user choose 10

? Please enter the quanty of numbers to play (1-10) 10
? Please select types: (Use arrow keys)
> Ambata
  Ambo
  Terno
  Quaterna
  Cinquina

User press on "Ambata"

? Please select types: Ambata
? Please bet on the selected type:

User choose 10

? Please bet on the selected type: 10
? Do you want to add another type? (Y/n)

User chooe No

? Please select cities: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
>( ) Bari
 ( ) Cagliari
 ( ) Firenze
 ( ) Genova
 ( ) Milano
 ( ) Napoli
 ( ) Palermo
(Move up and down to reveal more choices)

User choose "Tutte" (the list it's a loop)

? Please select cities: Tutte

Now start the selecting data for the second Bill

You are selecting data for Bill number 2
? Please enter the quanty of numbers to play (1-10)

user choose 5

? Please enter the quanty of numbers to play (1-10) 10
? Please select types: (Use arrow keys)
> Ambata
  Ambo
  Terno
  Quaterna
  Cinquina

User press on "Cinquina"

? Please select types: Cinquina
? Please bet on the selected type:

User choose 10

? Please bet on the selected type: 10
? Do you want to add another type? (Y/n)

User chooe No

? Please select cities: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
>( ) Bari
 ( ) Cagliari
 ( ) Firenze
 ( ) Genova
 ( ) Milano
 ( ) Napoli
 ( ) Palermo
(Move up and down to reveal more choices)

User choose "Roma" (the list it's a loop)

? Please select cities: Roma

Output:

image

image

image

? Do you want to play again? (Y/n)

You can choose if you want to play again.

Test

This are the results of the jest test implemented

image

Note: the functions that incorporate the library inquire are not tested.

lotto-game's People

Contributors

drbabol avatar

Watchers

 avatar

lotto-game's Issues

List of the feature of the lotto-game project - PART 001:

1. create function to determine how many bills the user want to generate

To consider:

  • input from the user

2. create a class to initialize the bills of the user

argument:

  • name
  • city
  • type
  • random numbers

methods:

  • private methods to initialize and calculate the arguments
    To consider:
  • city, type and quantity of numbers are an input from user
  • accept only valid values

3. Create a function to initialize multiple bills class

To consider:

4. Create a function to print with nice format the final result

final result is a list of bills with all their information

Improve user experience - Part 004

1. import some nice terminal package to improve the user experience.

  • possible implementation with "terminal-kit".
  • use a list of possible choices for cities and types.

Test

Create test for the program

List of the feature of the lotto-game project - PART 002:

1. create function to simulate the extraction of the lotto

  • possible print of the total extractions

2. create a function to check if there is any winner in the bills created

To consider:

  • print the ticktes result to have won / output the ticket that have won.

Test

To update ..... Description and Title
To create ..... new Label .... "Test"

Calculate prizes - PART 003:

1. create a method in the Bill class that calculate the prize of the bill played

  • ...

2. create a methid in the Bill class that calculate the winning prize if the bill played won

  • ...

3. create a a function that calculate the total prize spent and the total prize won and show gross and net value.

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.