class rainfall(cggframe): def __init__(self): self.cgg=CGGPYG("") self.m=[] for i in range(0,21): for j in range(0,41): self.m[len(self.m):] = [0] for i in range(0,19): r = random.randint(1,10) if r == 1: self.m[1*40 +i] = 1 else: self.m[i*40+ 1] = 0 self.gamestate="play" def draw(self): self.cgg.cls() self.cgg.setcolor(5) for i in range(0,19): for j in range(0,39): if self.m[i*40+j]>0: self.cgg.puth("circle",j,i) def scroll(self): for i in range(0,39): r = random.randint(1,40) self.m[1*40+i] = 0 if r == 1: self.m[1*40+i] = 2 if r == 2: self.m[1*40+i] = 6 for i in range(18,0,-1): for j in range(0,39): self.m[(i+1)*40+j] = self.m[i*40+j] self.draw() def routine(self): self.scroll()
class linetest13(cggframe): def __init__(self): self.x=[10,10,10,11,12,12,12,12,11,10] self.y=[10,11,12,12,12,13,14,15,15,15] self.dx=0 self.dy=-1 self.fx=5 self.fy=5 self.length=8 self.cgg=CGGPYG("") self.gamestate="play" self.timerct=0 pygame.mixer.init() self.beep=pygame.mixer.Sound("po.wav") self.sc=0 def keyin(self,key): if self.gamestate=="play": if key==pygame.K_UP: self.dy=-1 self.dx=0 if key==pygame.K_DOWN: self.dy=1 self.dx=0 if key==pygame.K_RIGHT: self.dx=1 self.dy=0 if key==pygame.K_LEFT: self.dx=-1 self.dy=0 if self.gamestate=="gameover" and key==pygame.K_RETURN: self.gamestate="play" self.__init__() def routine(self): self.timerct=self.timerct+1 if self.timerct==5: self.update() if self.timerct>=10: self.timerct=0 def update(self): self.cgg.cls() for i in range(self.length-1,-1,-1): self.x[i+1]=self.x[i] self.y[i+1]=self.y[i] self.x[0]=self.x[0]+self.dx self.y[0]=self.y[0]+self.dy for i in range(1,self.length+1): if self.x[0]==self.x[i] and self.y[0]==self.y[i]: self.gamestate="gameover" if self.x[0]<=0 or self.x[0]>=39 or self.y[0]<=0 or self.y[0]>=19: self.gamestate="gameover" if self.x[0]==self.fx and self.y[0]==self.fy: self.length=self.length+1 self.beep.play() self.sc=self.sc+1 self.x=self.x+[self.length-1] self.y=self.y+[self.length-1] checkflag=1 while checkflag==1: self.rx=random.randint(2,37) self.ry=random.randint(2,17) checkflag=0 for i in range(0,self.length+1): if self.rx==self.x[i] and self.ry==self.y[i]: checkflag=1 self.fx=self.rx self.fy=self.ry self.cgg.setcolor(1) for i in range(0,40): self.cgg.puth("sharp",i,0) self.cgg.puth("sharp",i,19) for i in range(0,20): self.cgg.puth("sharp",0,i) self.cgg.puth("sharp",39,i) self.cgg.setcolor(7) self.cgg.printc("length:"+str(self.length)+"",0,20) self.cgg.setcolor(4) for i in range(1,self.length): self.cgg.puth("circle",self.x[i],self.y[i]) self.cgg.setcolor(7) self.cgg.puth("circle",self.x[0],self.y[0]) self.cgg.setcolor(3) self.cgg.puth("heart",self.fx,self.fy)
class Grace80(): def __init__(self): self.cgg=CGGPYG("") pygame.mixer.init() self.bgm=pygame.mixer.Sound("pin-fa.wav") self.beep=pygame.mixer.Sound("po.wav") self.curx=20 self.cury=80 self.num=50 self.ct=0 self.m=[0,0] self.gameflag=0 for i in range(0,21): for j in range(0,41): self.m[len(self.m):] = [0] self.gamestate="title" self.msg="" self.sc = 0 self.x = 10 self.y = 18 self.counter=0 self.chaincounter=0 self.chainflag=0 self.k=1 self.m[self.y*40+self.x] = 3 def statemanager(self): if self.gamestate=="title": self.title() if self.gamestate=="play": self.routine() if self.gamestate=="gameover": self.gameover() def title(self): self.cgg.cls() self.cgg.setcolor(7) self.cgg.printc("lost and found the action game",5,5) self.cgg.printc("2018 tenkey aikoukai",5,7) self.cgg.printc("press ret key",5,9) def gameover(self): self.cgg.setcolor(2) self.cgg.printc("game over",15,10) def keyin(self,key): if self.gamestate=="title": if key==pygame.K_RETURN: self.gamestate="play" if self.gamestate=="play": if key==pygame.K_LEFT and self.x >= 1: self.x = self.x - 1 if key==pygame.K_RIGHT and self.x < 39: self.x = self.x + 1 if self.gamestate=="gameover": if key==pygame.K_RETURN: self.__init__() self.gamestate="title" def draw(self): self.cgg.cls() for i in range(0,19): for j in range(0,39): if self.m[i*40+j]==1: self.cgg.setcolor(4) self.cgg.puth("sharp",j,i) if self.m[i*40+j]==2: self.cgg.setcolor(6) self.cgg.puth("circle",j,i) if self.m[i*40+j]==3: self.cgg.setcolor(7) self.cgg.puth("a",j,i) self.cgg.setcolor(7) self.cgg.printc("score "+str(self.sc),2,20) self.cgg.printc(self.msg,2,21) def scroll(self): """scroll screen""" for i in range(18,0,-1): for j in range(0,40): self.m[(i+1)*40+j] = self.m[i*40+j] """enemy generate""" for i in range(0,39): r = random.randint(1,20) if r == 1: self.m[40+i] = 1 else: self.m[40+i] = 0 """coin generate""" if self.counter==20: r = random.randint(0,40) self.m[40+r] = 2 """collide check""" if self.m[self.y*40+self.x] == 1: self.cgg.printc("GAME OVER",2,20) self.gamestate="gameover" """collide with coin""" if self.m[self.y*40+self.x]==2 and self.chaincounter<=1: self.msg="get" self.sc=self.sc+100 self.beep.play() self.counter=0 self.chainflag=1 self.chaincounter=self.chaincounter+1 """chain check""" if self.m[self.y*40+self.x]==2 and self.chaincounter>=2: self.msg=str(self.chaincounter)+" chain" self.sc=self.sc+100*self.chaincounter self.chainflag=1 self.chaincounter=self.chaincounter+1 self.beep.play() self.counter=0 """draw myself""" if self.m[self.y*40+self.x]!=1 and self.m[self.y*40+self.x]!=2: self.m[self.y*40+self.x] = 3 self.draw() self.sc=self.sc+1 self.counter=self.counter+1 self.cgg.setcolor(7) """counter caliculate""" if self.counter==25 and self.chainflag==0: self.chaincounter=0 self.counter=0 if self.counter==25 and self.chainflag==1: self.chainflag=0 self.counter=0 self.bgm.stop() self.bgm.play() self.draw() def routine(self): if self.gameflag==0: self.ct=self.ct+1 if self.ct>=10: self.ct=0 self.scroll()