-
Notifications
You must be signed in to change notification settings - Fork 1
/
line.py
121 lines (103 loc) · 2.89 KB
/
line.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
from copy import copy
from math import ceil
import pygame as pg
from prisoner import Prisoner
from rect import *
class Line(Rect):
def __init__(self):
super().__init__()
self.prisoners=[]
self.total=0
self.x_spc=2
self.y_spc=2
self.cols=0
self.rows=0
self.win_h=0
def RoomSize(self,w,h):
self.SetSize(w-150,h-20)
def SetWinHeight(self,h):
self.win_h=h
self.SetSize(0,h)
self.DistributePrisoners()
def SetTotal(self,total):
if(total==0):
return
self.total=total
self.prisoners.clear()
for n in range(1,total+1):
self.prisoners.append(Prisoner())
self.prisoners[-1].SetNumber(n)
self.prisoners[-1].SetMaxAttempts(total//2)
self.CalcSize()
def Fill(self):
for n in range(1,self.total+1):
self.prisoners[n-1].SetNumber(n)
self.prisoners[n-1].SetMaxAttempts(self.total//2)
def CalcSize(self):
self.rows=self.win_h//self.prisoners[-1].h
self.cols=ceil(self.total/self.rows)
w=self.cols*(self.prisoners[-1].w+self.x_spc)
h=self.rows*(self.prisoners[-1].h+self.y_spc)
self.SetSize(w,h)
self.fg_surf=pg.Surface(self.size,pg.SRCALPHA)
self.bg_surf=pg.Surface(self.size,pg.SRCALPHA)
def IncrementTotal(self):
self.total=self.total+1
self.prisoners.append(Prisoner())
self.prisoners[-1].SetNumber(self.total)
# self.SetTotal(self.total+1)
self.DistributePrisoners()
self.CalcSize()
def DecrementTotal(self):
if(self.total-1>=1):
self.total=self.total-1
self.prisoners.pop(-1)
# self.SetTotal(self.total-1)
self.DistributePrisoners()
self.CalcSize()
def Click(self,pos):
mx,my=pos
mx=mx-self.x
my=my-self.y
for p in self.prisoners:
if(p.GetClick((mx,my))):
return(p)
return(None)
def DistributePrisoners(self):
x=self.x_spc
y=self.y_spc
r=1
for p in self.prisoners:
p.SetPos(x,y)
y=y+self.y_spc+p.h
if(r==self.rows):
y=self.y_spc
x=x+self.x_spc+p.w
r=0
r=r+1
self.LoadBgTileImg("imgs//tile_brick.png",self.w,self.h)
def RemPrisoner(self,p):
self.prisoners.remove(p)
def AddPrisoner(self,p):
np=copy(p)
self.prisoners.append(np)
self.prisoners[-1].SetNumber(p.number)
self.total=self.total+1
self.CalcSize()
self.DistributePrisoners()
def Clear(self):
self.prisoners.clear()
self.Render()
def Reset(self):
self.SetTotal(self.total)
self.DistributePrisoners()
self.Render()
def RightAlign(self,w):
x=(w-self.w)
self.SetPos(x,self.y)
def Render(self):
# self.FillBgColor()
self.FillFgColor()
for p in self.prisoners:
p.Render()
p.Draw(self.fg_surf)