Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

p33t00/py-game

Repository files navigation

Game Manual:

Run App:

The only requirement for running the game is python. Than in order to start the app, run:

python main.py

Start:

Initial command is start It is used to initialize game values and setup Player and Bot

r is used to restart game scores.

Player can refer to help manual in the game by typing 'help' command.

Roll/Stop:

Player shall roll the dice by using z command. When Player decides to stop the turn and score points, x command is used.

Player Statistics:

Players can view their statistics anytime, using the command stats It will display the statistics for the Player.

Cheat:

Player can set a value by which his/her roll score will be multiplied.

cheat 10

This way every time Player rolls the dice, result will be multiplied by 10

Change Name:

A Player can change their name, whenver they wish to, using c command, which will let the player to enter a new name. Doing this, all the tracks of their old name will be replaced with the new name.

Bot (Robot):

Intelligence of Bot is being selected on game initialization (start command) Also it is possible to change Bot intelect level anytime by using command:

b

This will let Player change Bot intelligence level and will restart game.

Exit:

In order to exit the game, exit command can be used.

Unit Testing

Our project uses unittests and pytests to cover different functionality. Each is executed and presents statitstics separately. That means, when you run pytests, unittests are not executed and not included in the stats.

Setup Testing env:

  1. Run make venv PYTHON={your_python_command} to install python virtual environment and follow the instructions on the screen.
  2. Run make install to install dev environment Can Run make installed to view installed packages

App testing

make coverage is used to run and view both pytest and unittest results. Test statistics shall be displayed on the screen and should be avilable in html format in htmlcov/index.html

Checking code compliance

make pylint in order to run pylint. make flake8 to let flake8 check code compliance. make lint to run both above

Generating Documentation

make pdoc will generate code documentation in doc/ directory. make pyreverse will generate UML documentation of the code make doc will run both pdoc and pyreverse and generate the documents.

Development Environment (detailed):

Code style: black

Install dot command:

Install dot command to help generating the UML pictures from the source code structure when using pyreverse. The dot command is part of the package called graphviz and you can install it using your package manager.

Windows, through the "Chocolatey" package manager using for example PowerShell as an Administrator.

choco install graphviz

Mac OS, through the "brew" package manager.

brew install graphviz

Debian (and other Linux), through your package manager.

apt install graphviz

After the installation is done you can check what version you got.

$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)

Read more on Graphiz Project.

Read more on How to install "Chocolatey" on Windows.

Check version of Python

Check what version of Python you have. The Makefile uses PYTHON=python as default.

# Check Python installation
make version

If you have another naming of the Python executable then you can solve that using an environment variable. This is common on Mac and Linux.

# Set the environment variable to be your python executable
export PYTHON=python3
make version

Read more on GNU make.

Python virtual environment

Install a Python virtual environment and activate it.

# Create the virtual environment
make venv

# Activate on Windows
. .venv/Scripts/activate

# Activate on Linx/Mac
. .venv/bin/activate

When you are done you can leave the venv using the command deactivate.

Read more on Python venv.

Install the dependencies

Install the PIP packages that are dependencies to the project and/or the development environment. The dependencies are documented in the requirements.txt.

Do not forget to check that you have an active venv.

# Do install them
make install

# Check what is installed
make installed

Read more on Python PIP.

Run the code

The example program can be started like this.

# Execute the main program
python main.py

All code is stored in directory src/.

Run the validators

You can run the static code validators like this. They check the sourcecode and exclude the testcode.

# Run each at a time
make flake8
make pylint

# Run all on the same time
make lint

You might need to update the Makefile if you change the name of the source directory currently named src/.

Read more on:

Run the unittests

You can run the unittests like this. The testfiles are stored in the test/ directory.

# Run unttests without coverage
make unittest

# Run unittests with coverage
make coverage

# Run pytests without coverage
pytest

# Run pytests with coverage
make coverage

# Run the linters and the unittests with coverage
make test

You can open a web browser to inspect the code coverage as a generated HTML report.

firefox htmlcov/index.html

Read more on:

Run parts of the testsuite

You can also run parts of the testsuite, for examples files or methods in files.

You can run all tests from a testfile.

# Run a testfile
python -m unittest test.test_game
pytest tests/pytests/Dice_test.py

You can also run a single testcase from a file.

# Run a test method, in a class, in a testfile
python -m unittest test.test_game.TestGameClass.test_init_default_object
pytest tests/pytests/Dice_test.py::TestDice::test_inc_turn_total_score

Remove generated files

You can remove all generated files by this.

# Remove files generated for tests or caching
make clean

# Do also remove all you have installed
make clean-all

Optional targets

These targets might be helpful when running your project.

Codestyle with black

You can unify the codestyle using black. Running black will change your source code to have a codestyle according to black codestyle.

# Same same, different names
make black
make codestyle

Read more on black.

More targets

The Makefile contains more targets, they are however not yet tested on this directory structure.

About

Python learning project. TDD and OOP.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors