-
Notifications
You must be signed in to change notification settings - Fork 0
/
triqui.py
169 lines (151 loc) · 5.83 KB
/
triqui.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
152
153
154
155
156
157
158
159
160
161
162
163
import config.Board as Board
import random, time, os, sys
b = Board._board()
class colorprint:
RED = '\033[91m'
GREEN = '\033[92m'
BOLD = '\033[01m'
END = '\033[0m'
class player:
def __init__(self, players=None):
self.p1_name = players
self.triqui = '''
▀█▀ █▀▄ ▀█▀ ▄▀▀▄ █░░█ ▀█▀
░█░ █▀▄ ░█░ █░▄█ █░░█ ░█░
░▀░ ▀░▀ ▀▀▀ ░▀▀▀ ░▀▀░ ▀▀▀
'''
def Carga(self):
self.c = [
'⚪ ◉ ◉',
'◉ ⚪ ◉',
'◉ ◉ ⚪',
'⚪ ◉ ◉',
'◉ ⚪ ◉',
'◉ ◉ ⚪',
'⚪ ◉ ◉',
'◉ ⚪ ◉',
'◉ ◉ ⚪',
'⚪ ◉ ◉',
'◉ ⚪ ◉',
'◉ ◉ ⚪',
]
for i in self.c:
print(i, end='\r')
time.sleep(.3)
def win(self, num):
global won, your
if num == f'{colorprint.GREEN}x{colorprint.END}':
if b.board['7']==b.board['5']==b.board['3']==num or b.board['9']==b.board['5']==b.board['1']== num:
won = True
nam = player(your)
b.printboard()
print(f'{colorprint.GREEN} Ganaste x felicitacion {nam.p1_name} {colorprint.END}')
time.sleep(5)
elif b.board['7']==b.board['4']==b.board['1']== num or b.board['8']==b.board['5']==b.board['2']==num or b.board['9']==b.board['6']==b.board['3']== num:
won = True
b.printboard()
nam = player(your)
print(f'{colorprint.GREEN} Ganaste x felicitacion {nam.p1_name} {colorprint.END}')
time.sleep(5)
elif b.board['7']==b.board['8']==b.board['9']== num or b.board['4']==b.board['5']==b.board['6']==num or b.board['1']==b.board['2']==b.board['3']== num:
won = True
nam = player(your)
b.printboard()
print(f'{colorprint.GREEN} Ganaste x felicitacion {nam.p1_name} {colorprint.END}')
time.sleep(5)
elif num == f'{colorprint.RED}o{colorprint.END}':
if b.board['7']==b.board['5']==b.board['3']==num or b.board['9']==b.board['5']==b.board['1']== num:
won = True
b.printboard()
print(f'{colorprint.RED} Perdiste el gano computador {num} {colorprint.END}')
time.sleep(5)
elif b.board['7']==b.board['4']==b.board['1']== num or b.board['8']==b.board['5']==b.board['2']==num or b.board['9']==b.board['6']==b.board['3']== num:
won = True
b.printboard()
print(f'{colorprint.RED} Perdiste el gano computador {num} {colorprint.END}')
time.sleep(5)
elif b.board['7']==b.board['8']==b.board['9']== num or b.board['4']==b.board['5']==b.board['6']==num or b.board['1']==b.board['2']==b.board['3']== num:
won = True
b.printboard()
print(f'{colorprint.RED} Perdiste el gano computador {num} {colorprint.END}')
time.sleep(5)
def clear(self):
self.cls = 'cls' if sys.platform.startswith("windows") else 'clear'
os.system(self.cls)
def Games(self):
global count, turno_player, won
won = False
turno_player = True
count = 0
while count != 9 and True != won:
try:
player(self.p1_name).condicion()
except ValueError as e:
print(e)
def condicion(self):
global count, turno_player, readnum
if turno_player:
b.printboard()
print(f'su turno {self.p1_name}')
pl = input('x: ')
if int(pl) > 9:
print('No, debe tener 0 hasta 9 ')
elif b.board[pl] == ' ':
b.board[pl] = f'{colorprint.GREEN}x{colorprint.END}'
count += 1
x = f'{colorprint.GREEN}x{colorprint.END}'
player().clear()
player().win(x)
readnum.remove(pl)
turno_player = False
else:
print(f'\n{colorprint.RED}ops, ya ha cogido antes{colorprint.END}')
else:
b.printboard()
print(f'Su turno Computador inteligencia')
rv = random.choice(readnum)
player().Carga()
if b.board[rv] == ' ':
b.board[rv] = f'{colorprint.RED}o{colorprint.END}'
count += 1
o = f'{colorprint.RED}o{colorprint.END}'
player().clear()
player().win(o)
readnum.remove(rv)
turno_player = True
def yours(self):
si = ['si','Si','SI','sI','yes','Yes','YES']
opcion= input('Quiere poner su nombres: Si/no: ')
if opcion in si:
nombres = input('Por favor escriba su nombre: ')
self.pase= str(nombres)
time.sleep(.5)
player().clear()
else:
self.pase= None
def Repetir(self):
si = ['si','Si','SI','sI','yes','Yes','YES']
print('Quiere jugar otra vez? Si/No')
opcion = input()
if opcion in si:
player().clear()
player().jugar()
def jugar(self):
global readnum, your, intro
print('Bienvenido a nuestro proyecto triqui')
print(colorprint.GREEN)
print(self.triqui)
print(colorprint.END)
time.sleep(3)
player().clear()
readnum = ['1','2','3','4','5','6','7','8','9']
b.limpiar()
self.name = player()
self.name.yours()
your = self.name.pase
self.game = player(your)
self.game.Games()
player().Repetir()
if __name__ == '__main__':
player().jugar()
print('Gracias por jugar :)')