-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added scores.txt to gitignore - added function validate_str_in_list_case_insensitive to input_validation
- Loading branch information
1 parent
3196b89
commit e818056
Showing
7 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,3 +162,4 @@ cython_debug/ | |
#.idea/ | ||
|
||
credentials.py | ||
scores.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from flask import Flask | ||
import utils | ||
|
||
|
||
score_website: Flask = Flask(__name__) | ||
|
||
|
||
@score_website.route('/') | ||
def main_page() -> str: | ||
with open(utils.scores_file_name) as scores_file: | ||
score: str = scores_file.read() | ||
|
||
# try to parse score. if passes, display score on web page, of not, display erroron web page. | ||
try: | ||
int(score) | ||
return f''' | ||
<html> | ||
<head> | ||
<title> Scores Game</title> | ||
</head> | ||
<body> | ||
<h1>The score is:</h1> | ||
<div id="score">{score}</dev> | ||
</body> | ||
</html>''' | ||
except ValueError as error: | ||
return f''' | ||
<html> | ||
<head> | ||
<title>Scores Game</title> | ||
</head> | ||
<body> | ||
<h1>ERROR :< /h1> | ||
<div id="score" style="color:red">{error}</div> | ||
</body> | ||
</html>''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import utils | ||
import input_validation | ||
|
||
|
||
def add_score(difficutly_number: int) -> None: | ||
points: int = (difficutly_number * 3) + 5 | ||
|
||
with open(utils.scores_file_name, 'r+') as scores_file: | ||
score_file_value: str = scores_file.read() | ||
|
||
if score_file_value: | ||
previous_score: int = 0 | ||
try: | ||
# parse save file | ||
previous_score = int(score_file_value) | ||
except ValueError: | ||
# save file is corrupted, let user choose between clearing the score file or quitting the program | ||
options: tuple[str, ...] = ('y', 'yes', 'n', 'no') | ||
default_option: str = 'n' | ||
|
||
while True: | ||
user_input: str = input( | ||
'Score file is corrupted, would you like to clear it? [yes/No]: ') | ||
user_selection = input_validation.validate_str_in_list_case_insensitive( | ||
user_input, options, default_option, input_not_in_list_prompt='Invalid input.') | ||
|
||
if user_selection is None: | ||
break | ||
|
||
match user_input.casefold(): | ||
case 'y' | 'yes': | ||
# clear file and set score to 0 | ||
scores_file.write('') | ||
previous_score = 0 | ||
break | ||
case 'n' | 'no': | ||
print('Quitting.') | ||
quit() | ||
else: | ||
previous_score: int = 0 | ||
|
||
score: int = previous_score + points | ||
|
||
scores_file.seek(0) | ||
scores_file.write(str(score)) | ||
scores_file.truncate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
scores_file_name = 'Scores.txt' | ||
|
||
bad_return_code = 500 | ||
|
||
|
||
def clear_screen() -> None: | ||
print('\x1b[2J') | ||
|