class Life: def __init__(self): self.mtx = [] self.mtx2 = [] self.cgg = CGGPYG() for i in range(0, 40): for j in range(0, 80): self.mtx[len(self.mtx):] = [random.randint(0, 1)] self.mtx2[len(self.mtx2):] = [0] def move(self): for i in range(1, 39): for j in range(1, 79): ct = 0 if self.mtx[(i - 1) * 80 + j - 1] == 1: ct = ct + 1 if self.mtx[(i - 1) * 80 + j] == 1: ct = ct + 1 if self.mtx[(i - 1) * 80 + j + 1] == 1: ct = ct + 1 if self.mtx[i * 80 + j - 1] == 1: ct = ct + 1 if self.mtx[i * 80 + j + 1] == 1: ct = ct + 1 if self.mtx[(i + 1) * 80 + j - 1] == 1: ct = ct + 1 if self.mtx[(i + 1) * 80 + j] == 1: ct = ct + 1 if self.mtx[(i + 1) * 80 + j + 1] == 1: ct = ct + 1 if (ct == 2 or ct == 3) and self.mtx[ i * 80 + j] == 1 or ct == 3 and self.mtx[i * 80 + j] == 0: self.mtx2[i * 80 + j] = 1 else: self.mtx2[i * 80 + j] = 0 for i in range(0, 3200): self.mtx[i] = self.mtx2[i] def draw(self): self.cgg.cls() self.cgg.setcolor(7) for i in range(1, 39): for j in range(0, 79): if self.mtx[i * 80 + j] == 1: self.cgg.put("star", j, i)
class Dempa(): def __init__(self): self.cgg = CGGPYG() self.tim = "noon" self.counter = 0 self.sunct = 0 self.birdct = 0 self.sunx = [19, 18, 16, 14, 12, 10, 8, 6, 4, 3, 2, 2] self.suny = [10, 7, 4, 3, 2, 2, 2, 3, 5, 7, 10, 10] def drawscene(self): if self.tim == "noon": self.cgg.setcolor(5) for i in range(0, 20): for j in range(0, 20): self.cgg.put("fill", i, j) self.cgg.setcolor(0) for i in range(7, 16): for j in range(8, 13): self.cgg.put("fill", i, j) if self.tim == "evening": self.cgg.setcolor(2) for i in range(0, 20): for j in range(0, 20): self.cgg.put("fill", i, j) self.cgg.setcolor(0) for i in range(7, 16): for j in range(8, 13): self.cgg.put("fill", i, j) if self.tim == "night": self.cgg.setcolor(0) for i in range(0, 20): for j in range(0, 20): self.cgg.put("fill", i, j) for i in range(7, 16): if self.tim == "noon" or self.tim == "evening": self.cgg.setcolor(7) if self.tim == "night" and i % 2 == 0 and self.counter % 2 == 0 or self.tim == "night" and i % 2 == 1 and self.counter % 2 == 1: self.cgg.setcolor(7) if self.tim == "night" and i % 2 == 0 and self.counter % 2 == 1 or self.tim == "night" and i % 2 == 1 and self.counter % 2 == 0: self.cgg.setcolor(6) self.cgg.put("circle", i, 8) self.cgg.put("circle", i, 12) for i in range(8, 12): if self.tim == "night" and i % 2 == 0 and self.counter % 2 == 0 or self.tim == "night" and i % 2 == 1 and self.counter % 2 == 1: self.cgg.setcolor(6) if self.tim == "night" and i % 2 == 0 and self.counter % 2 == 1 or self.tim == "night" and i % 2 == 1 and self.counter % 2 == 0: self.cgg.setcolor(7) self.cgg.put("circle", 7, i) self.cgg.put("circle", 15, i) if self.tim == "noon" or self.tim == "evening": self.cgg.setcolor(7) if self.tim == "night": self.cgg.setcolor(0) for i in range(7, 16): for j in range(13, 20): self.cgg.put("fill", i, j) if self.tim == "noon" or self.tim == "evening": self.cgg.setcolor(5) if self.tim == "night": self.cgg.setcolor(6) self.putwindow(8, 14) self.putwindow(12, 14) self.putwindow(8, 17) self.putwindow(12, 17) if self.tim == "noon" or self.tim == "evening": self.cgg.setcolor(7) if self.tim == "night": self.cgg.setcolor(7) self.cgg.put("d", 9, 9) self.cgg.put("e", 10, 9) self.cgg.put("m", 11, 9) self.cgg.put("p", 12, 9) self.cgg.put("a", 13, 9) self.cgg.put("b", 10, 11) self.cgg.put("l", 11, 11) self.cgg.put("d", 12, 11) self.cgg.put("g", 13, 11) if self.tim == "noon": self.cgg.setcolor(6) self.cgg.put("circle", self.sunx[self.sunct], self.suny[self.sunct]) if self.counter % 2 == 0: self.sunct = self.sunct + 1 if self.sunct >= 10: self.sunct = 0 if self.tim == "evening": self.cgg.setcolor(0) if self.birdct % 2 == 0: self.cgg.put("se", 20 - self.birdct, 3) if self.birdct % 2 == 1: self.cgg.put("ne", 20 - self.birdct, 3) self.birdct = self.birdct + 1 if self.birdct >= 20: self.birdct = 0 def putwindow(self, x, y): for i in range(y, y + 2): for j in range(x, x + 3): self.cgg.put("fill", j, i) def routine(self): offset = 0 self.counter = self.counter + 1 if self.counter >= 20: offset = 0 if self.tim == "noon": self.tim = "evening" offset = 1 if self.tim == "night": self.tim = "noon" if self.tim == "evening" and offset == 0: self.tim = "night" self.counter = 0 self.drawscene()
class squash80(cggframe): def __init__(self): self.cgg = CGGPYG("") self.bx = random.randint(1, 9) self.by = 16 self.dx = -1 self.dy = -1 self.mx = 4 self.sc = 0 self.gamestate = "title" self.ct = 0 self.wx = [] self.wy = [] self.wf = [] pygame.mixer.init() self.beep = pygame.mixer.Sound("po.wav") for i in range(0, 40): self.wx[len(self.wx):] = [(i % 9) + 2] self.wy[len(self.wy):] = [int(i / 9) + 2] if i <= 26: self.wf[len(self.wf):] = [1] else: self.wf[len(self.wf):] = [0] 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.mx >= 2: self.mx = self.mx - 1 if key == pygame.K_RIGHT and self.mx <= 8: self.mx = self.mx + 1 if self.gamestate == "gameover": if key == pygame.K_RETURN: self.__init__() self.gamestate = "title" def title(self): self.cgg.cls() self.cgg.setcolor(7) self.cgg.printc("breakout in pygame", 5, 5) self.cgg.printc("2018 tenkey aikoukai", 5, 7) self.cgg.printc("press ret key", 5, 9) pygame.display.flip() def gameover(self): self.cgg.setcolor(2) self.cgg.printc("game over", 8, 9) def routine(self): self.ct = self.ct + 1 if self.ct >= 5: self.update() self.ct = 0 self.draw() def update(self): if self.dx == -1 and self.bx <= 1: self.dx = 1 if self.dx == 1 and self.bx >= 11: self.dx = -1 if self.dy == -1 and self.by <= 1: self.dy = 1 hitflag = 0 for i in range(0, 27): if hitflag == 0: if self.wx[i] == self.bx and self.wy[ i] == self.by + 1 and self.wf[i] == 1: self.dy = 1 self.sc = self.sc + 1 self.wf[i] = 0 hitflag = 1 for i in range(0, 27): if hitflag == 0: if self.wx[i] == self.bx + self.dx and self.wy[ i] == self.by + self.dy and self.wf[ i] == 1 and self.wf[i + 9] == 0: self.dx = -1 * self.dx self.dy = 1 self.sc = self.sc + 1 self.wf[i] = 0 hitflag = 1 if hitflag == 0: self.bx = self.bx + self.dx self.by = self.by + self.dy if hitflag == 1: self.beep.stop() self.beep.play() pygame.display.flip() if self.by == 16 and self.dy == 1: if (self.mx - self.bx) >= -3 and (self.mx - self.bx) <= 0: self.dy = -1 if self.by >= 18: self.gamestate = "gameover" self.draw() def draw(self): self.cgg.cls() self.cgg.setcolor(7) self.cgg.printc("score " + str(self.sc), 1, 21) self.cgg.setcolor(2) for i in range(0, 27): if self.wf[i] == 1: self.cgg.put("brick", self.wx[i], self.wy[i]) self.cgg.setcolor(6) self.cgg.put("circle", self.bx, self.by) self.cgg.setcolor(7) for i in range(0, 3): self.cgg.put("equal", self.mx + i, 17) self.cgg.setcolor(1) for i in range(0, 20): self.cgg.put("brick", 0, i) self.cgg.put("brick", 12, i) for i in range(0, 13): self.cgg.put("brick", i, 0) self.cgg.put("brick", i, 19) def putscore(self): self.modsc = self.sc % 10 self.putnumchr(self.modsc, 19, 7) self.cursc = int(self.sc / 10) self.modsc = self.cursc % 10 self.putnumchr(self.modsc, 18, 7) self.cursc = int(self.cursc / 10) self.modsc = self.cursc % 10 self.putnumchr(self.modsc, 17, 7) def putnumchr(self, num, x, y): if num == 0: self.cgg.put("0", x, y) if num == 1: self.cgg.put("1", x, y) if num == 2: self.cgg.put("2", x, y) if num == 3: self.cgg.put("3", x, y) if num == 4: self.cgg.put("4", x, y) if num == 5: self.cgg.put("5", x, y) if num == 6: self.cgg.put("6", x, y) if num == 7: self.cgg.put("7", x, y) if num == 8: self.cgg.put("8", x, y) if num == 9: self.cgg.put("9", x, y)
class Aquarium: def __init__(self): self.fishx = [0, 2, 4, 2, 7, 15, 10, 12] self.fishy = [0, 5, 6, 9, 12, 15, 10, 8] self.fishd = [0, 1, 3, 1, 3, 3, 1, 1] self.kombud = [0, 1, 2] self.cgg = CGGPYG("marine") def routine(self): """"beep(1)""" for i in range(1, 7): r = random.randint(0, 3) if r == 1 and self.fishy[i] > 3: self.fishy[i] = self.fishy[i] - 1 if r == 2 and self.fishy[i] < 18: self.fishy[i] = self.fishy[i] + 1 self.fishx[i] = self.fishx[i] + self.fishd[i] - 2 if self.fishd[i] == 1 and self.fishx[i] < 3: self.fishd[i] = 3 if self.fishd[i] == 3 and self.fishx[i] > 17: self.fishd[i] = 1 if self.kombud[1] == 1: self.kombud[1] = 2 else: self.kombud[1] = 1 if self.kombud[2] == 1: self.kombud[2] = 2 else: self.kombud[2] = 1 self.cgg.cls() self.drawchr() self.drawwave() def drawchr(self): """draw fish""" for i in range(1, 7): self.cgg.setcolor(i) if self.fishd[i] == 1: self.cgg.put("se", self.fishx[i], self.fishy[i]) self.cgg.put("sw", self.fishx[i] + 1, self.fishy[i]) self.cgg.put("se", self.fishx[i] + 2, self.fishy[i]) else: self.cgg.put("sw", self.fishx[i], self.fishy[i]) self.cgg.put("se", self.fishx[i] - 1, self.fishy[i]) self.cgg.put("sw", self.fishx[i] - 2, self.fishy[i]) """draw kombu""" self.cgg.setcolor(4) if self.kombud[1] == 1: self.cgg.put("se", 5, 14) self.cgg.put("ne", 5, 15) self.cgg.put("sw", 6, 16) self.cgg.put("nw", 6, 17) self.cgg.put("se", 5, 18) self.cgg.put("ne", 5, 19) if self.kombud[1] == 2: self.cgg.put("sw", 6, 14) self.cgg.put("nw", 6, 15) self.cgg.put("se", 5, 16) self.cgg.put("ne", 5, 17) self.cgg.put("sw", 6, 18) self.cgg.put("nw", 6, 19) if self.kombud[2] == 1: self.cgg.put("se", 15, 14) self.cgg.put("ne", 15, 15) self.cgg.put("sw", 16, 16) self.cgg.put("nw", 16, 17) self.cgg.put("se", 15, 18) self.cgg.put("ne", 15, 19) if self.kombud[2] == 2: self.cgg.put("sw", 16, 14) self.cgg.put("nw", 16, 15) self.cgg.put("se", 15, 16) self.cgg.put("ne", 15, 17) self.cgg.put("sw", 16, 18) self.cgg.put("nw", 16, 19) def drawwave(self): for i in range(0, 39): if i <= 10 or i >= 14: r = random.randint(0, 1) self.cgg.setcolor(5) self.cgg.put("wave", i, r)
class fruits(cggframe): def __init__(self): self.cgg = CGGPYG("") pygame.mixer.init() self.gamestate = "title" self.click = pygame.mixer.Sound("click.wav") self.hit = pygame.mixer.Sound("po.wav") self.misssound = pygame.mixer.Sound("pin-do.wav") self.fruit = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.frame = 0 self.rnum = 0 self.px = pxmtx[2] self.mx = 2 self.sc = 0 self.ct = 0 self.ct2 = 0 self.miss = 0 self.rseed = 6 def puttree(self, x, y, leg): self.cgg.setcolor(4) self.cgg.put("se", x + 1, y) self.cgg.put("fill", x + 2, y) self.cgg.put("sw", x + 3, y) self.cgg.put("se", x + 1, y + 1) self.cgg.put("fill", x + 2, y + 1) self.cgg.put("sw", x + 3, y + 1) self.cgg.put("se", x, y + 2) self.cgg.put("fill", x + 1, y + 2) self.cgg.put("fill", x + 2, y + 2) self.cgg.put("fill", x + 3, y + 2) self.cgg.put("sw", x + 4, y + 2) self.cgg.setcolor(2) for i in range(1, leg + 1): self.cgg.put("fill", x + 2, y + 3 + i - 1) def update(self): if self.ct2 == 0: self.fruitset() self.click.play() self.ct = self.ct + 1 if self.ct >= 3 and self.ct2 == 0: self.ct2 = 1 self.ct = 0 elif self.ct >= 3 and self.ct2 >= 1: self.ct = 0 self.ct2 = 0 if self.fruit[24 + self.ct] > 0 and self.mx == self.ct: self.hit.play() self.draw() time.sleep(0.02) self.fruit[24 + self.ct] = 0 self.sc = self.sc + 1 if self.sc % 20 == 0 or self.sc % 80 == 0 or (self.sc >= 100 and self.sc % 100 == 0): self.rnum = self.rnum + 1 self.rseed = rmtx[self.rnum] if self.rnum == 17: self.rnum = 14 for i in range(9, -1, -1): self.fruit[(i + 1) * 3 + self.ct] = self.fruit[i * 3 + self.ct] self.fruit[self.ct] = 0 self.draw() if self.fruit[24 + self.ct] > 0 and self.mx == self.ct: self.hit.play() self.draw() time.sleep(0.02) self.fruit[24 + self.ct] = 0 self.sc = self.sc + 1 if self.sc % 20 == 0 or self.sc % 80 == 0 or (self.sc >= 100 and self.sc % 100 == 0): self.rnum = self.rnum + 1 self.rseed = rmtx[self.rnum] if self.rnum == 17: self.rnum = 14 if self.fruit[27 + self.ct] > 0: self.miss = self.miss + 1 self.misssound.play() if self.miss >= 3: self.gamestate = "gameover" self.cgg.put("heart", pxmtx[self.ct % 3], 17) self.draw() def draw(self): self.cgg.cls() self.fruitdraw() self.puttrees() self.cgg.setcolor(6) self.cgg.put("v", pxmtx[self.mx], 14) self.cgg.setcolor(7) self.cgg.put("s", 1, 19) self.cgg.put("c", 2, 19) self.cgg.put("o", 3, 19) self.cgg.put("r", 4, 19) self.cgg.put("e", 5, 19) self.putscore() if self.miss >= 1: self.drawmiss() pygame.display.flip() def title(self): self.cgg.cls() self.cgg.setcolor(7) self.cgg.printc("fruits in the forest", 5, 5) self.cgg.printc("2021 tenkey aikoukai", 5, 7) self.cgg.printc("press enter key", 5, 9) pygame.display.flip() def gameover(self): self.cgg.setcolor(2) self.cgg.printc("game over", 15, 6) 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.mx >= 1: self.mx = self.mx - 1 if key == pygame.K_RIGHT and self.mx <= 1: self.mx = self.mx + 1 time.sleep(0.005) if self.fruit[24 + self.ct] > 0 and self.mx == self.ct: self.hit.play() self.fruit[24 + self.ct] = 0 self.sc = self.sc + 1 if self.sc % 20 == 0 or self.sc % 80 == 0 or ( self.sc >= 100 and self.sc % 100 == 0): self.rnum = self.rnum + 1 self.rseed = rmtx[self.rnum] if self.rnum == 17: self.rnum = 14 self.draw() time.sleep(0.02) self.draw() if self.gamestate == "gameover": if key == pygame.K_RETURN: self.__init__() self.gamestate = "title" def routine(self): self.frame = self.frame + 1 if self.frame == 10: self.update() self.frame = 0 self.draw() def putscore(self): modsc = self.sc % 10 self.putnumchr(modsc, 9, 19) cursc = int(self.sc / 10) modsc = cursc % 10 self.putnumchr(modsc, 8, 19) cursc = int(cursc / 10) modsc = cursc % 10 self.putnumchr(modsc, 7, 19) def putnumchr(self, num, x, y): self.cgg.setcolor(7) if num == 0: self.cgg.put("0", x, y) if num == 1: self.cgg.put("1", x, y) if num == 2: self.cgg.put("2", x, y) if num == 3: self.cgg.put("3", x, y) if num == 4: self.cgg.put("4", x, y) if num == 5: self.cgg.put("5", x, y) if num == 6: self.cgg.put("6", x, y) if num == 7: self.cgg.put("7", x, y) if num == 8: self.cgg.put("8", x, y) if num == 9: self.cgg.put("9", x, y) def puttrees(self): x = 3 y = 3 self.puttree(x, y, 9) x = 8 y = 5 self.puttree(x, y, 7) x = 13 y = 7 self.puttree(x, y, 5) def fruitset(self): r = random.randint(0, self.rseed) if r == 1: if self.ct == 0: self.fruit[0] = 1 elif self.ct == 1: self.fruit[4] = 1 else: self.fruit[11] = 1 def fruitdraw(self): self.cgg.setcolor(3) for i in range(0, 31): py = int(i / 3) + 6 if self.fruit[i] == 1: self.cgg.put("heart", pxmtx[i % 3], py) def drawmiss(self): self.cgg.setcolor(7) self.cgg.put("m", 11, 19) self.cgg.put("i", 12, 19) self.cgg.put("s", 13, 19) self.cgg.put("s", 14, 19) self.cgg.put("spade", 16, 19) if self.miss >= 2: self.cgg.put("spade", 17, 19) if self.miss >= 3: self.cgg.put("spade", 18, 19)
class exhelm(cggframe): def __init__(self): self.cgg = CGGPYG("") pygame.mixer.init() self.bgm = pygame.mixer.Sound("powa.wav") self.click = pygame.mixer.Sound("pin-re.wav") self.beep = pygame.mixer.Sound("pin-do.wav") self.m = [] for i in range(0, 21): for j in range(0, 41): self.m[len(self.m):] = [0] self.mx = 0 self.my = 16 self.sc = 0 self.goal = "right" self.gamestate = "play" self.miss = 0 self.ct = 0 self.level = 5 def keyin(self, key): if self.gamestate == "title" and key == pygame.K_RETURN: self.gamestate = "play" if self.gamestate == "play": if key == pygame.K_RIGHT and self.mx < 19: self.mx = self.mx + 1 if key == pygame.K_LEFT and self.mx > 0: self.mx = self.mx - 1 if self.gamestate == "gameover" and key == pygame.K_RETURN: self.__init__() self.gamestate = "play" def draw(self): self.cgg.cls() """draw raindrops""" self.cgg.setcolor(5) for i in range(0, 16): for j in range(1, 19): if self.m[i * 20 + j] == 1: self.cgg.put("point", j, i) """draw floor of start and goal""" self.cgg.setcolor(6) self.cgg.put("fill", 0, 17) self.cgg.put("fill", 19, 17) """draw roof""" self.cgg.setcolor(2) self.cgg.put("sw", 0, 14) self.cgg.put("se", 19, 14) """draw road""" self.cgg.setcolor(4) for i in range(1, 19): self.cgg.put("fill", i, 17) """draw load""" if self.my < 20: if self.goal == "right": self.cgg.setcolor(1) self.cgg.put("brick", self.mx, self.my - 1) """draw player chr""" self.cgg.setcolor(7) self.cgg.put("spade", self.mx, self.my) """score display""" self.cgg.printc("score:" + str(self.sc) + " miss:" + str(self.miss), 0, 20) def gameover(self): self.cgg.setcolor(2) self.cgg.printc("game over", 15, 10) def scroll(self): self.click.stop() self.click.play() pygame.display.flip() self.m[10 * 20] = 1 self.m[10 * 20 + 19] = 1 for i in range(0, 19): r = random.randint(1, 10) self.m[i] = 0 if r == 1: self.m[i] = 1 for i in range(16, -1, -1): for j in range(1, 19): self.m[(i + 1) * 20 + j] = self.m[i * 20 + j] if self.m[(self.my - 1) * 20 + self.mx] == 1: self.miss = self.miss + 1 self.beep.play() if self.miss >= 3: self.gamestate = "gameover" if self.mx == 19 and self.goal == "right": self.sc = self.sc + 1 self.bgm.play() pygame.display.flip() self.goal = "left" if self.mx == 0 and self.goal == "left": self.sc = self.sc + 1 self.bgm.play() pygame.display.flip() if self.sc % 20 == 0 and self.level < 7: self.level = self.level + 1 self.goal = "right" self.draw() def routine(self): self.ct = self.ct + 1 if self.ct >= 10 - self.level: self.ct = 0 self.scroll() self.draw()
class NumberSnake: def __init__(self): self.mx = 0 self.my = 0 self.d = 1 self.mtx = [] self.currentnum = 1 self.sc = 0 self.gameflag = 1 self.gamestate = "title" self.cgg = CGGPYG() self.beepflag = 0 pygame.mixer.music.load('pingpong1.mp3') for i in range(0, 21): for j in range(0, 21): self.mtx[len(self.mtx):] = [0] for i in range(1, 11): flag = 0 r1 = 0 r2 = 0 while (flag == 0): r1 = random.randint(1, 17) r2 = random.randint(1, 17) """11-19:number 20:my address""" if (self.mtx[r2 * 20 + r1] == 0): self.mtx[r2 * 20 + r1] = 10 + i flag = 1 self.mx = r1 self.my = r2 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("number snake the action game", 5, 5) self.cgg.printc("2018 tenkey aikoukai", 5, 7) self.cgg.printc("press ret key", 5, 9) def gameover(self): if self.gameflag == 2: self.cgg.setcolor(2) self.cgg.printc("game over", 15, 10) if self.gameflag == 3: self.cgg.setcolor(5) self.cgg.printc("game clear", 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: self.d = 4 if key == pygame.K_RIGHT: self.d = 2 if key == pygame.K_UP: self.d = 1 if key == pygame.K_DOWN: self.d = 3 if self.gamestate == "gameover": if key == pygame.K_RETURN: self.__init__() self.gamestate = "title" def draw(self): self.cgg.cls() rectcolor = (255, 255, 255) rect = (0, 0, 608, 392) pygame.draw.rect(self.cgg.cvs, rectcolor, rect, 5) for i in range(0, 19): for j in range(0, 19): if self.mtx[i * 20 + j] == 1: self.cgg.setcolor(4) self.cgg.put("circle", j, i) if self.mtx[i * 20 + j] == 11: self.cgg.setcolor(6) self.cgg.put("1", j, i) if self.mtx[i * 20 + j] == 12: self.cgg.setcolor(6) self.cgg.put("2", j, i) if self.mtx[i * 20 + j] == 13: self.cgg.setcolor(6) self.cgg.put("3", j, i) if self.mtx[i * 20 + j] == 14: self.cgg.setcolor(6) self.cgg.put("4", j, i) if self.mtx[i * 20 + j] == 15: self.cgg.setcolor(6) self.cgg.put("5", j, i) if self.mtx[i * 20 + j] == 16: self.cgg.setcolor(6) self.cgg.put("6", j, i) if self.mtx[i * 20 + j] == 17: self.cgg.setcolor(6) self.cgg.put("7", j, i) if self.mtx[i * 20 + j] == 18: self.cgg.setcolor(6) self.cgg.put("8", j, i) if self.mtx[i * 20 + j] == 19: self.cgg.setcolor(6) self.cgg.put("9", j, i) if i == self.my and j == self.mx: self.cgg.setcolor(7) self.cgg.put("circle", j, i) self.cgg.setcolor(7) def routine(self): self.mtx[self.my * 20 + self.mx] = 1 pygame.mixer.music.play(1) time.sleep(0.2) pygame.mixer.music.stop() """up:1 and clockwork""" if self.d == 1: self.my = self.my - 1 if self.d == 2: self.mx = self.mx + 1 if self.d == 3: self.my = self.my + 1 if self.d == 4: self.mx = self.mx - 1 self.draw() if self.mtx[self.my * 20 + self.mx] > 10 and self.mtx[ self.my * 20 + self.mx] != self.currentnum + 10 or self.mtx[ self.my * 20 + self. mx] == 1 or self.mx < 0 or self.mx > 19 or self.my < 0 or self.my > 19: self.gameflag = 2 self.gamestate = "gameover" if self.mtx[self.my * 20 + self.mx] == self.currentnum + 10: pygame.mixer.music.load('buzzer.mp3') pygame.mixer.music.play(1) time.sleep(0.2) pygame.mixer.music.stop() pygame.mixer.music.load('pingpong1.mp3') self.sc = self.sc + 1 self.currentnum = self.currentnum + 1 if self.currentnum >= 10: self.gamestate = "gameover" self.gameflag = 3
class pokeshoot(): def __init__(self): self.cgg = CGGPYG("") self.m = [0, 0] self.gameflag = 0 for i in range(0, 21): for j in range(0, 21): self.m[len(self.m):] = [0] self.wy = [] self.wf = [] for i in range(0, 20): self.wy[len(self.wy):] = [0] self.wf[len(self.wf):] = [0] self.wy[0] = random.randint(10, 16) for i in range(1, 20): self.wy[i] = self.wy[i - 1] + random.randint(0, 2) - 1 self.gamestate = "title" self.sc = 0 self.mx = 0 self.my = 2 self.ex = 31 self.ey = random.randint(0, 3) self.bx = 0 self.by = 0 self.shoot = 0 self.edy = random.randint(0, 6) self.dw = 1 self.jumpct = 0 self.boaty = 0 self.boaty2 = 0 self.miss = 0 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(4) self.cgg.printc("cggpyg bmx game", 12, 8) self.cgg.printc("press ret key", 12, 10) 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_UP and self.jumpct == 0: self.jumpct = 1 self.boaty = self.wy[3] if self.gamestate == "gameover": if key == pygame.K_RETURN: self.__init__() def draw(self): self.cgg.cls() if self.jumpct == 0: self.boaty = self.wy[3] if self.jumpct > 0: if self.jumpct < 10: self.boaty = self.boaty - 1 else: if self.boaty < self.wy[3]: self.boaty = self.boaty + 1 if self.jumpct == 0: self.boaty2 = self.wy[4] if self.jumpct > 0: if self.jumpct < 10: self.boaty2 = self.boaty2 - 1 else: if self.boaty2 < self.wy[4]: self.boaty2 = self.boaty2 + 1 for i in range(0, 20): if self.wf[i] == 0: self.cgg.setcolor(4) self.cgg.put("fill", i, self.wy[i]) elif self.wf[i] == 1: self.cgg.setcolor(2) self.cgg.put("fill", i, self.wy[i]) else: self.cgg.setcolor(6) self.cgg.put("fill", i, self.wy[i]) self.cgg.setcolor(0) self.cgg.put("fill", 3, self.boaty) self.cgg.setcolor(7) self.cgg.put("circle", 3, self.boaty) self.cgg.put("circle", 4, self.boaty2) self.cgg.line(32 * 3 + 16, self.boaty * 20 + 10, 32 * 4 + 16, self.boaty2 * 20 + 10) self.cgg.line(32 * 4 + 16, self.boaty2 * 20 + 10, 32 * 4 + 16, self.boaty2 * 20 - 10) self.cgg.line(32 * 4 + 16, self.boaty2 * 20 - 10, 32 * 4 - 16, self.boaty2 * 20 - 10) self.cgg.printc("score:" + str(self.sc) + " miss:" + str(self.miss), 1, 20) def routine(self): self.sc = self.sc + 1 if self.jumpct > 0: self.jumpct = self.jumpct + 1 if self.jumpct >= 20: self.jumpct = 0 if self.wy[3] == self.boaty and self.wf[3] == 1: self.miss = self.miss + 1 if self.miss >= 30: self.gamestate = "gameover" if self.wy[3] == self.boaty and self.wf[3] == 2: self.miss = 0 for i in range(0, 19): self.wy[i] = self.wy[i + 1] self.wf[i] = self.wf[i + 1] r = random.randint(0, 10) if r == 5: self.dw = -self.dw self.wy[19] = self.wy[18] + self.dw if self.wy[19] <= 10 and self.dw < 0: self.dw = -self.dw if self.wy[19] >= 19 and self.dw > 0: self.dw = -self.dw if random.randint(0, 5) == 1: self.wf[19] = 1 elif random.randint(0, 1000) == 1: self.wf[19] = 2 else: self.wf[19] = 0 self.draw()