本文整理汇总了Python中Board.getBoard方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getBoard方法的具体用法?Python Board.getBoard怎么用?Python Board.getBoard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.getBoard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Board
# 需要导入模块: import Board [as 别名]
# 或者: from Board import getBoard [as 别名]
from Logic import *
from Board import *
import unittest
# sample board with the colour red
allTile = Board()
for x in range(6):
for y in range(6):
allTile.getBoard()[x][y] = 'R'
# sample board with color red and missing a piece at 2,3 (x,y).
missingTile = Board()
for x in range(6):
for y in range(6):
missingTile.getBoard()[x][y] = 'R'
missingTile.getBoard()[2][3] = 0
#Test class
class Test_Logic(unittest.TestCase):
# Tests the first function in Logic
# Checks if remove tile by passing a full board and the same board with a missing piece.
def test_removeTile(self):
print (str(missingTile))
print (allTile)
self.assertEqual(str(Logic.removeTile(allTile,2,3)), str(missingTile))
self.assertNotEqual(str(Logic.removeTile(allTile,5,5)), str(missingTile))
示例2: GameMenu
# 需要导入模块: import Board [as 别名]
# 或者: from Board import getBoard [as 别名]
#.........这里部分代码省略.........
if ((pos[0] >= mm_posx - 10) & (pos[0] <= mm_posx + mm_width + 5)) & ((pos[1] >= mm_posy - 10) & (pos[1] <= mm_posy + mm_height - 5)):
endDisplay = False
self.board = Board()
self.counter = 60
self.text = '60'
self.displayedScore = 0
self.score = 0
self.screen.fill(self.bg_color)
startDisplay = True
if ((pos[0] >= res_posx - 10) & (pos[0] <= res_posx + res_width + 5)) & ((pos[1] >= res_posy - 10) & (pos[1] <= res_posy + res_height - 5)):
endDisplay = False
self.board = Board()
self.counter = 60
self.text = '60'
self.displayedScore = 0
self.score = 0
self.screen.fill(self.bg_color)
gameDisplay = True
'''''''''
game display
'''''''''
if gameDisplay:
# game display (w/ timer, score, board, and restart)
self.display()
if event.type == pygame.MOUSEBUTTONDOWN:
self.isDragging = True
if event.type == pygame.MOUSEBUTTONUP:
self.isDragging = False
# if only one tile is selected, keep the same tile
if self.score == 1:
self.board.getBoard()[selectedRow][selectedCol] = selectedColour
# else, update total score and board
else:
self.displayedScore += self.score
Logic.addTile(self.board)
#turn score set to 0
self.score = 0
# when mouse button is down
if self.isDragging:
if event.type == pygame.MOUSEMOTION:
pos = pygame.mouse.get_pos()
if ((pos[0] >= 0) & (pos[0] <= self.gameWidth)) & ((pos[1] >= 0 & pos[1]) <= (self.gameHeight)): ## if we click within game display
column = pos[0] // (self.blockWidth + self.blockMargin) ##returns the y coordinate of the board
row = pos[1] // (self.blockHeight + self.blockMargin) ##returns the x coordinate of the board
if row >= self.maxRows:
row = 5
if column >= self.maxColumns:
column = 5
#select first piece
if self.score == 0:
selectedRow = row
selectedCol = column
selectedColour = self.board.getBoard()[row][column]
Logic.removeTile(self.board, selectedRow, selectedCol)
self.score += 1
#for new pieces selected
if self.score >= 1:
if Logic.adjacent(selectedRow, selectedCol, row, column) & Logic.colourMatch(self.board, row, column, selectedColour): # if colours are the same, and the tiles are adjacent
selectedRow = row
selectedCol = column
Logic.removeTile(self.board, selectedRow, selectedCol)