-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepertoire.py
255 lines (227 loc) · 9.53 KB
/
repertoire.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#Beginning of imports
import os
import platform
#End of imports
#Beginning of stable variables
sys = platform.system()
#End of stable variables
###============ Database Updating ============###
exec(open("updates/DatabaseVersion.py").read())
###========== Database Updating end ==========###
def RemplirSets(filename, ListeSets):
file = open(filename, "r")
lines = file.readlines()
sets = []
for i in lines:
name, code, baseSetSize = i.split(',')
sets.append(name)
sets.append(code.replace("\n", ""))
ListeSets.append(sets)
sets = []
file.close()
def RemplirCartes(nomFichier, liste):
fichier = open(nomFichier, "r")
lines = fichier.readlines()
card = []
for i in lines:
if len(i.split('"')) == 5:
code, rarity, name, mana, category = i.split('"')
elif len(i.split('"')) == 6:
code, rarity, name, mana, category, strenght = i.split('"')
card.append(code)
card.append(rarity)
card.append(name)
card.append(mana)
card.append(category.replace("\n", ""))
if len(i.split('"')) == 6:
card.append(strenght.replace("\n", ""))
liste.append(card)
card = []
fichier.close()
def ColorTest(ManaCost):
color1 = ManaCost[3].replace('B',' Black')
color2 = color1.replace('U',' Blue')
color3 = color2.replace('W',' White')
color4 = color3.replace('R',' Red')
color5 = color4.replace('G',' Green')
return(color5)
def namesearch(deck, names):
cards = []
for x in deck:
if names in x[2].lower().split(' '):
cards.append(x)
for x in deck:
if names in x[2].lower().split("'"):
cards.append(x)
return cards
def ManaCalc(deck,worth):
for x in deck:
card = x
manaColorless1 = x[3].replace('B','')
manaColorless2 = manaColorless1.replace('U','')
manaColorless3 = manaColorless2.replace('W','')
manaColorless4 = manaColorless3.replace('G','')
manaColorless5 = manaColorless4.replace('R','')
OperationManas = manaColorless5.split(' ')
if len(OperationManas) == 1:
if OperationManas[0][:1] == 'X':
ManaValue = 0
elif OperationManas[0].isdigit() == True:
ManaValue = int(OperationManas[0])
elif len(OperationManas) == 2:
if OperationManas[0].isdigit() == True and OperationManas[1].isdigit() == True:
ManaValue = int(OperationManas[0]) + int(OperationManas[1])
elif OperationManas[0] == 'X':
ManaValue = 0 + int(OperationManas[1])
card[3] = str(ManaValue)
if card[3] == worth:
print(card)
elif OperationManas[0] == "X":
if len(OperationManas) >= 2:
if OperationManas[1] <= worth:
print(card)
else:
print(card)
###============== Main Program ==============###
sys = platform.system()
sets = []
RemplirSets("sets/TXT-SetFiles/sets.txt", sets)
while True:
print("\nBienvenue dans l'index des cartes legales de Magic: The Gathering\n")
print("1: Acces a l'inventaire")
print("2: Chercher de l'information sur une carte")
action = input("Que puis-je faire pour toi? ")
if action == "1":
print("\n1. Consulter l'inventaire --> Code et quantité seulement")
print("2. Ajouter / Retirer une carte à l'inventaire")
action = input("Que veux-tu faire? ")
if action == '1':
print("\n1. Chercher une carte par numero")
print("2. Afficher l'ensemble des cartes de l'inventaire (Au moins une possédée")
data = input("Que dois-je chercher? ")
if data == "1":
card = input("\nQuel est le numero de la carte? (série + chiffre --> AAA123) ")
CardSet = card[:3]
CardNumber = card[3:]
try:
if sys == "Linux":
file = open(("inventory/"+CardSet.upper()+".txt"), "r")
elif sys == "Windows":
file = open(("inventory/"+CardSet.upper()), "r")
lines = file.readlines()
print(lines[int(CardNumber)-1])
except FileNotFoundError:
print("Cette entree n'est pas valide, veuillez ressayer")
elif data == "2":
file = open("sets/TXT-SetFiles/sets.txt", "r")
lines = file.readlines()
sets = []
ListeSets = []
PrintedCards = 0
for i in lines:
name, code, baseSetSize = i.split(',')
CardSet = open(("inventory/"+code+".txt"),"r")
CardList = CardSet.readlines()
for Cards in CardList:
CardsClean = Cards.replace("\n","")
CardsSplit = CardsClean.split(' ---> ')
if int(CardsSplit[1]) > 0:
print(CardsClean)
PrintedCards = PrintedCards+1
CardSet.close()
file.close()
if PrintedCards == 0:
print("Aucune carte dans l'inventaire\n")
elif action == '2':
CardID = input("Quel est le numero de la carte? (série + chiffre --> AAA123) ")
CardSet = CardID[:3]
try:
file = open("inventory/"+CardSet+".txt","r")
AllRawCards = file.readlines()
AllCards = []
for RawCard in AllRawCards:
WholeCards = []
WholeCards = RawCard.replace("\n","").split(" ---> ")
AllCards.append(WholeCards)
file.close()
card = AllCards[int(CardID[-3:])-1]
print("Ceci est ta carte:")
print(card)
while True:
confirmation = input("Est-ce bien ta carte? (y/n) ")
if confirmation == "y":
QtyToAdd = int(input("Combien à ajouter / retirer? (Pour retirer, ajouter un moins devant) "))
QtyInInventory = int(card[1])
NewQty = QtyToAdd + QtyInInventory
card[1] = NewQty
break
elif confirmation == "n":
break
else:
print("Cette entrée n'est pas valide, veuillez réessayer")
AllCards[int(CardID[-3:])-1] = card
if sys == "Linux":
file = open("inventory/"+CardSet+".txt","w+")
elif sys == "Windows":
file = open("inventory/"+CardSet+".txt","w+")
for x in AllCards:
FormattedCard = (x[0] + " ---> " + str(x[1]) + "\n")
file.write(FormattedCard)
file.close()
except FileNotFoundError:
print("Ce set n'existe pas, veuillez reessayer")
pass
except ValueError:
print("Cette entree est invalide")
pass
elif action == "2":
for x in range(len(sets)):
print(sets[x][0] + " , " + sets[x][1])
Deckname = input("Set? ")
deck = []
try:
if sys == "Linux":
RemplirCartes(("sets/TXT-SetFiles/" +Deckname.upper()+ ".txt"), deck)
elif sys == "Windows":
RemplirCartes(("sets/TXT-SetFiles/" +Deckname.upper()+ ".txt"), deck)
print('\n1. Par numero\n2. Par rarete\n3. Par nom (Sensible a la casse)\n4. Par cout en manas\n5. Par type ')
information = input('Comment souhaite-tu chercher ta carte? ')
if information == '1':
number = input('Quel est le numero de la carte? ')
card_preliminary = deck[int(number)-1]
card = card_preliminary
card[3] = ColorTest(card)
print("")
print(card)
elif information == '2':
print("\n1. Common\n2. Uncommon\n3. Rare\n4. Mythic")
scarcity = input('Quelle est la rareté de la carte? ')
if scarcity == '1':
ScarcityLetter = 'C'
elif scarcity == '2':
ScarcityLetter = 'U'
elif scarcity == '3':
ScarcityLetter = 'R'
elif scarcity == '4':
ScarcityLetter = 'M'
for x in deck:
if ScarcityLetter in x[1]:
card = x
x[3] = ColorTest(card)
print(card)
elif information == '3':
names = input('Quel est le nom de la carte? ')
card = namesearch(deck, names)
for x in card:
card = x
card[3] = ColorTest(card)
print(card)
elif information == '4':
print('1. Cout brut en manas (i.e 6 manas)')
print('2. Cout detaille (i.e 3 + 2 Bleus)')
quality = input("Comment veux-tu entrer tes manas? ")
if quality == '1':
quantity = input("Combien de manas? ")
ManaCalc(deck,quantity)
except FileNotFoundError:
print("Cette carte / ce set n'existe pas, veuillez reessayer")