-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmain.py
151 lines (128 loc) Β· 5.62 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import random
import os
values = {'a' : 0, 'b' : 1, 'c' : 2, 'd' : 3, 'e' : 4, 'f' : 5, 'g' : 6, 'h' : 7}
table_heading = {65:"A", 66:"B", 67:"C", 68:"D", 69:"E", 70:"F", 71:"G", 72:"H"}
temp_found = []
user_values = []
user_choices = []
progress = True
competed = False
def game_elements(num):
lst = []
while len(lst) < num:
row = []
while len(row) < num:
random_number = random.randint(65,73)
if random_number not in row:
row.append(chr(random_number))
lst.append(row)
element = row.copy()
random.shuffle(element)
lst.append(element)
return lst
def game_process(num):
global user_values
global temp_found
global competed
def game_table(list_with_spaces):
char_count = 65
if user_choice_data == 2:
print(" 0 1 ")
print(" |---------|---------|")
for i in range(2):
print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} |")
print(" |---------|---------|")
char_count += 1
if user_choice_data == 4:
print(" 0 1 2 3 ")
print(" |---------|---------|---------|---------|")
for i in range(4):
print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} |")
print(" |---------|---------|---------|---------|")
char_count += 1
if user_choice_data == 6:
print(" 0 1 2 3 4 5 ")
print(" |-------|-------|-------|-------|-------|-------|")
for i in range(6):
print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} | {list_with_spaces[i][4]} | {list_with_spaces[i][5]} |")
print(" |-------|-------|-------|-------|-------|-------|")
char_count += 1
if user_choice_data == 8:
print(" 0 1 2 3 4 5 6 7 ")
print(" |-------|-------|-------|-------|-------|-------|-------|-------|")
for i in range(8):
print(f"{table_heading[char_count]} | {list_with_spaces[i][0]} | {list_with_spaces[i][1]} | {list_with_spaces[i][2]} | {list_with_spaces[i][3]} | {list_with_spaces[i][4]} | {list_with_spaces[i][5]} | {list_with_spaces[i][6]} | {list_with_spaces[i][7]} |")
print(" |-------|-------|-------|-------|-------|-------|-------|-------|")
char_count += 1
list_with_spaces = [[' ' for _ in sublist] for sublist in main]
while progress:
os.system('cls')
game_table(list_with_spaces)
trial = 0
for i in range(2):
if len(user_choices) == (num**2):
competed = True
break
opn = input("\nEnter the tile to uncover: ")
while opn in user_choices:
print("\n===========>>>You have already completed this tile!")
opn = input("\nEnter the new tile to uncover: ")
user_values.append(opn)
index_1 = values[opn[0]]
index_2 = int(opn[1])
temp_found.append(main[index_1][index_2])
list_with_spaces[index_1][index_2] = main[index_1][index_2]
game_table(list_with_spaces)
trial += 1
if trial == 2:
user_input = input("\n===========>>> Press (Enter) to Continue: ")
trial = 0
if competed:
print("\n===========>>> You Won! <<<===========")
break
elif temp_found[0] == temp_found[1]:
for i in range(2):
user_choices.append(user_values[i])
index_1 = values[user_values[i][0]]
index_2 = int(user_values[i][1])
list_with_spaces[index_1][index_2] = "βοΈ"
user_values = []
temp_found = []
else:
for i in range(2):
index_1 = values[user_values[i][0]]
index_2 = int(user_values[i][1])
list_with_spaces[index_1][index_2] = " "
user_values = []
temp_found = []
while True:
user_choice_data = input("""
For '2x2' enter "EASY"
For '4x4' enter "MEDIUM"
For '6x6' enter "HARD"
For '8x8' enter "EXTREME"
Enter your choice: """).lower()
while user_choice_data not in ["easy", "medium", "hard", "extreme"]:
os.system("cls")
user_choice_data = input("""
For '2x2' enter "EASY"
For '4x4' enter "MEDIUM"
For '6x6' enter "HARD"
For '8x8' enter "EXTREME"
Enter your choice: """).lower()
if user_choice_data == "easy":
user_choice_data = 2
if user_choice_data == "medium":
user_choice_data = 4
if user_choice_data == "hard":
user_choice_data = 6
if user_choice_data == "extreme":
user_choice_data = 8
main = game_elements(user_choice_data)
process = game_process(user_choice_data)
choice = input("Do you want to play the game again? (y/n): ").lower()
while choice not in ["y", "n"]:
print("\n Invalid choice")
choice = input("Do you want to play the game again? (y/n): ")
if choice == "n":
break