AshLaw96 / weather-wise

0 stars 1 forks source link

WEATHER WISE

GitHub commit activity GitHub last commit GitHub repo size


Weather Wise is a multiple choice weather quiz that users can play to help improve their knowledge about weather. It is a fun game for all ages, so everyone can play.

When a user first opens the quiz it will show a menu with a title and a brief overview of what the program actually is. Below this will be a list of options with what the user can do next. Depending on their choice it will either start the game, show the instructions on how to play or quit the game. If the user inputs an incorrect value they will then be informed that whatever they have just inputted was incorrect and they need to write either 1, 2 or 3 depending on what they would like to do. If the user inputs 2 into the program, it will then take them to the difficulty choosing section, where it will ask the user what level of difficulty the user would like for example easy, medium or hard. Again, if the user inputs an incorrect value it will tell them that they have done so and need to write either 1, 2 or 3. Following their choice it will then ask how many questions they would like to answer for example 10, 20 or 30. Once more if the user didn't type a correct value it will tell them so and that they need to type either 1, 2 or 3. After this the program will then access data from the questions library and start asking randomly chosen multiple choice questions up until the user has answered their desired amount. For example what is rain? a. God peeing b. condensation from clouds c. water squirting from plains d. water that falls from clouds in the sky. Once again, if the user doesn't input a, b, c or d for any question they will be told to write a correct value from the options given. When the quiz has been finished their score will be added up and then shown to the user. The user will then be asked to enter their name and that their score will then be added to the leaderboard and the top 10 scorers will then be shown in the leaderboard. The user will then be asked if they would like to play again or quit the game. If the user doesn't input a correct value again, they will be informed of this and asked to input a correct value. Providing they have chosen a correct value it will either take them to the difficulty choice section or show a message saying 'thank you for playing, goodbye'. However, at the menu screen if the user inputted the second option the app will then show the user how to play the quiz and once they have read this it will return them back to the menu. Finally, if the user chooses the last option it will then double check they want to quit and if they do it will show the thank you for playing, goodbye message.

Deployed site: https://ui.dev/amiresponsive?url=https://weather-wise-project-e6ccd7a6b753.herokuapp.com

screenshot

source: amiresponsive


User Stories

New Site Users

Returning Site Users

Features

Existing Features

screenshot

screenshot

screenshot

screenshot

screenshot

screenshot

screenshot

screenshot

Click here to view the quit options Y/y or N/n ![screenshot](documentation/features/quit.png) Y/y input ![screenshot](documentation/features/quit-yes.png)

screenshot

screenshot

screenshot

Click here to see both right and wrong answers Correct ![screenshot](documentation/features/right.png) Incorrect ![screenshot](documentation/features/wrong.png)

screenshot

Click here to view the finished game options leaderboard ![screenshot](documentation/features/leaderboard.png) options ![screenshot](documentation/features/play-again.png)

screenshot

Future Features

  1. Allow users to play split-screen or multiplayer.
  2. Add links to other quizzes or cool facts about weather.
  3. Add sound effects to the program.
  4. Add error validation for name (name must be > 2 but < 15 and only include letters).
  5. Add multi-language support so more users can play.
  6. Add a pause feature during the quiz.
  7. Add a timed quiz mode.
  8. Allow the user to have a second attempt at guessing the answer.
  9. Add a timer so users can track how long it takes for them to complete the quiz.
  10. Add a quit feature during the quiz.

Tools & Technologies Used

Data Model

Flowchart

To follow best practice, a flowchart was created for the app's logic, and mapped out before coding began using a free version of Draw.io.

Below is the flowchart of the main process of this Python program. It shows the entire cycle of the program.

screenshot

I used Mermaid to create an interactive flowchart as well.

flowchart TD
    Start([Start]) --> A1[Show menu of what the user needs to do and what the app does e.g. info of what program actually is 1. press 1 to show instructions 2. press 2 to play game 3. press 3 to quit.]
    A1 --> B1[Asks user what difficulty level they want for example 1. easy 2. medium 3. hard]
    B1 --> C1{1, 2 or 3}
    C1 --> D1[Check what difficulty the user has inputted and then ask how many questions they want to answer e.g. 1. press 1 for 10 questions 2. press 2 for 20 questions 3. press 3 for 30 questions.]
    D1 --> E1{1, 2 or 3}
    E1 --> F1[Checks what amount the user would like then access data from the questions library and pulls random questions from this.]
    F1 --> G1[Starts the quiz asking the user multiple choice questions e.g. what is a cloud? a. pillow b. the sky c. a group of tiny water droplets or ice crystals that float in the sky d. rain]
    G1 --> H1{a, b, c or d}
    H1 --> I1[When the user has answered their chosen amount of questions, they will then show their score and be asked to input their name.]
    I1 --> J1[Their score will then be added to a leaderboard and they will then be asked if they'd like to play again or quit e.g. 1. press 1 to play again 2. press 2 to quit]
    J1 --> K1{1 or 2}
    K1 --> |1| A1
    K1 --> |2| End([End])

    A1 --> L1[Shows the user instructions on how to play the game.]
    A1 --> M1[Shows a message making sure the user wants to quit the game e.g. 1. press 1 to keep playing 2. press 2 to quit.]
    A1 --> N1[Incorrect input by user shows they inputted incorrect value and what they need to type.]
    N1 --> A1

Source: Mermaid

Classes & Functions

The program uses classes as a blueprint for the project's objects (OOP). This allows for the object to be reusable.

class SelectionChecker:
    """  Check user input and display errors if input is invalid. """
    def __init__(self, selections):
        self.selections = selections
class CheckerFactory:
    """   Provides different types of selection checkers based on input. """
    @staticmethod
class UIManager:
    """  Handles the starting functions so the program can run. """
    def __init__(self):
        pass
class QuizGame:
    """  Handles all the game functions. """
    def __init__(self):
        self.difficulty = None
        self.num_questions = None
        self.total_score = 0
class LeaderboardManager:
    """  Authenticates to the Google Sheets API and returns the sheet object. """
    def __init__(self):
        self.sheet = None
class StyleHelper:
    """  Handles all the styling operations and definitions. """
class ProgramHelper:
    """  Handles all the helper functions. """

The primary functions used on this application are:

Imports

I've used the following Python packages and/or external imported packages.

Testing

[!NOTE]
For all testing, please refer to the TESTING.md file.

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:

Heroku needs three additional files in order to deploy properly.

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

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

The Procfile can be created with the following command:

The runtime.txt file needs to know which Python version you're using:

  1. type: python3 --version in the terminal.
  2. in the runtime.txt file, add your Python version:
    • python-3.12.2

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

Either:

Or:

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

Google Sheets Deployment

This application uses Google Sheets to handle a "makeshift" database on the live site.

To run your own version of this application, you will need to create your own Google Sheet with three sheets named easy, medium, and hard in the following format:

Name Score Number of questions Timestamp
Max 3 10 2024-10-07 13:15:19
Molly 14 20 2024-10-01 10:9:29
Melvin 10 10 2024-10-07 16:5:9

A credentials file in .JSON format from the Google Cloud Platform is also mandatory:

Google Cloud Platform

  1. From the dashboard click on "Select a project", and then the NEW PROJECT button.
  2. Give the project a name, and then click CREATE.
  3. Click SELECT PROJECT to get to the project page.
  4. From the side-menu, select "APIs & Services", then select "Library".
  5. Search for the "Google Drive API", select it, and then click on ENABLE.
  6. Click on the CREATE CREDENTIALS button.
  7. From the "Which API are you using?" dropdown menu, choose Google Drive API.
  8. For the "What data will you be accessing?" question, select Application Data.
  9. Click Next.
  10. Enter a "Service Account" name, then click Create.
  11. In the "Role" dropdown box, choose "Basic" > "Editor", then press Continue.
  12. "Grant users access to this service account" can be left blank. Click DONE.
  13. On the next page, click on the "Service Account" that has been created.
  14. On the next page, click on the "Keys" tab.
  15. Click on the "Add Key" dropdown, and select "Create New Key".
  16. Select JSON, and then click Create. This will trigger the .json file with your API credentials in it to download to your machine locally.
  17. For local deployment, this needs to be renamed to creds.json.
  18. Repeat steps 4 & 5 above to add the "Google Sheets API".
  19. Copy the client_email that is in the creds.json file.
  20. Share your Google Sheet to the client_email, ensuring "Editing" is enabled.
  21. Add the creds.json file to your .gitignore file, so as not to push your credentials to GitHub publicly.

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.

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:
    • git clone https://github.com/AshLaw96/weather-wise.git
  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!

Local VS Deployment

No differences were found between the local version and the live deployed version of the program.

Credits

Source Location Notes
Markdown Builder README and TESTING tool to help generate the Markdown files
YouTube PP3 terminal tutorial for adding color to the Python terminal
Chatgpt question.py used to generate randomly made multiple choice questions
geeksforgeeks helpers.py used for looking how to clear the terminal using the os library
W3schools helpers.py used format() method to be able to center text
geeksforkeeks helper.py used to understand how to use the sleep() method with the imported time library
Python Docs helpers.py used to understand how to use the quit() method with the imported sys library
W3Schools helpers.py used to understand how to use sample() method from the random library
Python Docs helper.py used to understand how to use ascii_lowercase method from the string library
Python Docs helpers.py used to understand how to use the walrus operator :=
Python Docs helpers.py used to understand how to use the timestamp method from the datetime library
W3Schools helpers.py understand how to use now().strftime() method from the datetime library
geeksforgeeks checks.py used to understand how to use @staticmethod in a class so that __init__ is not required
W3Schools run.py used to understand how to use the pass keyword so that the program does not bring up a error
Tim Nelson entire site used for ideas on how to structure the program
W3Schools game.py used for understanding how to use the lambda function
Stack Overflow helpers.py used to improve the remove function by using \033c escape code, so no left over lines show up

Media

Source Location Type Notes
TinyPNG entire site image tool for image compression
GetEmoji helpers.py image used to add emoji's to the program
prettytable game.py leaderboard table used to create the leaderboard image shown to the user

Acknowledgements