Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Hard #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ profile:
help:
PYTHONPATH=. $(PYTHON) wpm --help

hard:
PYTHONPATH=. $(PYTHON) wpm --hard

dump:
PYTHONPATH=. $(PYTHON) tools/dumpdiffs.py

Expand Down
7 changes: 6 additions & 1 deletion wpm/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ def parse_args():
argp.add_argument("--short", default=False, action="store_true",
help="Starts wpm with short texts")


argp.add_argument("--hard", default=False, action="store_true",
help="Typos will restart the game")

argp.add_argument("--monochrome", default=False, action="store_true",
help="Starts wpm with monochrome colors")


opts = argp.parse_args()

if opts.version:
Expand Down Expand Up @@ -274,7 +279,7 @@ def main():
sys.exit(1)

try:
with wpm.game.GameManager(quotes, stats, opts.cpm, opts.monochrome) as gm:
with wpm.game.GameManager(quotes, stats, opts.cpm, opts.monochrome, opts.hard) as gm:
try:
gm.run(to_front=text_ids)
gm.stats.save(opts.stats_file)
Expand Down
7 changes: 6 additions & 1 deletion wpm/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

class GameManager(object):
"""The main game runner."""
def __init__(self, quotes, stats, cpm_flag, monochrome):

def __init__(self, quotes, stats, cpm_flag, monochrome, hard_flag):

self.config = Config()
self.stats = stats
self.cpm_flag = cpm_flag
self.hard_flag = hard_flag
self.average = self.stats.average(self.stats.tag, last_n=10)
self.tab_spaces = None

Expand Down Expand Up @@ -295,6 +298,8 @@ def handle_key(self, key):
# Finished typing?
if self.position == len(self.quote.text):
self.mark_finished()
elif self.hard_flag:
self.reset()
elif self.incorrect + self.position < len(self.quote.text):
self.incorrect += 1
self.total_incorrect += 1
Expand Down