'Numberex' is a number guessing game where either you (the User) guesses the AI number, or the AI tries to guess the number you are thinking of. The project has been developed using the Python programming language to create a command line application that demonstrates the skills I have learnt.
- Here is a link to the final project
My initial idea for the project was to create a number guessing game to play against the computer or let the computer guess the User's number. The upper number limit can be chosen by the User for personalised difficulty.
- As a User, I want the game to have varying difficulty
- As a User, I want to easily understand the main purpose of the game
- As a User, I want a choice of games
- As a User, I want to be able to see how many lives I have left
- As a User, I want the option to play again
- The Features I want the game to have are:
- Allow the User to guess a number between 1 and (a number chosen by the User)
- To give an aspect of difficulty with 5 'lives' or attempts
- If either game is lost or finished, the User will be presented with a restart game option
- To provide a game where the User guesses the AI number and the AI then has a chance to guess the User's number
- Make sure any User input is validated to prevent improper value input
- A terminal with the title
Numberex
andEnter your name:
- Once the User name has been entered, the User is then presented with game rules
and
Please choose upper limit
appears
- The User has the option to choose the highest number they wish
- The game starts with
Make a guess between 1 and (number chosen)
- The User makes a guess, and the game checks if it is correct, If the User makes an incorrect guess, they lose a life and must guess again
- If the User has run out of guesses,
Sorry, you ran out of guesses
AI tells the User the number and the game moves to AI guessing
- If the User made the correct guess, they win and the turn moves to AI guessing
- The User now thinks of a number between 1 and (original number chosen)
- The AI asks the User
..Is your number (AI Guess)?
- If the User thinks it is too high, press
h
- if too high, AI guesses again
- If the User thinks it is too low, press
l
- If too low, AI guesses again
- If the User thinks the AI guess is correct, press
c
- If correct, AI shows off by telling you they won
- Option for
Do you want to restart the game [Y/N]
appears - If the User enters
y
, A welcome back message appears and game restarts toMake a guess between 1 and (number chosen)
- If the User enters
n
, Game ends withThank you for playing Numberex!
- Add AI Guesses (lives) left
- Add an option to choose between AI vs User or User vs AI
- Add how many lives the User or AI had left once correctly guessed the number
- There is one background image, for aesthetics only IStockphoto
- The project uses Pyfiglet for the ascii art (title)
- Otherwise, Standard terminal font, cannot be changed
As a User, I want the game to have varying difficulty
:- After the User inputs his/her name, The option to choose
highest number
will appear to provide a personalised level of difficulty. Outcome:Fulfilled.
- After the User inputs his/her name, The option to choose
As a User, I want to easily understand the main purpose of the game
:- Once the User has entered his/her name, and made a choice of difficulty,
there will be a paragraph on what the game entails. Outcome:
Fulfilled.
- Once the User has entered his/her name, and made a choice of difficulty,
there will be a paragraph on what the game entails. Outcome:
As a User, I want a choice of games
:- I have provided two games that run consecutively,
First: User to guess the AI number
Second: AI to guess User number. Outcome:
Fulfilled.
- I have provided two games that run consecutively,
First: User to guess the AI number
Second: AI to guess User number. Outcome:
As a User, I want to be able to see how many lives I have left
:- After each guess from the User, the terminal will print how many lives (guesses)
the User has remaining, counting down from five. Outcome:
Fulfilled.
- After each guess from the User, the terminal will print how many lives (guesses)
the User has remaining, counting down from five. Outcome:
As a User, I want the option to play again
:- I have provided an option at the end of the game that asks
Do you want to restart the game? [Y/N]
If the User inputsy
, the game restarts to the User vs AI with the original input difficulty. If the User inputsn
the game ends with a messageThank you for playing Numberex!
. Outcome:Fulfilled.
- I have provided an option at the end of the game that asks
-
Upon loading the game screen terminal:
-
The User is greeted with
Enter your name:
, Although it is out of my power for a User to input random letters or characters rather than a name, I have made sure that any spaces before or after the input are stripped after the User presses enter. For example: -
After enter is pressed, the Users name appears without whitespace along with the game rules This always prints at the start of the game after the User has input a name and pressed enter
-
At the same time the game rules print out to the terminal, a statement appears to enable the User to choose a high number in order to make the game more difficult:
-
As you can see in the image above, I have input several letters, characters and combinations of both including numbers, validation always catches the fact the input is not a number or integer, it prints the statement
Please select a valid number
and then re-prints the statementPlease choose an upper limit:
-
When the correct value (number) is input into the terminal for
Please choose an upper limit:
i.e.10
, enter is pressed and a new line with messageMake a guess at a number between 1 and 10:
- I have input words, strings of words, individual letters, characters, and pressed enter, but with validation,
I cannot input anything other than a number. A message appears
Sorry, Chris, That is not a number!
:
- I have input words, strings of words, individual letters, characters, and pressed enter, but with validation,
I cannot input anything other than a number. A message appears
-
For the sake of this test the upper limit is 10. If I try to input a number outside of the set limits (1 to 10), in this case
15000
, the issue is caught with the following messagePlease choose a number between 1 and 10:
-
When the correct value is entered for this part of the game (a guess between 1 and 10) but the guess is too low, the game sees that the number is too low and prints out the statement
Sorry Chris, guess a little higher!
-
The terminal prints again
Make a guess at a number between 1 and 10:
-
The code then recognises one guess has been made out of five and prints out
..Guesses Remaining: 4
-
When the correct value is entered but the guess is too high, the game sees that the number is too high and prints out the statement
Sorry Chris, guess a little lower!
-
The terminal prints again
Make a guess at a number between 1 and 10:
-
The code then recognises two guesses have been made out of five and prints out
..Guesses Remaining: 3
- If I keep inputting the same number until the lives have run out, The terminal prints,
Sorry you ran out of guesses, my number was: (example number)
- Then the game moves to the AI guessing my number.
- But, if I guess the correct number within the limits, I win with a message
Well done, You guessed the correct number: (Example number)
-
-
The next part of the game is, I have to guess the number the AI is thinking of,
-
My Turn!!.. Is your number (in this case) 9?
-too high(H) too low(L) correct(C)
-
For this test I forced the AI higher by the input of
too low(L)
-
The AI printed:
-
My Turn!!.. Is your number 10?
too high(H) too low(L) correct(C)
-
Again, my input was
too low(L)
- With validation in my code I am able to catch a user forcing past the upper and lower limits with a try/except rule and the following happens:
-
If I input
too low(L)
one more time, the code is written to prevent cheating and the terminal prints a statementI think you are cheating I am not playing this game with you anymore!
-
This test is also the same when entering
too high(H)
and trying to force the AI past 1 and lower -
The game then ends with a final statement
Chris, Do you want to restart the game? [Y/N]
- If I input anything other than
y
orn
, input validation has been written to prevent an invalid character or letter apart fromy
orn
- If I input anything other than
-
When I type
y
, The code has stored the name to reinsert into the print statementWelcome back, (name)!
-
The game then loops back to the
User vs AI
But this time there is no option to input a higher number,- This is something I would like to implement for future development of the game
-
When I type
n
The game simply ends with messageThankyou for playing Numberex!
-
For the sake of testing, If none of the above is true, (no cheating, no incorrect values etc) the AI has infinite guesses to find the number I am thinking of
- This is a flaw I came across while carrying out manual testing, I would like to in future development (with more time), include AI guess limit function
-
If the number I am thinking of matches the AI guess, I input
correct(c)
and I am greeted with a message:HAHA!! I guessed (number) The number you were thinking of.. I WIN!!
-
And finally the option to restart the game appears, If I press
y
, the loop starts again, if I pressn
, the game finishes with the messageThank you for playing Numberex!
-
-
Throughout the development of this project, several automated (flake8) errors have been fixed i.e.
- Indentation errors
- Undefined variable name
- Not enough whitespace between functions
- No new line at end of file
- Invalid syntax errors
- Imported but unused errors
-
Found an issue with
AI vs User
, where there was a double input of the User controls ofH L or C
, for example, if the User is thinking of 5 and AI guessed 4, the User would input H for higher, but two H H would appear on seperate lines.- This was fixed by removing a missed duplicate print() statement.
-
Found an issue with restart game function, the option to restart the game would appear during the
AI vs User
game, or wouldn't appear at all.- This was a complete oversight, I had simply placed the function at the end of the file, logically, the
end_game()
function needed to be placed aboveuser_guess
andcomputer_guess
functions in order to be called after the game ended. - Importing
sys
forsys.exit()
also cured the issue of the game not ending in the same function.
- This was a complete oversight, I had simply placed the function at the end of the file, logically, the
-
Any duplicate or unused code, comments etc have been removed
-
Any irrelevant space in between code has been removed
- When the game comes to an end and the User requests to restart the game, the game loops back to User vs AI, without the possibility of inputting a new number for difficulty purposes. The game does run as normal apart from this issue
- All previously known errors during the development process have been resolved
- The project was written and tested using Gitpod
- The project uses Github for utilising git version control
- The project was deployed via Heroku
- The project was written using PYTHON3
-
Pyfiglet
- This library was used to create the ASCII art for the title upon loading the game
-
Random
- randint was used to generate a random number for the game
-
Sys
- sys was imported for the exit and restart function of the game
- This Game was deployed using Heroku with the following the steps:
- Navigate to Heroku.com and log-in or create a new account.
- On the top right hand side, click the 'New' button.
- Inside the dropdown menu, select 'Create new app'.
- Create a new name for your app (making sure the name chosen is available) in this case it is
numberex
. App names can only be in lower-case letters, numbers and dashes. - Select your region, in this case,
Europe
. - Click on the
Create App
button. - This will create your app in Heroku and take you to the Heroku dashboard.
- Navigate to the settings tab and scroll down to the button
Reveal Config vars
. - Replace the word
KEY
and enterPORT
and then replace the wordVALUE
and enter8000
then click on theAdd
button. - Below
Config vars
isBuildpacks
. Click theAdd Buildpack
button. - In the pop up window, select
python
and save changes. - Repeat this again but this time selecting
node.js
and save the changes. - It is
important
to make sure the buildpacks are in the correct order withPython
being at the top andnode.js
bottom. If they are not in the correct order, you can drag them into the right order. - Next, navigate to the
Deploy
tab at the top left side. - Select
Github, 'connect to github'
as the deployment method. - Search for the Github Repository in the search field (in this case
Python_PP3
) and clickSearch
. - When the search is complete, click
connect
. - Once your repository is connected to Heroku, Click the
Enable Automatic Deploys
button for automatic deployment. - Alternatively you can manually deploy by selecting a branch to deploy from and clicking
Deploy Branch
. - If you choose to
Enable Automatic Deploys
, Heroku will build a new version of the app when a change togitpod
is pushed toGithub
. - Manual deployment allows you to update the app whenever you click
Deploy Branch
. In the case of this project, I chose toEnable Automatic Deploys
to ensure the code was deployed straight away at each push fromGitpod
. - Once the build process is complete (this can take a few seconds) you will then be able to view the live app by clicking on the button
View
belowYour app was successfully deployed
.
-
These commands were used for version control during project:
- git add
example filename
- to add files before committing - git commit -m
"example message"
- to commit changes to the local repository - git push - to push all committed changes to the GitHub repository
- git branch - to see which branch currently working on
- git pull - to pull all code into main branch once the feature branch had been merged and deleted
- git status - to see if the branch currently working on is upto date or if the are any unstaged
- git log --oneline - to see the last commit
- git commit --amend - to amend the most recent commit message
- git add
If you need to BRANCH
off of the main repository:
- If you have not already, login in to GitHub and go to https://github.com/Chr15w1986/Python_PP3
- On the left side of the screen underneath the nav links, click the drop down box
Main
- Inside the box you will see
Create new branch/tag
- Inside the text box, enter the new branch or tag name i.e.,
Features
- Below the Branches Tags tab, you will see
Create branch: Features from "main"
- Click on
Create branch: Features from "main"
and you will be taken to the new branch page you just calledFeatures
If you need to FORK
a repository:
- If you have not already, login in to GitHub and go to https://github.com/Chr15w1986/Python_PP3
- In the top right corner, click
Fork
- The next page will be the forked version of https://github.com/Chr15w1986/Python_PP3 but in your own repository
If you need to make a clone of this repository:
- Fork the repository https://github.com/Chr15w1986/Python_PP3 using the steps above
- Above the file list, click
Code
(Usually green at the top right of the code window) - Choose if you want to clone using HTTPS, SSH or GitHub CLI, then click the copy button to the right
- Open Git Bash
- Change the directory to where you want your clone to go (your own github)
- Type
git clone
and then paste the URL you copied in step 4 - Press
Enter
to create your clone
If you need to make a local clone:
- If you have not already, login in to GitHub and go to https://github.com/Chr15w1986/Python_PP3
- Under the repository name, above the list of files, click
Code
- Here you will have two options,
Clone
orDownload
the repository - You should close the repository using HTTPS, clicking on the icon to copy the link
- At this point, you can launch the
Gitpod workspace
or choose your own directory - Open Git Bash
- Change the current working directory to the new location of where you want the cloned directory to be
- Type git clone and then paste the URL you copied in step 4
- Press Enter, to create your local clone to your chosen directory
- Background image of numbers collage, IStockphoto
- W3Schools for an interesting read on python functions and how they can be implemented
- Stackoverflow For an unused import error I was experiencing
- Stackoverflow For a rough guide on how to implement a restart game function
- Code institute for the amazing Tutors on the course
- My brilliant Mentor Ben Kavanagh, BAK2K3 for his advice on my code, pushing me back on track when I start to lose faith, taking time out of his own day and duties to answer ALL of my questions with utter perfection!
- Dave Horrocks DaveyJH, again! for giving me time out of his own studies, for his patience, helping me above and beyond.
- Shellie Downie ShellieD, for her support, pointing out an obvious issue with my code so quickly.. TWICE! after hours of staring at it and looking straight over the problem.
- My family for their support, patience and testing!!
- My wonderful fiancée for being my personal spell checker/grammer police and for listening to me when I need to rant!
- Everybody on Slack for tips, advice, quick fixes and support