Giter VIP home page Giter VIP logo

-mark-o-s-bulls-and-calves's Introduction

Bulls and Calves

Bulls and Calves is a Python terminal game that runs on Code Institute's mock terminal in Heroku.

This is a fun game in which the game generates a random 2, 3 or 4 digit number.

The player then chooses to guess the numbers in which the game prompts "bulls" or "calves" if the user guesses the numbers correctly or is partially correct. This will test the users problem solving skills and logical thinking.

Image of the app

Table of Contents

User Experience (UX)

User Goals

  • To be able to play the game without having to run into any errors.
  • To be able to read and understand how to play the game.
  • To have the option of different difficulties in order to make the game more challenging.
  • To be able to record the users guesses and have it displayed in order to aid them in the game.
  • To have the option of playing again and choosing a different difficulty if they'd like.
  • To be able to see how many times the user beats the game after they finish playing.

User Stories

  • As a user, I would like to be able to play the game and choose a difficulty.
  • As a user, I would like the option to restart the game after completing it.
  • As a user, I would like to see how many times I guess the numbers correctly after finishing the game.

Design

Flow Chart

I created a flowchart by using Lucid in order to map out what I wanted to happen in the terminal.

Flowchart image

Features

Current features

Starting screen

  • When the game starts up, it informs the user of what they are playing.
  • It tells the user how to play the game.
  • It also informs the user of the games difficulty levels.
  • It prompts the user to enter their name.

Choose difficulty

  • After user inputs their name they are asked to choose difficulty by choosing to guess either 2, 3 or 4 digits.

After choosing difficulty

  • After choosing difficulty, the program repeats the difficulty level chosen by the user.
  • The user must then input their guess.

Playing Bulls and Calves

  • The above is displayed if the user does not get any number correct.

  • The above is displayed if the user guess a correct number but in the wrong position.

  • The above is displayed if the user guesses a correct number and also in the correct position.

  • The above is displayed once the user guesses all the numbers correctly.
  • The user is then asked if they would like to play again.

  • If the user chooses not to play again after after guessing correctly, the program displays how many times they guessed correctly.

  • If the user chooses to play again, they are redirected back to choose the difficulty and play again.

Potential Future Improvements or Implementation

  • Create an optional feature so that the user could play against a bot to guess the numbers also.
  • Make the game more visually pleasing by including different colours and drawing the name of the game instead of just plain text.

Back to Table of Contents

Technologies Used

  • Python - For building the game.
  • JavaScript - Generated from the python essentials template created by Code Institute.
  • HTML5 - Generated from the python essential template built by Code Institute.
  • Github - To save and store all the files of the site.
  • Gitpod - To write all the python. Also used to write the README.
  • CI Github template - Used to help create the terminal that displays for users on the live page.
  • Code Beautify - To aid me in formatting my Python code.

Back to Table of Contents

Testing

Manual Testing

Features

Feature Tested Expected Result Actual Result Pass/Fail
Write name and press enter Receive a message "Hello {name}! Please choose difficulty" and ask how many digits the user wants to guess As expected Pass
When the user chooses either 2, 3 or 4 and press enter The game repeats the users chosen difficulty and prompts user to enter guess As expected Pass
User enters a numbered guess The game will respond and inform the user the result of their guess As expected Pass
Player get all digits correct User is congratulated and asks if they want to play again As expected Pass
After guessing the numbers correctly, user chooses to play again The user is prompted to choose the difficulty again and then continue the next round of guessing As expected Pass
After guessing the numbers correctly and not choosing to play again The game thanks the user and displays how many times they guessed the numbers correctly As expected Pass

Invalid Inputs

Input Expected Result Actual Result Pass/Fail
When promted to choose difficulty, input a letter, word, symbol and any number besides 2, 3 or 4 Receive a message saying "invalid game difficulty" and prompt user to select from 2, 3 or 4 As expected Pass
When prompted to enter users guess, input letters, words, symbols and more digits than required Receive a message saying "Invalid guess" and the game tells user to input a unique number As expected Pass

Bugs

What went wrong:

When attempting to generate 3 unique digits, I called the random module directly. I received "TypeError: 'module' object is not callable" To fix this, I used random.sample() function to generate unique numbers for the game.

When I wanted to use a list of strings, I was still using the input I got from the user. I expected a list of strings but instead I got a string. user_input = input("Enter your guess: ") list_user_input = list(user_input) valid_user_code = validate_user_code_guess(user_input, difficulty_level)

Was trying to compare two interger types when thet were an integer and a string. The string was an input from the user and wasn't converted to an integer type. Fixed the issue by using the int() function to then convert the value to an integer type.

I had an issue with validating the game difficulty. The issue was when the game requests to input difficulty, if the user inputs a word or a letter, it should print out (...invalid game difficulty). However, there is a ValueError instead. The program is looking for an integer number of 2, 3 or 4. I updated it so that the program will accept 2, 3 or 4 as a string if the user enters either of this number. After implementing the new code. The game works.

Validator Testing

PEP8CI was used to check if there were any errors. Below is the result.

  • I received an error at line 156 of my code stating "E501 line too long"
  • I was unable to remove this error due to it being part of me else statement for validating the users input.

  • In line 181 states ("W292 no newline at end of file")
  • I removed this error by placing a new line at the end of the file.

  • Above is the result of my last PEP8CI test for code. I am unable to remove the error of line 156 due to it being a necessary code that I cannot change.

Back to Table of Contents

Deployment

The game was deployed on Heroku. The following steps were used to deploy the game to Heroku:

  • Sign into Heroku.
  • On the main dashboard choose to Create new app.
  • Choose a unique name for your project and the region, based on where you are located (as I'm in Europe, I chose Europe), and then click on "Create app".
  • Then go to the Settings tab.
  • In Settings click on Reveal Config Vars and enter the following key: PORT and value: 8000.
  • Next scroll down to Buildpacks and click Add buildpack, choose Python first, then choose Node.js and then click "Save changes".
  • Repeat the above step and select nodejs and click "Save changes".
  • Next go to the Deploy tab.
  • Under the Deployment method, choose GitHub and then click Connect to GitHub you will be prompted to sign into your GitHub.
  • Then you can search for your GitHub repository, in my case this was "bulls-and-calves" and click connect.
  • To deploy automatically you will need to select Enable Automatic Deploys which will rebuild the app every time you push a change to GitHub.
  • To deploy manually go to the Manual deploy section below and click Deploy Branch. Just remember you will need to do this every time you make a change to your code on Github.
  • Below you will see your app was successfully deployed with a view button below this that will take you to the URL of your deployed app.

Back to Table of Contents

Credits

  • Code Institute for the Python Gitpod template
  • Heroku as the platform to deploy my project
  • My partner for suggesting this game that we both like to play.
  • Stack Overflow for checking errors that I received while building this project.
  • W3Schools for being a secondary platform for me to go over certain types of code while trying to implement my code.

Back to Table of Contents

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.