Skip to content

artontray/PROJECT3

Repository files navigation

Purpose of this project

This project was developed in order to demonstrate some ability to code in Python. I got in mind that I had to get more experience with followings :

  • Repetitions with loops
  • Selections
  • Using Modules
  • Aggregating data such as array and lists
  • Iterations
  • Functions
  • Object-Oriented programming
  • Data structures
  • Exceptions and error management
  • API keys

The main objective is to demonstrate competency in Python whilst proposing to code a simple game.

Check this out

Le Juste Prix

This game was very famous in 90' in France. I got inspired by doing a game as the original version of "Le Juste Prix" except the fact that instead playing with prices, we plays with numbers.

If you are interested just check this link here

Sometimes is better a good picture than a big text to explain something :

Explain the game

Explain the game



Some basics informations around this game :

  • The user plays against the computer.
  • The user select a level of difficulty which will give to computer a specific range where to select a number
  • Timer is starting to run when computer inform the user that a number has been selected
  • The user can try to guess the computer's number as many time as he wants but time is running
  • The aim is to guess the computer's number as fast as possible!
  • When the user enter the right computer's selected number, the Timer stops and computer calculates Time on-game
  • Time is calculated in second as unit and Time on-game will determinate the player's position into the score tab
  • A message is displayed to show up the player's position in the score tab

Contents

User Experience (UX)

Wireframes

The wireframes for this game were inspired by CowSay.

If you are curious and want to try it on your own Unix Machine Run apt-get install cowsay on a terminal as following : (This action is not required, it's just for fun)

Cowsay Unix

Cowsay Unix

From beginning, i wanted to make the game interactive with a custom print function:

This is the final interaction layout of the Game:

Main page with Cowsay

Back to top

Structure of the game

Le "juste prix" game has one main page called run.py . This Page is the default loading page. When first loading, a box pops up displaying a welcome message . Next box, the user will be invited to register an username. The main page run.py is calling an other page called print.py for :

  • printing out a welcome message : welcome_print()
  • printing out messages to the user : my_print()
  • printing out some coloring messages : red_string(text), green_string(text), blue_string(text)

I used this site to build up this following ASCII design.

Welcome

Your name

This name will be registered to Excel file database for scoring tab display (We will see this in details later on in this readme file)

A Main menu has been created to give easy access to differents sections :

  • Play Game
  • See the instructions of the Game
  • See the top5 players score for each Level of difficulty

Main menu

Going through Instructions :

Instructions

Press Enter to run the instructions....

Instructions

I introduce an on-game example so the user get to known more about what is happening when game starts :

Instructions

Instructions

Instructions

After finishing to read the instructions, the user can start playing!

The Game have 4 differents level of difficulty:

  • Beginner : User will have to guess a number from 1 to 100
  • Medium : User will have to guess a number from 1 to 500
  • hard : User will have to guess a number from 1 to 1000
  • Champion : User will have to guess a number from 1 to 10000

Instructions

After selecting the level of difficulty, the game starts :

Instructions

Each time the user type a number, a timeline is displayed with a message :

Instructions

Instructions

When user found out the right number, computer stops the time and calculate the time on-game, a message is displayed :

Instructions

Instructions

A score tab is displayed with the user's position :

Instructions

Back to top

Programming Structure

Before starting to code, I wanted to have a big picture of the programming structure :

Beginning of the Game :

  • 1/ Give instructions of the game
  • 2/ Choose the level of the game
  • 3/ Timer start to run
  • 4/ Run the Game
  • 5/ User found the good number, we stop the Timer
  • 6/ Calculate the time on-game
  • 7/ According the selected level, we select the right worksheet
  • 8/ We register the data into excel file
  • 9/ We sort the files by Time value, smaller time is first
  • 10/ We shows the scoring tab

Back to top

Python Logic

I created a graphcet-like diagram to get a big picture of all the functions needed for the Game :

Graphcet

"Fin" (Black circle) means "End" on this graph. I wanted to change it through the Lucid Graph Website but then I was limited by the free version, could not modificate anything more on the graph without suscribing for a premium access.

Back to top

Data Model

I used Google Sheets to store all the data of the game. The Google Sheet have 4 separated worksheets :

  • Beginner - Used to store users username and time performance in Beginner Level
  • Medium - Used to store users username and time performance in Medium Level
  • Hard - Used to store users username and time performance in Hard Level
  • Champion - Used to store users username and time performance in Champion Level

Click this link for Google Spreadsheet of this Game

excelfile

Back to top

Design Choices

  • Typography

    The game beeing only running with a terminal design, i wanted to create a custom print function to make it more friendly. In fact, no graphical effects here so the main focus was on creating a friendly design to catch the interest from the user...

Back to top

  • Colour Scheme

    I used 3 differents coloring effects :
  • Blue : when computer interact with the user

blue color

blue color

blue color

  • Green : When an action have succeed

green color

  • Red : When an action failed

red color

red color

Back to top

User stories

First Time Visitor Goals

  • As a First Time Visitor, I want immediately to understand the main purpose of the game.
  • I want to be able to quickly understand the game controls and mechanics in order to enjoy playing the game
  • I want to be able to consult the game instructions as many time as I want.
  • I want to be able to see my score after each game.
  • I would like to play a simple game, with a fairly short play time.
  • I would like to come back in the future and use my username to challenge my previous performing.

Considering that there is no possibility to login for the user, the Game is built in the way that :

  • As long as you perform at least one game, your name and scoring is registered into database
  • if your name is already on the database, your score for each game will be updated (only if user perform a new personal record of course!)
  • The user can come back to play this game any time in the future and challenge himself using the same username as registered previously

Instructions

Features

The game should have a fun design and is intended for users as an entertainment value only.

Back to top

Loading a New Game

How do we start a new Game?

To start a new Game :

  • Give your username
  • Choose option 1 in the main menu
  • Select your level of difficulty
  • Game is starting

Back to top

When is the game finished

How do we stop the Game ?

If you want to stop playing do the following :

  • Press "q" when prompt the following message :

No more gaming

OR Click the following button :

No more gaming

  • Then close the brownser window

  • To get back to the game

Click here

Easy, right? :-D

Back to top

  • Errors

    A message is displayed

Each time user type an incorrect input, Game will guide to get back on tracks :

Errors

Errors

Errors

Errors

Errors

Back to top

Future Features

As a Future Features:

  • It could be interesting for the user to choose himself the range of number to guess...
  • It could be interesting to register the email adress of the User also. So when his position changes into the tab score he can receive a email as, for example : Dear Damien, a User called John has registered a better Time on Level Hard at "Le Juste Prix" Game. Join Now!

Back to top

Technologies Used

  • Heroku - used to deploy the Game online.
  • Gitpod - used to get a workspace to use for coding.
  • Github - used to edit the website.
  • veed - used to edit Gif for readme file.
  • Favicon - used to create a favicon for the website.
  • Lucid App - used to create The logic flow on the application with Graphcet style diagram.
  • Python - Provides game's functions and rules.
  • GitBash - Terminal used to push changes to the GitHub repository.
  • Google Chrome DevTools - Used to test responsiveness and debug.
  • Responsive Design Checker - Used to test responsiveness.
  • Microsoft Excel - Used to create spreadsheets to easily view data.
  • Google Sheets - Used to host the application data.
  • VS STUDIO was used to edit the code.
  • Excalidraw to draw the image to describe the game in. first part of this document.
  • Readme.so was used to write this readme File.

Back to top

Python Packages

  • GSpread - Used to transfer data between google sheets.
  • Randint - Used to implement pseudo-random number generators.
  • OS - Used to provide a way of using operating system dependent functionality. Clear the screen output for example.
  • Time - Used to provide various time-related functions.
  • Wrap - Used for editing strings structure.

Back to top

Testing

Am I responsive App?

Responsive test

Back to top

  • Manual Testing

    • In addition to the other tests, I have conducted a manual check list for myself to carry out to make sure that everything is working as intended.

    • Manual Tests Conducted

      • Startup Display

        • Verify that the input for username refuses some specific caracter as '\n', '\' or '"'.
        • Verify that the username validation is working as intended.
        • Verify that if the user enters a correct name, they will move to the Main Menu.
      • Main Menu

        • Verify that the users name is displayed at the top of the page.
        • Verify that the user receives an invalid input message if an incorrect key has been entered.
        • Verify that all menu options load as intended only if the user enters the appropriate key.
      • Level of difficulty Menu

        • Verify that the user receives an invalid input message if an incorrect key has been entered.
      • On Game inputs

        • Verify that the user receives an invalid input message if an incorrect key has been entered.
        • Verify that the Timeline is correctly displayed.
        • Verify that the message from computer is clear enough to guide user finding the right number.
      • Score Tab

        • Verify that an registered user always appears on the tab score even not in top5 players.

        Score tab

        • Verify that the score tab is displayed correctly
        • Verify that the sort_tab() function is working correctly and sort the all cells of the selected worksheet by time.
        • Verify that the Application is creating missing worksheet needed to register the player's score

        Creating Worksheet

        I 've been using Exceptions to detect the error during opening the Worksheet if not found :

        function check database

        • Verify that the Application is creating missing worksheet when displaying the top5 players from the main menu.

        Creating Worksheet

      • Verify that a message is displayed if the worksheet is existing but empty.

      • Rules of the Game

        • Verify that the rules of the game are accessible from first visit users.
        • Verifiy that the rules are easy to understand and well presented
        • Verify that the rules are explained with a clear example
      • Exit App

        • Verify that when the user exits the app, a message is displayed with a thank you message and then the program shuts down successfully.

PYTHON VALIDATOR

PYTHON

The Python validator results is below:

  • run.py, print.py : for testing I used the following tools here

First try, I got hundreds of warnings :

warnings

However these have now been all fixed because it was only about extra space or too long syntax issues.

No errors detected for both files.

Pep8

Pep8

Back to top

HTML CHECKER

The HTML validator results is below:

No errors detected.

html

CSS CHECKER

The CSS Validator results is below:

No errors detected.

css

Back to top

Browser Compatibility

The website was tested on the following browsers with no visible issues for the user :

  • Brave
  • Mozilla Firefox
  • Safari

Appearance, functionality and responsiveness were consistent throughout for the previous range of browsers.

Back to top

  • Lighthouse Testing

    • Furthermore the website has been through the Chrome Dev Tools Lighthouse Testing which tests the website for the following:
      • Performance - How the page performs whilst loading.
      • Accessibility - Is the site accessible for all players and how can it be improved.
      • Best Practices - Site conforms to industry best practices.
      • SEO - Search Engine Optimisation. Is the site optimised for search engine result rankings.

lighthouse

Back to top

To sum up

To sum up :

  • I confirm that the main content of the game is readable and easy to understand.
  • I confirm that the interaction with the user is smooth and efficient with errors management functions.

Back to top

Bugs

Fixed Bug

As i said in the first part of this document, I wanted to create an custom print function for this game. It tooks me some good time to code it properly because each message to display can be different to an other (structure, coloring, scoring tab etc...) Dealing with different type of messages as coloring or score tab can create some problems in the display :

Error Layout

Error Layout

Error Layout

Error Layout

Error Layout

Detecting each type of messages to display, I found the way to have a perfect display :

Good Layout

Also the black and white screen was hard to display error messages as "Wrong number" or "Try again" or simply get the user's focus front of a big block of text as below :

try again

wrongnumber

Good Layout

Big blocks of text looks better like this :

Good Layout

So, I had to find the way to incoporate into the custom print function some coloring doing as the following :

Adding coloring

Adding coloring

Then i could add some coloring text depending the situation :

Adding coloring

When I first deployed on Heroku, I could finally see the layout of the game and i could see that the fixed window space create some distortion on the display. In fact, the amount of text on each screens of the game can be different, the layout can appear far away from the bottom zone and create some problem of visibility :

Empty space

For that, I added some new lines into my custom print function :

First, I needed to clear the screen on each new call of my custom print function :

Empty space

Empty space

After that, I calculated the number of lines to print out and knowing the maximum's number of lines (80 characters wide and 24 rows high) of this fixed windows, it was easy to build up a for loop to generate the right quantity of lines to end up always on the bottom of the screen.

Empty space

Empty space

Back to top

Unfixed Bug

When making some repetitive tests on my code, i got this following message :

exceed quota

It looks like the only way to fix this problem of quota is to register for a new package from Google Cloud Service.

Back to top

Deployment

How to fork a repository :

If you need to "FORK" a repository:

  1. Login in to GitHub and go to https://github.com/artontray/PROJECT3
  2. In the top right corner, click Fork
  3. The next page will be the forked version of https://github.com/artontray/PROJECT3 but in your own repository

Fork

Back to top

How to create a local clone of this project :

The method from cloning a project from GitHub is below:

  1. Under the repository’s name, click on the code tab.
  2. In the Clone with HTTPS section, click on the clipboard icon to copy the given URL.

To Clone

  1. In your IDE of choice, open Git Bash.
  2. Change the current working directory to the location where you want the cloned directory to be made.
  3. Type git clone, and then paste the URL copied from GitHub.
  4. Press enter and the local clone will be created.

Back to top

To deploy the project with Heroku:

The site was deployed to Heroku cloud Platform. To be able to run your python program on the web, you need Heroku Cloud platform to host it and deploy. There are severals steps to proceed, please , follow carefully every steps :

  1. Create an account gmail
  2. Go to Cloud
  3. Create a New Project

deployment

deployment

  1. Select your project

deployment

  1. Search for Library into APIs and Services Left Menu

deployment

Back to top

  1. Search for Google Drive API and ENABLE IT

deployment deployment deployment

  1. Do the same but searching for google Sheet and ENABLE IT

deployment

  1. Create CREDENTIALS

deployment deployment deployment

  1. Select a role

deployment deployment

Back to top

  1. Editing Credentials

deployment deployment deployment deployment

  1. Download your JSON FILE

It will automatically download a JSON file, save it on your computer.

deployment

  1. Key will be active

deployment

Back to top

  1. Import the excel file

Go to this File

And Make a copy and share the file with the email created into cloud

deployment deployment deployment deployment

Be sure to select EDITOR when sharing the file :

deployment

  1. Fork the project with Github and open it with Gitpod :

To fork the project, refer to this part Deployment

Launch Gitpod and drag and drop the JSON file into the project and rename it as following :

Clik here : GitPod

deployment

Back to top

  1. Protect your JSON FILE :

Add the creds.json file into .gitignore file

deployment

Just after that, run :

  • git add .
  • git commit -m "Initial commit"
  • git push
  1. Install gspread

run on the terminal : pip3 install gspread google-auth

Back to top

  1. Finally Deploy with Heroku :

Go Heroku Plateform

Create a New App

deployment

Add Buildpack : Python and nodejs

deployment

Configure VARS :

deployment deployment

Connect your github account and Deploy :

deployment deployment deployment deployment

Back to top

Wait for installation and check your deployed project :

deployment deployment

Back to top

Credits

Content and Media

  • The general custom print function idea came from Cow Say
  • The favicon came from This site
  • The first Welcome Menu ASCII design came from Patorjk.com
  • General mathematics functions information in Python came from This site
  • General Os functions information in Python came from This site
  • General path functions information in Python came from This site
  • General random functions information in Python came from This site
  • General information about exceptions in Python came from This site

Best part of this project

To be honest, best parts of my learning progress are the following :

  • Learning Python
  • Learning how to connect an excel File with programming code through API
  • Learning how to deal with exceptions and errors messages
  • Learning how to import external library and incoporate it to my coding
  • Learning Oriented Object programming
  • This function is my favorite one : Asking for an username through an input, creating an Object called User and Launching a Menu of option in one line of code!

Oneline

Back to top

Personal Development

That was my first time with Python. I instantly enjoyed so much starting to code. I feel like I 've been through the fundamentals of Python even If I still feel that I have only scratched the surface but I understand why it is currently one of the most popular programming language in the world. It's easy readeable and mostly so powerful! I can' t wait to experiment Python in other application as a dynamic database website.

Back to top

Acknowledgements

The Game was completed as a Portfolio 3 Project for the Full Stack Software Developer Diploma at the Code Institute. As such I would like to thank the web in general for beeing such an open library for learning, the Slack community for the good vibes and my mentor Precious_Mentor for the support.

This material has been prepared for educational purposes only.

Damien B.

Back to top

About

Portfolio 3 Project for the Full Stack Software Developer Diploma at the Code Institute.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published