当前位置: 首页>>代码示例>>Python>>正文


Python Board.draw方法代码示例

本文整理汇总了Python中Board.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Board.draw方法的具体用法?Python Board.draw怎么用?Python Board.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Board的用法示例。


在下文中一共展示了Board.draw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]
class DummyController:
	board = None
	curMino = None
	linesCleared = None
	gameOver = None
	player = None
	streak = None

	def __init__(self, player):
		self.board = Board()
		self.curMino = choice(Tetrominoes.minoes)
		self.linesCleared = 0
		self.streak = 0
		self.player = player
		gameOver = False

	def tick(self):
		self.player.makeMove(self)

	def getMino(self):
		return Mino(self.curMino)

	def getBoard(self):
		return Board(self.board)

	def makeMove(self, move):
		mino = Mino(self.curMino)
		for i in range(move[1]):
			mino.rotate()

		newBoard = self.board.placeMino(mino, move[0])
		if newBoard:
			self.board = newBoard
		else:
			print "Controller: invalid move received"
			raise

		clearedLines = self.board.clearAndReturnLines()
		
		if clearedLines == 0:
			self.streak = 0
		else:
			self.streak += clearedLines

		self.linesCleared += clearedLines
		self.curMino = choice(Tetrominoes.minoes)

	def gameIsOver(self):
		self.gameOver = True

	def addLines(self, num):
		self.board.addLines(num)

	def draw(self):
		self.board.draw()
开发者ID:chaitub1,项目名称:python-tetrisai,代码行数:57,代码来源:DummyController.py

示例2: main

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]
def main():
    global FPSCLOCK, DISPLAYSURF, FONTOBJ
    pygame.init()	#initialize the game
    FPSCLOCK = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    FONTOBJ = pygame.font.Font('freesansbold.ttf', 18)
    
    pygame.display.set_caption('Tetrisss?')

    #set up initial pieces
    board = Board(DISPLAYSURF, FONTOBJ)
    queue = Queue(DISPLAYSURF)
    splashscreen = Splashscreen(DISPLAYSURF, FONTOBJ)
    DISPLAYSURF.fill(WINDOWCOLOR)
    start = False
    lastEventTime = time.time()
    lastDropTime = time.time()
    soundOn = True
    pygame.mixer.music.load('tetrisb.mid')
    pygame.mixer.music.play(-1, 0.0)
        
    while True: #main game loop
        #speed up the game as you level up
        fallspeed = generateSpeed(board.level)
        listenForQuit()
        soundOn = toggleSound(soundOn) 
        start = listenForStart(start)
        if not start:
            splashscreen.draw()
        else:
            board.checkGameState()
            board.draw()
            drawScorePanel(board)
            drawInstructions()
            if board.gameState == ACTIVE:
                queue.draw()
                #if its been longer than the fallspeed and the down key is not pressed, move the piece down
                keystate = pygame.key.get_pressed()
                if time.time() - lastDropTime > fallspeed and not keystate[K_DOWN]: 
                    move(board, queue, DOWN)
                    lastDropTime = time.time()
            
            lastEventTime = listenForKeyEvents(board,queue,lastEventTime)
            
        
        #update screen
        pygame.display.update()
        FPSCLOCK.tick(FPS)
开发者ID:Conanjun,项目名称:tetromino_andrew,代码行数:50,代码来源:tetris.py

示例3: tileInterspace

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]
# A fórmula usada aqui é uma fatoração da seguinte fórmula
# BODY_HEIGHT == numTiles*tileSize + (numTiles - 1)*tileInterspace + 2*border
# Onde border está em função do tileInterspace (border == 2*tileInterspace)
# Onde o tileInterspace está em função do tamanho do tile
# BODY_HEIGHT == numTiles*tileSize + (numTiles - 1)*(tileSize*TILE_INTERSPACE_FACTOR) + 4*(tileSize*TILE_INTERSPACE_FACTOR)
tileSizeH = BODY_HEIGHT / (numTilesHeight + TILE_INTERSPACE_FACTOR*(numTilesHeight + 3))
tileSizeW = BODY_WIDTH / (numTilesWidth + TILE_INTERSPACE_FACTOR*(numTilesWidth + 3))
# Como número de tiles pode variar no eixo X e Y, deve-se fazer os dois cálculos e usar o menor
# Isso é demonstrado nos testes de mesa 1 e 2
tileSize = min(tileSizeH, tileSizeW)

# Com o maior tamanho possível para o tile definido, pode-se criar o board
board = Board((numTilesHeight, numTilesWidth), tileSize, COLOR_BOARD, COLOR_TILE)
# Depois de criado ele deve ser centralizado na tela
board.setPositionCentral((HEIGHT, WIDTH), (HEADER, 0))
# E enfim alguns tiles devem ser marcados de acordo com o nível
board.setMarkedTiles(level)

# DESENHAR

# Desenha o board
board.draw(DISPLAYSURF)

# Executa o game loop
while True:
   for event in pygame.event.get():
      if event.type == QUIT:
         pygame.quit()
         sys.exit()
   pygame.display.update()
开发者ID:drigos,项目名称:donkey,代码行数:32,代码来源:MemoryMatrix.py

示例4: run

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]
    def run(self,level=0):
        self.init()
        self.level=level
        clock = pygame.time.Clock()
        screen = pygame.display.set_mode((self.width, self.height))
        screen.convert()
        screen.set_colorkey((1,1,1))
        # set the title of the window
        pygame.display.set_caption(self.title)
        if(self.level==1):
            bg = pygame.image.load("bg3.jpg")
        elif(self.level==3):
            bg = pygame.image.load("Deathstar.jpg")
        else:
            bg = pygame.image.load("moon-min.jpg")
        bg=pygame.transform.scale(bg,(600,400))
        screen.blit(bg, (0, 0))
        ui = pygame.image.load("ui2.png")
        ui = pygame.transform.scale(ui,(600,300))
        # stores all the keys currently being held down
        self._keys = dict()
        # call game-specific initialization
        
        playing = True 
        # makes board
        x=Board(self.width,self.height,self.hero,level,self.testLevel)
        self.gravity=x.gravity # level gravity
        while playing:
            screen.blit(bg, (0, 0))
            
            time = clock.tick(self.fps)
            self.timerFired(time)

            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                    self.mousePressed(*(event.pos))
                elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                    self.mouseReleased(*(event.pos))
                elif (event.type == pygame.MOUSEMOTION and
                      event.buttons == (0, 0, 0)):
                    self.mouseMotion(*(event.pos))
                elif (event.type == pygame.MOUSEMOTION and
                      event.buttons[0] == 1):
                    self.mouseDrag(*(event.pos))
                elif event.type == pygame.KEYDOWN:
                    self._keys[event.key] = True
                    self.keyPressed(event.key, event.mod)
                elif event.type == pygame.KEYUP:
                    self._keys[event.key] = False
                    self.keyReleased(event.key, event.mod)
                elif event.type == pygame.QUIT:
                    playing = False
            
            self.checkMode(screen) # check if win/lose
            if(not self.gameOver):
                x.draw(screen,self.hero.z,self.posX,self.posY,self.posYconst)
                self.redrawAll(screen)
                screen.blit(ui,(0,200))
                self.drawData(screen)
            
            pygame.display.flip()
            if(self.count==35 or self.dontWait):
                break
        return self.hero.mode
开发者ID:SlashDK,项目名称:PyRoads,代码行数:66,代码来源:Movement.py

示例5: gameLoop

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]

#.........这里部分代码省略.........
                        gameExit = True
                    if event.key == pygame.K_p:
                        gamePause = True
                    if event.key == pygame.K_a:
                        player.go_left()
                    if event.key == pygame.K_d:
                        player.go_right()
                    if event.key == pygame.K_w:
                        player.go_up()
                    if event.key == pygame.K_s:
                        player.go_down()
                    if event.key == pygame.K_SPACE:
                        player.jump()
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_a or event.key == pygame.K_d:
                        player.stop()
                    if event.key == pygame.K_w or event.key == pygame.K_s:
                        player.stop()
                        # MAKE FIREBALLS
            flag = random.randrange(2)
            if freq > self.ball_frequency and flag:
                # if freq > 10: FOR TESTING RANDOMNESS
                freq = 0
                ball = Fireball(donkey, board, self.ball_speed)
                balls_sprite_list.add(ball)
                all_sprites_list.add(ball)
            else:
                freq += 1

                # DRAWINGS BELOW
            all_sprites_list.update()

            # board.update()
            balls_sprite_list.update()
            board.door.vanish(balls_sprite_list)

            board.draw(screen)
            all_sprites_list.draw(screen)
            balls_sprite_list.draw(screen)
            ##DRAWINGS ABOVE

            # LOGIC BELOW
            self.player_lives = player.show_attributes(screen, font, balls_sprite_list)
            if self.player_lives == 0:
                gameOver = True

            if self.cur_val != self.player_lives:

                player.rect.x = 30
                player.rect.y = SC_HEIGHT - player.rect.height - 50

                donkey.rect.x = 50
                donkey.rect.y = 150
                self.cur_val = self.player_lives
                # queen hit
            queen_hit = pygame.sprite.spritecollide(player, queen_sprite_list, False)
            if len(queen_hit) > 0:
                self.score = player.score + 50
                self.ball_speed += 2
                self.player_speed += 2
                if self.ball_frequency > 50:
                    self.ball_frequency -= 50
                else:
                    self.ball_frequency -= 5
                self.gameLoop(screen, font)
                ##LOGIC ABOVE

            clock.tick(60)
            pygame.display.update()

            while gameOver == True:
                m.End_Message(self.score)
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_q:
                            gameExit = True
                            gameOver = False
                        if event.key == pygame.K_r:
                            gameOver = False
                            self.score = 0
                            self.fl = 1
                            self.gameLoop(screen, font)

            while gamePause == True:
                m.Pause_Message()
                for event in pygame.event.get():
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_q:
                            gameExit = True
                            gamePause = False
                        if event.key == pygame.K_r:
                            gamePause = False
                            self.score = 0
                            self.fl = 1
                            self.gameLoop(screen, font)
                        if event.key == pygame.K_c:
                            gamePause = False

        pygame.quit()
        quit()
开发者ID:IIITSERC,项目名称:SSAD_2015_A3_Group2_14,代码行数:104,代码来源:Game.py

示例6: __init__

# 需要导入模块: import Board [as 别名]
# 或者: from Board import draw [as 别名]

#.........这里部分代码省略.........

		return board

	def readSignature(self, board):
		pid = deepcopy(board)
		for i in range(20):
			for j in range(10):
				if pid[i][j] == '#':
					pid[i][j] = ' '
		pl = []

		for j in pid:
			if '.' in j:
				pl.append(j)

		pid = []
		for l in zip(*pl):
			if '.' in list(l):
				pid.append(l)

		pShape = map(list, zip(*pid))
		pSig = ""
		for line in pShape:
			pSig += ''.join(line)
			pSig += "|"

		pMino = -1
		if pSig == "":
			return -1

		if   pSig == "  .|...|":
			pMino = Tetrominoes.SL
		elif pSig == ".  |...|":
			pMino = Tetrominoes.IL
		elif pSig == " . |...|":
			pMino = Tetrominoes.ST
		elif pSig == "..|..|":
			pMino = Tetrominoes.SQ
		elif pSig == "....|":
			pMino = Tetrominoes.SI
		elif pSig == " ..|.. |":
			pMino = Tetrominoes.SS
		elif pSig == ".. | ..|":
			pMino = Tetrominoes.IS
		else:
			print "pSig desconhecido: %s" % pSig
			return -1

		return pMino


	def getMino(self):
		self.readScreen()
		return Mino(self.curMino)

	def getBoard(self):
		self.readScreen()
		return Board(self.board)

	def makeMove(self, move):
		print move
		b = Board(self.board)
		m = Mino(self.curMino)

		for i in range(move[1]):
			m.rotate()

		m.draw()
		b = b.placeMino(m, move[0])
		b.clearAndReturnLines()
		self.expb = b

		for i in range(move[1]):
			self.keyPress(126)

		pd = (move[0] - 3)
		if pd > 0:
			for i in range(pd):
				self.keyPress(124)
		else:
			for i in range(abs(pd)):
				self.keyPress(123)

		self.keyPress(49)
		sleep(lcWait)
		self.readScreen()


		for i in range(20):
			for j in range(10):
				if self.expb.board[i][j] != self.board.board[i][j]:
					print "Ops!"
					self.expb.draw()
					self.board.draw()
					print "---"
					break


	def draw(self):
		self.board.draw()
开发者ID:chaitub1,项目名称:python-tetrisai,代码行数:104,代码来源:TetrisBattleController.py


注:本文中的Board.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。