-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_board.py
58 lines (51 loc) · 2.21 KB
/
generate_board.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pygame
from constants import *
from tiles import *
from pieces import *
def gen_board(window):
# -- create checkerboard tiles --
tiles = pygame.sprite.Group()
i = 0
for column in range(1, 9):
for row in range(1, 9):
# -- decide what color the tile is --
if row % 2 == 0:
if column % 2 == 0:
tile_color = CHECKER_COL
else:
tile_color = BLACK
if row % 2 == 1:
if column % 2 == 0:
tile_color = BLACK
else:
tile_color = CHECKER_COL
# create the tile and add to sprite group
tiles.add(Tile(row, column, tile_color, window, i))
i += 1
# -- create peices --
pieces_group = pygame.sprite.Group()
# -- pawns --
for i in range(0, 8):
pieces_group.add(Pawn("img/pawnB.bmp", tiles.sprites()[8+i]))
pieces_group.add(Pawn("img/pawnW.bmp", tiles.sprites()[48+i]))
# -- bishops --
pieces_group.add(Bishop("img/bishopB.bmp", tiles.sprites()[2]))
pieces_group.add(Bishop("img/bishopB.bmp", tiles.sprites()[5]))
pieces_group.add(Bishop("img/bishopW.bmp", tiles.sprites()[58]))
pieces_group.add(Bishop("img/bishopW.bmp", tiles.sprites()[61]))
# -- knights --
pieces_group.add(Knight("img/knightB.bmp", tiles.sprites()[1]))
pieces_group.add(Knight("img/knightB.bmp", tiles.sprites()[6]))
pieces_group.add(Knight("img/knightW.bmp", tiles.sprites()[57]))
pieces_group.add(Knight("img/knightW.bmp", tiles.sprites()[62]))
#-- rooks --
pieces_group.add(Rook("img/rookB.bmp", tiles.sprites()[0]))
pieces_group.add(Rook("img/rookB.bmp", tiles.sprites()[7]))
pieces_group.add(Rook("img/rookW.bmp", tiles.sprites()[56]))
pieces_group.add(Rook("img/rookW.bmp", tiles.sprites()[63]))
# -- Royals --
pieces_group.add(Queen("img/queenB.bmp", tiles.sprites()[3]))
pieces_group.add(Queen("img/queenW.bmp", tiles.sprites()[59]))
pieces_group.add(King("img/kingB.bmp", tiles.sprites()[4]))
pieces_group.add(King("img/kingW.bmp", tiles.sprites()[60]))
return tiles, pieces_group