7 from pygame.locals import *
10 from threading import Thread
20 screen = pygame.display.set_mode((2*Wid*Size,Hei*Size))
32 self.rect = pygame.Rect(0,0,Size,Size)
38 self.colors = [white for x in range(4)]
41 self.horizontal = True
42 self.left,self.top = Pos
45 i = random.randint(0,4)
49 self.colors[x] = green
53 self.colors[x] = yellow
55 self.colors[x] = purple
56 def assign(self,source):
57 self.horizontal = source.horizontal
58 self.left = source.left
60 self.colors[x] = source.colors[x]
68 self.time = pygame.time.get_ticks()
70 self.terminate = False
79 self.rect = pygame.Rect(0,0,Wid*Size,Hei*Size)
80 self.strings = [[Ball() for y in range(Hei)] for x in range(Wid)]
83 self.strings[x][y].rect.move_ip(x*Size,y*Size)
85 def checkindex(self,index):
89 if self.strings[x][y].index == index:
93 def assign(self,source):
96 self.strings[x][y].color = source.strings[x][y].color
99 if x < 0 or x > Wid-1 or y < 0 or y > Hei-1:
103 yield self.strings[x][y-1].index
105 yield self.strings[x-1][y].index
107 yield self.strings[x+1][y].index
109 yield self.strings[x][y+1].index
115 def __init__(self,ground):
124 k.extend(self.make())
130 self.strings.append(s)
131 if len(self.strings) > 0:
133 if self.count == 0 and len(self.strings) == 0:
140 s = [x for x in range(Wid)]
141 for x in range(self.count):
142 y = random.randint(0,len(s)-1)
152 for x in self.strings:
153 if x.top < Hei-1 and self.ground.strings[x.left][x.top+1].color == white:
156 s = self.ground.strings[x.left][x.top]
159 self.strings.remove(x)
161 def delete(self,index):
164 if self.ground.strings[x][y].color == self.color:
166 k.extend(self.ground.check(x, y))
169 s = self.ground.strings[x][y]
176 self.ground = Ground()
178 self.system = System()
179 self.ojama = Ojama(self.ground)
182 screen.fill(white,pygame.Rect(self.ground.rect))
185 s = self.ground.strings[x][y]
187 pygame.draw.ellipse(screen,s.color,s.rect)
188 if self.item.visible == True:
190 if self.item.horizontal == True:
191 pygame.draw.ellipse(screen,self.item.colors[x],self.ground.strings[self.item.left+x-1][self.item.top].rect)
193 pygame.draw.ellipse(screen,self.item.colors[x],self.ground.strings[self.item.left][self.item.top-x+1].rect)
194 for x in self.ojama.strings:
195 pygame.draw.ellipse(screen,self.ojama.color,self.ground.strings[x.left][x.top].rect)
196 pygame.display.update(self.ground.rect)
197 pygame.display.update(pygame.draw.line(screen,(0,0,0),(Wid*Size,0),(Wid*Size,Hei*Size)))
199 def put(self,buf=False):
200 self.item.visible = False
202 if self.item.horizontal == True:
203 self.ground.strings[self.item.left+x-1][self.item.top].color = self.item.colors[x]
205 self.ground.strings[self.item.left][self.item.top-x+1].color = self.item.colors[x]
206 self.system.count = 0
207 self.system.rensa = 0
209 self.system.group = 0
213 pygame.time.delay(Sleep)
215 k.extend(self.remove())
221 if self.drop() == False:
226 def ojamashoot(self):
227 while self.ojama.shoot() == False:
229 pygame.time.delay(Sleep)
232 if self.system.rensa > 0:
233 self.system.rensa -= 1
234 if self.ojama.count > 0:
235 if self.ojama.count > self.system.rensa:
236 self.ojama.count -= self.system.rensa
239 self.system.rensa -= self.ojama.count
243 com.ojama.count += self.system.rensa
246 self.system.index = 1
249 self.ground.strings[x][y].index = 0
252 s = self.ground.strings[x][y].color
253 if s != white and s != self.ojama.color:
254 self.system.color = self.ground.strings[x][y].color
255 if self.mapindex(x,y) == True:
256 self.system.index += 1
257 for w in range(1,self.system.index):
258 m = self.ground.checkindex(w)
260 self.system.group += 1
262 self.system.count += m
263 self.system.rensa += 1
266 def delete(self,index):
269 m = self.ground.strings[x][y]
276 self.system.count = 0
277 self.system.group = 0
278 self.ojama.strings = []
281 s = self.ground.strings[x][y]
286 def mapindex(self,x,y):
287 if x < 0 or x > Wid-1 or y < 0 or y > Hei-1:
289 s = self.ground.strings[x][y]
290 if s.index == 0 and s.color == self.system.color:
291 self.ground.strings[x][y].index = self.system.index
292 self.mapindex(x-1,y-1)
294 self.mapindex(x-1,y+1)
297 self.mapindex(x+1,y-1)
299 self.mapindex(x+1,y+1)
307 for y in range(Hei-1,0,-1):
308 if self.ground.strings[x][y].color == white:
309 for w in range(y-1,0,-1):
310 if self.ground.strings[x][w].color != white:
314 for w in range(y,1,-1):
315 m = self.ground.strings[x][w]
316 n = self.ground.strings[x][w-1]
320 m = self.ground.strings[x][0]
342 def turn(self,boolean=True):
343 self.item.horizontal = not self.item.horizontal
344 if (boolean == True and self.item.horizontal == True)or(boolean == False and self.item.horizontal == False):
345 x,y = self.item.colors[0],self.item.colors[1]
346 self.item.colors[0],self.item.colors[1]= self.item.colors[3],self.item.colors[2]
347 self.item.colors[3],self.item.colors[2] = x,y
350 if self.item.horizontal == True:
351 if self.item.left-1 < 0 or self.item.left+2 > Wid-1 or self.item.top < 0 or self.item.top > Hei-1:
354 if self.item.left < 0 or self.item.left > Wid-1 or self.item.top-2 < 0 or self.item.top+1 > Hei-1:
357 if self.item.horizontal == True:
358 if self.ground.strings[self.item.left+x-1][self.item.top].color != white:
361 if self.ground.strings[self.item.left][self.item.top-x+1].color != white:
365 def shoot(self,buf=False):
366 while self.move(K_DOWN) == True:
369 pygame.time.delay(Sleep)
374 class ComPlayer(Player):
376 Player.__init__(self)
377 self.buffer = Ground()
379 self.ground.rect = pygame.Rect(Wid*Size,0,2*Wid*Size,Hei*Size)
382 self.ground.strings[x][y].rect.move_ip(Wid*Size,0)
385 self.buffer.assign(self.ground)
386 if self.checkitem() == False:
388 self.__vir.assign(self.item)
392 if game.terminate == True:
395 self.ground.assign(self.buffer)
397 self.item.left,self.item.top = Pos
398 self.item.visible = True
400 if self.item.horizontal != self.__vir.horizontal:
404 if self.item.colors[x] != self.__vir.colors[x]:
410 while self.item.left < self.__vir.left:
413 while self.item.left > self.__vir.left:
419 if self.__score >= 100:
423 if game.terminate == True:
425 self.ground.assign(self.buffer)
426 self.item.left,self.item.top = x,3
427 if self.checkitem() == False:
430 if self.system.count > high:
431 self.__vir.assign(self.item)
434 m = self.system.group*10+self.system.count
437 self.__vir.assign(self.item)
441 man.ojama.count += self.system.rensa
445 Thread.__init__(self)
449 while game.terminate == False:
450 if com.item.visible == True:
455 if com.checkitem() == False:
464 pygame.display.set_caption("")
465 while game.terminate == False:
466 while timer() == True:
469 pygame.time.delay(Sleep*500)
473 for event in pygame.event.get():
474 if event.type == QUIT:
476 elif event.type == KEYDOWN:
477 if event.key == K_ESCAPE:
479 if man.item.visible == False:
481 if event.key == K_UP:
483 if man.checkitem() == False:
485 elif event.key == K_DOWN:
491 temp = pygame.time.get_ticks()
492 if game.time+game.interval > temp:
495 if man.item.visible == True:
496 if man.move(K_DOWN) == False:
502 if man.checkitem() == True:
508 def gameover(sender):
513 pygame.display.set_caption(s+' WIN!!')
514 game.terminate = True