/
main.py
73 lines (69 loc) · 1.99 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
__author__ = "n3rdkeller.de"
__license__ = "GPL"
__version__ = "0.9"
__email__ = "github@n3rdkeller.de"
__status__ = "Development"
# imports
import ui
from sudoku import Sudoku # importing class
from sudoku import EMPTY_SUDOKU
from sudoku import ERROR
from sudoku import COLORS
# -----
# functions
# -----
def main():
ui.mainmenu()
s = Sudoku()
print(s.get_str())
while True:
command = ui.input_command()
if command[0] == 0:
# ADD
args = ui.parse_add(command[1])
if s.check_number(args[0], args[1], args[2]) == []:
s.add_number(args[0], args[1], args[2])
else:
print("The number you tried to add does not fit the rules.")
print("Please try again.")
continue
elif command[0] == 1:
# DEL
args = ui.parse_del(command[1])
s.del_number(args[0], args[1])
elif command[0] == 2:
# SAVE
if not s.save(command[1]):
continue
elif command[0] == 3:
# LOAD
if not s.load(command[1]):
continue
elif command[0] == 4:
# CHK
if s.check():
print(COLORS["green"] + "Your Sudoku seems right.\n" + \
COLORS["clear"])
else:
print(COLORS["red"] + COLORS["bell"] + \
"Your Sudoku is wrong.\n" + COLORS["clear"])
continue
elif command[0] == 5:
# HELP
ui.parse_help(command[1])
continue
elif command[0] == 6:
# QUIT
print("Quitting game...")
exit()
elif command[0] == 7:
# NEW
s.set_numbers(EMPTY_SUDOKU)
elif command[0] == ERROR:
# ERROR
print("Unknown command. Please try again.")
continue
ui.clear_screen()
print(s.get_str())
if __name__ == '__main__':
main()