Python library to easily create CLI interactive games to learn or practice new concepts, without having to worry about the game related aspects such as score or timers
Project description
cligame
Lightweight python library to easily create CLI interactive games to learn or practice new concepts, without having to worry about the game related aspects such as score or timers.
Why?
When attempting to learn something quickly, it is often useful to quiz oneself repeatedly. This library makes life easier by abstracting away the elements surrounding the game itself, such as score, mistakes, streaks, time, etc.
With this library, it is easy and frictionless to quickly create a CLI game and start training as soon as possible, knowing that the user experinence will be consitent and adequate from the get-go.
Modes
The currently supported game modes are as follows:
- Timed mode. Game ends when timer runs out.
- Number of questions mode. Game ends after certain number of questions, regardless of right or wrong answer.
- Score mode. Game ends when a certain score is reached.
- Mistake mode. Game ends after a certain number of errors are made.
- Consecutive mode. Game ends after correctly answering a determined number of questions in a row.
Usage
- install the library:
pip install cligame
- create a script that asks questions based on your logic
### myscript.py ###
from cligame import Game
from random import randint
# create a function with the following signature: (bool) => (bool, str)
# in this example we ignore the bool that is passed in
def ask_question(_):
x, y = randint(1, 10), randint(1, 10)
ans = input(f"What is {x} + {y}? ")
correct_ans = str(x + y)
return ans == correct_ans, correct_ans
# initizlize a Game object with that function, and start the game
mygame = Game(ask_question)
mygame.start()
- run the script:
python myscript.py
That's it! Upon running the program, you will be prompted to choose a game mode and will be quizzed accordingly.
Explanation
The user must provide a function that:
- takes in a boolean
repeat
- this indicates if the same question as last time should be asked again
- for now, this functionallity must be implemented by the user
- returns a boolean and a string
- the boolean indicates whether the correct answer was given
- the string represents either the correct answer or an explanation on how to get the correct answer.
- this will be shown to the user upon a wrong answer unless
noexplain
is enabled.
- this will be shown to the user upon a wrong answer unless
Let's see a more complete example of the above function
x, y = randint(1, 10), randint(1, 10)
def ask_question(repeat):
global x, y
if not repeat:
x, y = randint(1, 10), randint(1, 10)
ans = input(f"What is {x} + {y}? ")
correct_ans = str(x + y)
return ans == correct_ans, f"the correct answer was '{correct_ans}', but '{ans}' was given"
Command-line arguments
(run python myscript.py --help
to see all options)
Once you've become familiar with the different game modes, you can quick-start a game by passing command-line arguments:
python myscript.py t 5
will start a 5 minute game.python myscript.py c 10
will start a game that ends after correctly answering 10 questions in a row.
Further configuration
You can customize different aspects of the game using the following flags:
-E
or--noexplain
to disable explanations. Upon answering a question incorrectly, the correct answer won't be shown.-q
or--quiet
to disable feedback. After answering a question, there will be no indication whether the answer was correct or not (impliesnoexplain
)-r
or--repeat
to enable repetition. Upon answering a question incorrectly, the same question will be asked until the correct answer is given. Currently, this must be handled by the function created by the user, as indicated by therepeated
argument (impliesnoexplian
)
Stats logging
If you want to keep track of your performance to track your progress over time, call the save_raw
function after the game is done:
mygame = Game(ask_question)
mygame.start()
mygame.save_raw("my_stats.json")
- If no filename is provided, "stats.json" will be used by default
- if using this package with multiple games, be careful to store the stats in different files!
In the future, this package will implement modules to analize the resulting output
TODO
- move
repeat
to game logic - configuration without command-line arguments
- add submodes
- add more stats logging options
- add stats analizer
- add spaced repetition
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cligame-0.2.2.tar.gz
.
File metadata
- Download URL: cligame-0.2.2.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91cabf54f8bdf2f83aa14692682a444a62662e04421908575eba51d68b946115 |
|
MD5 | 59ef3e8f7284fcb572fe744d0a0a9b11 |
|
BLAKE2b-256 | 28d767b41fd949eab484d4d0ab083d2fe11214b4014262b818019ab7fdc87b53 |
File details
Details for the file cligame-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: cligame-0.2.2-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a3737ed6d6e9c9d5c82dd8a63a0372ff85016835f6ac477c0e9f63e647a0241 |
|
MD5 | 1dee4b80bc14a801b4cbd219f43f3e98 |
|
BLAKE2b-256 | 57e69621aa2261ca0177e1ee4a31ce35456b8e0c1ae918d467c1d688591eb835 |