Added the boardgame tic-tac-toe without winning conditions, written entirely in Python.
This commit is contained in:
parent
0590fa6ca1
commit
affcb739b4
28 changed files with 448 additions and 0 deletions
18
games/tic-tac-toe/board.py
Normal file
18
games/tic-tac-toe/board.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from rectangle import Rectangle
|
||||
from gamerectangle import GameRectangle
|
||||
from math import sqrt
|
||||
#param: nr_of_squares, dimensions(could be a Rectangle)
|
||||
#creates an array of gamerectangles within itself with correct
|
||||
#positions from each other
|
||||
|
||||
class Board(object):
|
||||
def __init__(self, nr_of_rectangles, dimensions):
|
||||
self.game_rectangles = []
|
||||
axis = sqrt(nr_of_rectangles)
|
||||
width = dimensions.width
|
||||
height = dimensions.height
|
||||
for index in range(nr_of_rectangles):
|
||||
x = width * (index % axis)
|
||||
y = height * int(index / axis)
|
||||
gr = GameRectangle(index, x, y, width, height)
|
||||
self.game_rectangles.append(gr)
|
||||
Reference in a new issue