示例#1
0
 def __init__(self, column, row, shape):
     self.x = column
     self.y = row
     self.shape = shape
     self.color = shape_colors[shapes.index(
         shape)]  # Color index is the same as shape index
     self.rotation = 0  # number from 0-3
示例#2
0
 def __init__(me, rows, cols, startshape):
     me.rows, me.cols = me.dim = (rows, cols)
     me.canvas = [ [0] * cols for i in range(rows) ]
     me.colormap = [ [-1] * cols for i in range(rows) ]
     me.anchor = (0, cols/2)
     me.curr = startshape
     me.currcolor = shapes.index(startshape)
示例#3
0
 def reset(me, newshape):
     """
     Resets position and sets the new shape.
     If game is over (i.e. new shape is invalid) returns -1.
     """
     me.curr = newshape
     me.currcolor = shapes.index(newshape)
     me.anchor = (0, me.cols/2)
     if not me.isValid(me.anchor, me.curr):
         return -1
示例#4
0
    def render(me, game):
        me.clearLines(game)

        # blit the background
        game.screen.blit(me.bg, (0, 0))

        # blit next shape
        color = shapes.index(me.nextShape)
        for i, r in enumerate(me.nextShape):
            for j, b in enumerate(r):
                if me.nextShape[i][j] == 1:
                    game.screen.blit(me.blockimgs[color], ((me.wmarg + 20) + j * me.bpx, me.hmarg + (i + 5) * me.bpx))

        # blit lines/level
        game.screen.blit(game.gameFont.render("Level", 20, (255, 255, 255)), (me.wmarg, me.hmarg + 14 * me.bpx))
        game.screen.blit(
            game.gameFont.render(str(me.stats.level), 20, (255, 255, 255)),
            (me.wmarg, me.hmarg + 16 * me.bpx - me.bpx / 2),
        )
        game.screen.blit(game.gameFont.render("Lines", 20, (255, 255, 255)), (me.wmarg, me.hmarg + 18 * me.bpx))
        game.screen.blit(
            game.gameFont.render(str(me.stats.totalLines), 20, (255, 255, 255)),
            (me.wmarg, me.hmarg + 20 * me.bpx - me.bpx / 2),
        )

        # blit the canvas
        for i in range(me.rows):
            for j in range(me.cols):
                game.screen.blit(me.cbg, (me.xs + j * me.bpx, me.ys + i * me.bpx))
                color = me.c[i][j]
                if color != -1:
                    game.screen.blit(me.blockimgs[color], (me.xs + j * me.bpx, me.ys + i * me.bpx))

        # blit the current shape
        color = me.c.currcolor
        for r, c in me.c.getBlocks():
            game.screen.blit(me.blockimgs[color], (me.xs + c * me.bpx, me.ys + r * me.bpx))
 def __init__(self, x, y, shape):
     self.x = x
     self.y = y
     self.shape = shape
     self.color = colors[shapes.index(shape)]
     self.rotate = 0
 def __init__(self, column, row, shape):
     self.x = column
     self.y = row
     self.shape = shape
     self.color = colors[shapes.index(shape)]
     self.rotation = 0