|
import random |
|
from words import words |
|
|
|
class WordGame: |
|
|
|
def __init__(self): |
|
self.points = 0 |
|
self.target_word = "" |
|
self.attempts = 3 |
|
self.generate_task() |
|
|
|
def generate_task(self): |
|
self.attempts = 3 |
|
self.target_word = random.choice(words) |
|
|
|
return self.target_word |
|
|
|
def check_input_for_word(self, string): |
|
if self.target_word in string.lower(): |
|
|
|
self.generate_task() |
|
self.points -= 1 |
|
|
|
return True |
|
|
|
else: |
|
|
|
return False |
|
|
|
def check_output_for_word(self, string): |
|
|
|
if self.target_word in string.lower(): |
|
self.points += self.attempts |
|
|
|
score_gained = self.attempts |
|
self.generate_task() |
|
return f"Success! You earned {score_gained} points!" |
|
|
|
else: |
|
|
|
self.attempts -= 1 |
|
|
|
if self.attempts <= 0: |
|
self.generate_task() |
|
|
|
return f"You did not win in three attempts. Generating new target word." |
|
|
|
else: |
|
|
|
return "That didn't quite hit the mark. Try again!" |
|
|
|
def update_status(self, message=""): |
|
return f'Current score: {self.points}\nRemaining attempts: {self.attempts}\nTarget word: "{self.target_word}"\n{message}' |