コード例 #1
0
ファイル: wirelife.py プロジェクト: tenkeyaikoukaint/cggpyg
class wirelife(cggframe):
    def __init__(self):

        self.ct = 0
        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]
        self.gamestate = "play"

    def readmtx(self, x, y):

        return self.mtx[y * 80 + x]

    def routine(self):

        for i in range(1, 39):
            for j in range(1, 79):
                ct = 0
                for k in range(i - 1, i + 2):
                    for l in range(j - 1, j + 2):
                        if (k - i) == 0 and (l - j) == 0:
                            dummy = 0
                        else:
                            ct = ct + self.readmtx(l, k)
                if (ct == 2 or ct == 3) and self.readmtx(
                        j, i) == 1 or ct == 3 and self.readmtx(j, i) == 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]
        self.draw()
        self.ct = self.ct + 1

    def keyin(self, key):

        dummy = 0

    def draw(self):

        self.cgg.cls()
        self.cgg.setcolor(5)
        for i in range(1, 39):
            for j in range(0, 79):
                if self.mtx[i * 80 + j] == 1:
                    for k in range(i - 1, i + 2):
                        for l in range(j - 1, j + 2):
                            if self.mtx[k * 80 + l] == 1:
                                self.cgg.line(j * 8, i * 8, l * 8, k * 8)

        self.cgg.setcolor(7)
        self.cgg.printc("time:" + str(self.ct), 0, 16)
コード例 #2
0
ファイル: cggtemp.py プロジェクト: tenkeyaikoukaint/cggpyg
class cggtemp(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]
        self.mx = 0
        self.my = 16
        self.sc = 0
        self.gamestate = "play"
        self.miss = 0

    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()
        self.cgg.setcolor(2)

    def gameover(self):

        self.cgg.setcolor(2)
        self.cgg.printc("game over", 15, 10)

    def routine(self):

        self.draw()
コード例 #3
0
ファイル: breakout.py プロジェクト: tenkeyaikoukaint/cggpyg
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)
コード例 #4
0
ファイル: fruits.py プロジェクト: tenkeyaikoukaint/cggpyg
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)
コード例 #5
0
ファイル: rainwork3.py プロジェクト: tenkeyaikoukaint/cggpyg
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()
コード例 #6
0
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
コード例 #7
0
ファイル: bmx.py プロジェクト: tenkeyaikoukaint/cggpyg
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()
コード例 #8
0
ファイル: snakegame.py プロジェクト: tenkeyaikoukaint/cggpyg
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)
コード例 #9
0
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()