Skip to content

Commit

Permalink
Remove time python module and clear terminal call function at the top…
Browse files Browse the repository at this point in the history
… of the run function in the games class. Update deployment details in README file
  • Loading branch information
Robrowno committed Jun 2, 2022
1 parent ad10bf3 commit 94de55b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ Aside from aesthetics in the 'terminal view port' width and layout, I'm happy to

- There was an issue where if the player didn't play the game as intended and lied about the results in game2 (Guess-The-Number (AI)), it would throw a traceback error in the terminal. An extra try/except statement was included and another if statement and it catches out the problem. This issue in particular was spotted by Niki Tester and together we found a solution to the problem.

- On the deployed game, I had a flickering issue when a number greater than 3 or less than zero was entered in the main menu. To fix this, I imported Python's time module and set a time.sleep for 3 seconds in the menu run function. This did fix the flickering but I still wasn't too happy as during the 3 second delay you could continue to input different options. It was only after this I realised I was calling my clear terminal function too early and this was causing the flickering. By removing this, it did an even better job than introducing the time module and so I promptly removed it.


---

Expand All @@ -357,7 +359,9 @@ I submitted my project to the peer-code-review channel in the C.I Slack communit

- A few other users on Slack also made some suggestions regarding how I could present the list of past guesses differently and also I had a suggestion for future builds to automate the whole second game and remove the user input element of it.

- Daisy, my C.I Mentor, has been reviewing my work at the beginning, middle and end of my project, providing vital feedback in the direction and scope of my project.
- Dave on Slack found a flickering bug in the main menu if an incorrect integer greater than 3 or less than 0 was entered. I took this feedback and imported the python time module to introduce a small pause to stop the flickering issue. It was only after this I realised I was calling my clear terminal function too early and this was causing the flickering. By removing this, it did an even better job than introducing the time module and so I promptly removed it.

- Daisy, my C.I Mentor, has been reviewing my work at the beginning, middle and end of my project, providing vital feedback in the direction and scope of my project. In the final review right the end of the project, Daisy was very happy with how far I'd come with the project, and after a couple of further suggestions for my code and README file, I was ready to submit it.


---
Expand All @@ -366,15 +370,37 @@ I submitted my project to the peer-code-review channel in the C.I Slack communit

Follow the steps below to see how to deploy a repository through Heroku:

### Build an app in Heroku:

To build an app in Heroku, follow these steps:

1. Open the Heroku site, login and access your dashboard. In the top right hand corner of the website, click on the "New" button and select "create new app".
![Heroku Home](/assets/readme-images/heroku-start.png)

2. You will be brought to a new page where you can enter the name of your app and the region you are based in. Once you do this, click on the "create app" button:
![Create New app](/assets/readme-images/heroku-newapp.png)

3. Once you do this, you will be brought to the app-specific dashboard.
![Heroku Pipeline](/assets/readme-images/heroku-pipeline.png)

4. Make sure you connect/link your github account for ease of deployment and then head to the settings tab to configure vars and install required buildpacks:
![Settings](/assets/readme-images/heroku-settings.png)
- You will want your config vars to have the key and value --> PORT and 8000
- Buildpacks required will be Python and Node.JS **in that order**
![Config Vars and Buildpacks](/assets/readme-images/build-config-vars.png)

5. Once this is done, you are ready to begin deploying your application!


### Steps to deploy your app to Heroku:

1. Login to Heroku in the terminal byt entering the command **heroku login -i** followed by your login details.
2. Retreive your application's name from heroku and enter **heroku apps**.
1. Login to Heroku in the terminal by entering the command **heroku login -i** followed by your login details.
2. Retrieve your application's name from heroku and enter **heroku apps**.
3. Set the heroku remote: (make sure you replace the <app_name> with your actual application name) heroku git:remote -a <app_name>
4. Next, as per a usual deployment to github, enter the following commands with a similar message: git add. (followed by -->) git commit -m "Deploy to Heroku through CLI" (followed by -->) git push origin main (followed by -->) git push heroku main

Alternatively, if available, you can also enable auto or manual deployments if you link your github account and repository to your Heroku account. This enables much faster linked deployments without using the CLI.

Alternatively, if available, you can also enable auto or manual deployments if you link your github account and repository to your Heroku account. This enables much faster linked deployments without using the CLI.

---

Expand Down
Binary file added assets/readme-images/build-config-vars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/readme-images/heroku-newapp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/readme-images/heroku-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/readme-images/heroku-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/readme-images/heroku-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/readme-images/pep8-validation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 9 additions & 24 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Main app file for game
"""
import random
import os
import time

import colorama
from colorama import Fore, Style
Expand Down Expand Up @@ -53,7 +55,6 @@ def clear_terminal(self):
print("\n" * 150)


# User has to guess a number generated by the computer
class PlayerGuesses(Helper):

"""
Expand Down Expand Up @@ -105,15 +106,6 @@ def play(self):
print(f"\n{Fore.GREEN}You got it! The number was: {random_number_100}")
print(f"{Fore.GREEN}You guessed it in {self.guesses + 1} attempts!")

# Computer has to guess a number generated by the User

# User chooses a number
# Computer makes a guess
# User gets an input to say if the number needs to be lower or higher
# by entering 1 for lower, 2 for higher or 3 for when the number is correct
# Continues until computer gets to the correct number
# prompt to play again or something else


class ComputerGuesses(Helper):

Expand Down Expand Up @@ -200,15 +192,6 @@ def play(self):
print(f"{Fore.RED}You're not playing the game correctly!!")
break

# Coin Toss (Heads/Tails)

# Program begins when user presses a key
# User calls in an input whether they think it will be heads or tails
# The computer makes a guess of its own
# The 'coin' is flipped and a result is generated
# See who wins the round
# Prompt to either 'flip a coin' again or do something else


class CoinToss(Helper):

Expand Down Expand Up @@ -295,6 +278,10 @@ def __init__(self):
self.game3 = CoinToss()

def __menu(self):
"""
Prints the welcome message and start menu
options and descriptions.
"""

print(f"{Style.BRIGHT}Welcome to my Guess-The-Number application!\n")
print("A game where you or the computer can try to guess a number.")
Expand All @@ -310,10 +297,8 @@ def run(self):
Runs the menu introduction and provides player with an input to
pick one of three options.
"""
self.clear_terminal()

while True:

self.__menu()

menu_input = self.get_int("Please pick a number to begin: ")
Expand All @@ -333,8 +318,8 @@ def run(self):
self.game3.play()
self.__end_of_game(self.game3)
elif menu_input > 3 or menu_input < 0:
print(f"{Fore.RED}Invalid option! Pick: 0, 1, 2 or 3 only")
time.sleep(3)
print(f"\n{Fore.RED}Invalid option! Pick: 0, 1, 2 or 3 only\n")

self.run()

else:
Expand Down

0 comments on commit 94de55b

Please sign in to comment.