Giter VIP home page Giter VIP logo

yahtzee-1's Introduction

Yahtzee

Yahtzee is a dice game which can be be played as multi-player or single player. For the purposes of this project, I have chosen to write a program for the latter.

Planning

I evaluated several other ideas for this project - noughts and crosses, sudoku, stock management - and documented them here. I chose Yahtzee because it has a challenging set of scoring rules to code, and it lends itself well to customization. For example, it can be played solo or multi-player, single-game or multi-game and has an optional Yahtzee bonus score. It also lends itself well to a leaderboard using Google leaderboard - see Future Enhancements.

Flowchart

To help me structure the functions and visualize the user stories, I created a flowchart which is broken down by function, input, flow control and display blocks.

flowchart

UX & Design

User Stories

As a user, I want to:

  • Play a solo, fun interactive game of Yahtzee and learn rules if needed.
  • Input my name which will be used throughout the game.
  • Re-roll, submit score or escape home if desired.
  • Easily select which dice I want to keep for re-roll .
  • Get feedback on how my dice will score against my chosen category and allow me to change my mind.
  • View my updated scoreboard as I progress through the game.
  • Compete against my personal best.

Colorama

Colours have been used to help the user understand how to select the correct box in which to score points:

colorama

Terminal Window Size

This app was originally designed to fit a terminal screen size of 80 columns by 24 rows. Due to this constraint, I have used a clear_display function to minimize the amount of information displayed on the screen at any one time. Even so, there were points in the flow (such as the rules screen) where the screen size had to be intentionally exceeded to enable the user to see all the information in one place, albeit with scrolling.

Some rows were repeating due to conflict between terminal size and clear_display function. This is a known bug in Heroku which occurs if some rows are hidden from view when clear_display function is used.

Columns and rows were increased from 80 and 24 to 100 and 40 respectively.

terminal size

By increasing the terminal size, the scoreboard with rules displayed without any errors.

terminal size

Lessons learned from previous project implemented here

  • Section on validation and bug fixes included in table form here.
  • Validation errors caught and fixed using the CI pep8 linter.
  • Commit messages like "take 2" avoided. Messages kept short and frequent. Commits made per file or folder. See commit history here

Features and Functionality

Features and functions have been designed to meet the requirements of the User Stories. Docstrings are provided for every function explaining what they doc. Additional comments are included where helpful.

Imported Libraries and Packages

  • random was used to generate 5 random numbers between 1-6 to represent dice face values.
  • os was used to create the clear_display function to enhance user experience and reduce clutter on screen.
  • Colorama was used to add colour to some aspects of the program to help them stand out.

Testing and Debugging

View Testing and Bug Fixing here.

Deployment

Code Institute has provided a template to display the terminal view of this backend application in a modern web browser. This is to improve the accessibility of the project to others.

The live deployed application can be found deployed on Heroku.

Heroku Deployment

This project uses Heroku, a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.

Deployment steps are as follows, after account setup:

  • Select New in the top-right corner of your Heroku Dashboard, and select Create new app from the dropdown menu.
  • Your app name must be unique, and then choose a region closest to you (EU or USA), and finally, select Create App.
  • From the new app Settings, click Reveal Config Vars, and set the value of KEY to `PORT`, and the value to `8000` then select add.
  • If using any confidential credentials, such as CREDS.JSON, then these should be pasted in the Config Variables as well.
  • Further down, to support dependencies, select Add Buildpack.
  • The order of the buildpacks is important, select `Python` first, then `Node.js` second. (if they are not in this order, you can drag them to rearrange them)

Heroku needs two additional files in order to deploy properly.

  • requirements.txt
  • Procfile

You can install this project's requirements (where applicable) using:

  • `pip3 install -r requirements.txt`

If you have your own packages that have been installed, then the requirements file needs updated using:

  • `pip3 freeze --local > requirements.txt`

The Procfile can be created with the following command:

  • `echo web: node index.js > Procfile`

For Heroku deployment, follow these steps to connect your own GitHub repository to the newly created app:

Either:

  • Select Automatic Deployment from the Heroku app.

Or:

  • In the Terminal/CLI, connect to Heroku using this command: `heroku login -i`
  • Set the remote for Heroku: `heroku git:remote -a app_name` (replace app_name with your app name)
  • After performing the standard Git `add`, `commit`, and `push` to GitHub, you can now type:
    • `git push heroku main`

The frontend terminal should now be connected and deployed to Heroku!

Local Deployment

This project can be cloned or forked in order to make a local copy on your own system.

For either method, you will need to install any applicable packages found within the requirements.txt file.

  • `pip3 install -r requirements.txt`.

If using any confidential credentials, such as `CREDS.json` or `env.py` data, these will need to be manually added to your own newly created project as well.

Cloning

You can clone the repository by following these steps:

  1. Go to the GitHub repository
  2. Locate the Code button above the list of files and click it
  3. Select if you prefer to clone using HTTPS, SSH, or GitHub CLI and click the copy button to copy the URL to your clipboard
  4. Open Git Bash or Terminal
  5. Change the current working directory to the one where you want the cloned directory
  6. In your IDE Terminal, type the following command to clone my repository:
  7. Press Enter to create your local clone.

Alternatively, if using Gitpod, you can click below to create your own workspace using this repository.

Open in Gitpod

Please note that in order to directly open the project in Gitpod, you need to have the browser extension installed. A tutorial on how to do that can be found here.

Forking

By forking the GitHub Repository, we make a copy of the original repository on our GitHub account to view and/or make changes without affecting the original owner's repository. You can fork this repository by using the following steps:

  1. Log in to GitHub and locate the GitHub Repository
  2. At the top of the Repository (not top of page) just above the "Settings" Button on the menu, locate the "Fork" Button.
  3. Once clicked, you should now have a copy of the original repository in your own GitHub account!

Future Enhancements

  • Interaction with Google Sheets to read/write data to/from a Leaderboard.
  • Play against the computer.
  • Inlcude a Yahtzee bonus.

Credits

Code

  • Code to create clear_display function taken from Delftstack
  • Code to generate 5 random numbers between 1-6 to represent dice face value taken from Real Python
  • Code to display ASCII art for YAHTZEE lettering generated by ascii-art-generator

Design

  • The Flowchart was made using Google Slides.
  • Favicon was taken from freefavicon

Content

The site is intended solely for educational purposes. All images and favicons remain the property of those credited above

Acknowledgements

I would like to give special thanks to my mentors, Dave Bowers and Tim Nelson for their guidance during the development of this project. The latter provided a useful reference to an example README here.

yahtzee-1's People

Contributors

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