Giter VIP home page Giter VIP logo

rpsgame's Introduction

Rock, Paper, Scissors... And How

Hello. If you've arrived here, you may be either wanting to play a Rock, Paper, Scissors game, or see how to create one using Python. If either (or both) of those things are correct, then you're in the right place.

This game is built on FastAPI. It allows two players (or one vs a computer) to engage in a friendly game of Rock, Paper, Scissors and can be played through a web browser.

Install

To start, fork the repository from source. Then, clone (or download) the fork locally.

Navigate to your local repository at the project root. Something like:

cd rps-game

Setup Project

Create and activate a new virtual environment. It will be some variation of this, depending on operating system:

python -m venv .venv
.venv/Scripts/activate

Make sure that your virtual environment is activated, then install the dependencies:

python -m pip install -r requirements.txt

Give It A Spin

You can run a FastAPI application locally by using uvicorn. It will run in your local host, aka http://localhost:8000/

The uvicorn command is the following:

uvicorn app.main:app --reload

The --reload flag will refresh the page any time you make changes to the code base.

To Do

This project is very much unfinished. A few enhancements are listed under the Issues, but at a high level, still need to:

  • Finalize the "Results" page and ensure the database is being updated accordingly for tracking purposes.
  • Add a little window-dressing to the Jinja/HTML templates (CSS and maybe htmx)
  • Fix and add tests
  • Review, update, and add documentation where needed

License

MIT

rpsgame's People

Watchers

 avatar

rpsgame's Issues

Fix the results_post route

Description

The app/routes/game.py module has a route specific to displaying the results. It's supposed to receive form data from the most recent game played and update the database results. I was having an issue updating the game history. I was trying to append to a list, but forgot that TinyDB doesn't like the list type, so I switched to saving the history in a sub-dictionary key-value pair, and added a field to the db entry for total number of games to serve as the dictionary keys.

The logic has been mostly fixed, but the jinja template still needs to be built.

Tasks

  • Update tests for the results_post route
  • Handle expected exceptions
  • Ensure feature is working for both 1 and 2 players
  • Create basic Jinja template and call it results.html

Add save_file functionality

Description

So far, the game will continue tracking games based on the auto-generated save-file name given by the game engine. Would like to add functionality for the user to add their own save-file name, but only after a "new" game has been created. If a game is loaded from a previous save, the user should not have the ability to change the save file name. Also, I would like to add the ability to delete a save file as well.

Error Handling - Need to add better user feedback

Description

Right now, there is no error handling on the front end. On the backend, pydantic is doing a lot of the validating, but need to do another pass at some of the edge cases. In addition, need to provide visual cues or immediate feedback to user when they enter an invalid entry. Right now the user_action is safeguarded, but when entering a wrong value in the frontend form returns a pydantic error to the browser.

Scenario

Employee enters a wrong or invalid letter while playing the game. When submitting form, the browser should route user either to a useful error page, or provide immediate feedback, and not allow the user to submit in the first place.

Opportunity

This might be a great place to add HTMX for some light js-like features.

Add CSS styling to html

Description

The UI is ugly. Need to add some CSS. Creating a simple file from scratch shouldn't be too difficult, but may be a good time to try (and learn) to use Tailwind.

Update test coverage

Description

Started doing okay with test coverage but got sidetracked. Approaching close to 100% test coverage should not be too difficult, but need to think about mocking the db data.

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.