-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.py
More file actions
94 lines (86 loc) · 4.15 KB
/
Copy pathcard.py
File metadata and controls
94 lines (86 loc) · 4.15 KB
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
#the card class
from tkinter import *
# cmu_112_graphics cited from
# http://www.cs.cmu.edu/~112/notes/notes-animations-part1.html
from cmu_112_graphics import *
from utilities import *
class Card(object):
fontSizeRatio = 0.3
nameSizeRatio = 0.15
cardCount =0
def __init__(self, name = 'none', cost = 0, stats = (0,0), effect = 'none', image = None):
#card Stuff
self.name = name
self.cost = cost
self.attack = stats[0]
self.maxLife = stats[1]
self.curLife = self.maxLife
self.effect = effect
self.selected = False
Card.cardCount += 1
self.x = -1 # -1 indicates not visible on the board
self.y = -1
self.id = self.cardCount #even identical cards stat wise are unique
self.summoningSickness = True
self.attackedThisTurn = False
self.target = False
def __repr__(self):
return f'{self.name}: cost:{self.cost}, attack:{self.attack}, life:{self.life}'
def getCardZones(self, width, color):
cardImg = getCardImage(self.name)
fontSize = int(width * Card.fontSizeRatio)
nameFontSize = int(width * Card.nameSizeRatio)
nameImg = getCustomFontText(str(self.name), nameFontSize, color)
statImg = getCustomFontText(str(self.attack) + ' ' + str(self.curLife), fontSize, color)
effectImg = getCustomFontText(self.effect, nameFontSize, color)
costColor = color
if self.summoningSickness:
costColor = 'Green'
costImg = getCustomFontText(str(self.cost), fontSize, costColor)
return nameImg, statImg, effectImg, costImg, cardImg
def drawCard(self, canvas, width, outline):
zones = self.getCardZones(width, outline)
height = 2 * width
if self.selected:
outline = 'yellow'
elif self.target:
outline = 'light green'
elif self.attackedThisTurn == True:
outline = 'white'
else:
outline = outline
fillColor = 'black'
font = 'system ' + str(int(width * Card.fontSizeRatio))
nameFont = 'system ' + str(int(width * Card.nameSizeRatio))
canvas.create_rectangle(self.x - (width/2), self.y - (height/2), self.x + (width/2), self.y + (height/2),
fill = fillColor, outline = outline, width = 6)
#canvas.create_text(self.x - (width/2), self.y - (height/2), text = str(self.cost), font = font, fill = costColor, anchor = 'nw')
canvas.create_image(self.x - (width/2) + 6, self.y - (height/2) + 6, image = getCachedPhotoImage(zones[3]), anchor = 'nw')
#canvas.create_text(self.x, self.y - (3/8) * height, text = self.name, font = nameFont)
canvas.create_image(self.x, self.y - (3/8) * height, image = getCachedPhotoImage(zones[0]))
canvas.create_image(self.x, self.y + (1/3) * height, image = getCachedPhotoImage(zones[1]))
#canvas.create_text(self.x - (width/4), self.y + (height/4), text = str(self.attack), font = font)
#canvas.create_text(self.x + (width/4), self.y + (height/4), text = str(self.curLife), font = font)
#canvas.create_text(self.x, self.y, text = self.effect, font = nameFont)
canvas.create_image(self.x,self.y + (1/4) * height, image = getCachedPhotoImage(zones[2]))
if zones[4] != None:
canvas.create_image(self.x,self.y, image = getCachedPhotoImage(zones[4]))
def createCardFromString(self, string):
components = string.split(':')
self.name = components[0]
self.cost = int(components[1])
self.attack = int(components[2])
self.maxLife = int(components[3])
self.curLife = int(components[4])
self.effect = components[5]
self.selected = (components[6] == 'True')
self.x = int(components[7])
self.y = int(components[8])
self.id = int(components[9])
self.summoningSickness = (components[10] == 'True')
self.attackedThisTurn = (components[11] == 'True')
def __repr__(self):
string = ''
for key in self.__dict__:
string = string + str(self.__dict__[key]) + ':'
return string