Skip to content
Snippets Groups Projects
Commit a2c1478f authored by Aidan Mariglia's avatar Aidan Mariglia
Browse files

Merge branch 'feature/gameclass' into 'main'

Feature/gameclass

See merge request !2
parents dd30f415 7d5dd828
No related branches found
No related tags found
1 merge request!2Feature/gameclass
Showing
with 214 additions and 129 deletions
# Editors
.vscode/
.idea/
*.swp
# Vagrant
.vagrant/
......
<?xml version="1.0" encoding="UTF-8"?><project name="3XA3_Gant" company="" webLink="http://" view-date="2022-03-31" view-index="0" gantt-divider-location="700" resource-divider-location="300" version="3.1.3102" locale="en_CA">
<?xml version="1.0" encoding="UTF-8"?><project name="3XA3_Gant" company="" webLink="http://" view-date="2022-03-02" view-index="0" gantt-divider-location="700" resource-divider-location="300" version="3.1.3102" locale="en_CA">
<description/>
<view zooming-state="default:1" id="gantt-chart">
<field id="tpd3" name="Name" width="315" order="0"/>
<field id="tpd4" name="Begin date" width="191" order="1"/>
<field id="tpd5" name="End date" width="190" order="2"/>
<timeline><![CDATA[0]]></timeline>
<option id="color.recent"><![CDATA[#3300cc #ff3333 #00ff00 #ff9999 #ff9900 #00ffff #6666ff #009900 #ff66ff]]></option>
<option id="color.recent"><![CDATA[#6666ff #3300cc #ff3333 #00ff00 #ff9999 #ff9900 #00ffff #009900 #ff66ff]]></option>
</view>
<view id="resource-table">
<field id="0" name="Name" width="210" order="0"/>
......@@ -43,11 +43,12 @@
<task id="34" name="Develop Proof of Concept" color="#009900" meeting="false" start="2022-02-11" duration="18" complete="0" thirdDate="2022-02-04" thirdDate-constraint="0" expand="true"/>
<task id="36" name="Gather Game Assets" color="#009900" meeting="false" start="2022-02-04" duration="6" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
</task>
<task id="19" name="Test Plan Revision 0" color="#6666ff" meeting="false" start="2022-02-28" duration="12" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true">
<task id="59" name="Implementing Tests" color="#6666ff" meeting="false" start="2022-03-05" duration="7" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="60" name="Planning Tests" color="#6666ff" meeting="false" start="2022-02-28" duration="6" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="61" name="Documenting Tests" color="#6666ff" meeting="false" start="2022-02-28" duration="6" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="19" name="Test Plan Revision 0" color="#6666ff" meeting="false" start="2022-02-28" duration="35" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true">
<task id="59" name="Implementing Tests" color="#6666ff" meeting="false" start="2022-03-05" duration="30" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="60" name="Planning Tests" color="#6666ff" meeting="false" start="2022-02-28" duration="12" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="61" name="Documenting Tests" color="#6666ff" meeting="false" start="2022-02-28" duration="12" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
</task>
<task id="66" name="Ongoing manually testing" color="#6666ff" meeting="false" start="2022-03-05" duration="30" complete="0" thirdDate="2022-03-05" thirdDate-constraint="0" expand="true"/>
<task id="26" name="Design and Document Revision 0" color="#ff9900" meeting="false" start="2022-02-28" duration="19" complete="0" thirdDate="2022-02-28" thirdDate-constraint="0" expand="true"/>
<task id="27" name="Revision 0 Demonstration" color="#ff9999" meeting="false" start="2022-03-01" duration="21" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
<task id="29" name="Final Demonstration (Revision 1)" color="#ff3333" meeting="false" start="2022-04-04" duration="4" complete="0" thirdDate="2022-02-01" thirdDate-constraint="0" expand="true"/>
......@@ -65,14 +66,20 @@
<allocation task-id="10" resource-id="0" function="Default:1" responsible="true" load="50.0"/>
<allocation task-id="36" resource-id="0" function="Default:1" responsible="true" load="25.0"/>
<allocation task-id="34" resource-id="0" function="Default:1" responsible="true" load="50.0"/>
<allocation task-id="66" resource-id="0" function="Default:1" responsible="true" load="10.0"/>
<allocation task-id="59" resource-id="0" function="Default:1" responsible="true" load="10.0"/>
<allocation task-id="0" resource-id="1" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="7" resource-id="1" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="10" resource-id="1" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="34" resource-id="1" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="66" resource-id="1" function="Default:1" responsible="false" load="10.0"/>
<allocation task-id="59" resource-id="1" function="Default:1" responsible="false" load="10.0"/>
<allocation task-id="0" resource-id="2" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="7" resource-id="2" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="10" resource-id="2" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="34" resource-id="2" function="Default:1" responsible="false" load="50.0"/>
<allocation task-id="66" resource-id="2" function="Default:1" responsible="false" load="10.0"/>
<allocation task-id="59" resource-id="2" function="Default:1" responsible="false" load="10.0"/>
</allocations>
<vacations/>
<previous/>
......
import pygame, sys
from pygame.locals import *
from squareMap import *
##prodives methods for updating the display
class Display:
CELLSIZE = 100
DARK, LIGHT = (220, 211, 234), (138, 129, 93)
SIZE = WIDTH, HEIGHT = CELLSIZE*8, CELLSIZE*8
## Display class constuctor
# @param
def __init__(self):
#TODO
self.board = pygame.Surface((Display.CELLSIZE*8, Display.CELLSIZE*8))
self.board.fill(Display.DARK)
self.screen = pygame.display.set_mode(Display.SIZE)
self.pieces = self.import_pngs()
self.pieceRects = self.get_rects(self.pieces)
##create board image
def create_board(self):
for x in range (0, 8, 2):
for y in range(0, 8, 2):
pygame.draw.rect(self.board, Display.LIGHT,
(x * Display.CELLSIZE, y * Display.CELLSIZE,
Display.CELLSIZE, Display.CELLSIZE))
for x in range (1, 8, 2):
for y in range(1, 8, 2):
pygame.draw.rect(self.board, Display.LIGHT,
(x * Display.CELLSIZE, y * Display.CELLSIZE,
Display.CELLSIZE, Display.CELLSIZE))
##import piece pngs
def import_pngs(self):
return {
'P': pygame.image.load("assets/white_pawn.png"),
'N': pygame.image.load("assets/white_horse.png"),
'B': pygame.image.load("assets/white_bishop.png"),
'R': pygame.image.load("assets/white_rook.png"),
'Q': pygame.image.load("assets/white_queen.png"),
'K': pygame.image.load("assets/white_king.png"),
'p': pygame.image.load("assets/black_pawn.png"),
'n': pygame.image.load("assets/black_horse.png"),
'b': pygame.image.load("assets/black_bishop.png"),
'r': pygame.image.load("assets/black_rook.png"),
'q': pygame.image.load("assets/black_queen.png"),
'k': pygame.image.load("assets/black_king.png"),
}
##generate rect objects for pngs
def get_rects(self, pngs):
return {
'P': pngs['P'].get_rect(),
'N': pngs['N'].get_rect(),
'B': pngs['B'].get_rect(),
'R': pngs['R'].get_rect(),
'Q': pngs['Q'].get_rect(),
'K': pngs['K'].get_rect(),
'p': pngs['p'].get_rect(),
'n': pngs['n'].get_rect(),
'b': pngs['b'].get_rect(),
'r': pngs['r'].get_rect(),
'q': pngs['q'].get_rect(),
'k': pngs['k'].get_rect(),
}
#TODO, take dictionary from game class, use lookup to convert
# from square numbers 0 - 63 and relate to coords,
#or look at other board display options
def draw_pieces(self, piece_dict):
for square, piece in piece_dict.items():
self.pieceRects[piece.symbol()].x = \
squareMap[chess.square_name(square)][0]
self.pieceRects[piece.symbol()].y = \
squareMap[chess.square_name(square)][1]
self.screen.blit(
self.pieces[piece.symbol()], self.pieceRects[piece.symbol()])
if __name__=="__main__":
d = Display()
d.create_board()
b = chess.BaseBoard()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
d.screen.blit(d.board, d.board.get_rect())
d.draw_pieces(b.piece_map())
pygame.display.flip()
import chess
## Represents the core game functionality
class Game():
## Game class constructor
# @param
def __init__(self):
#TODO
self.__board = chess.BaseBoard()
## Initializes a new game
def start_game(self):
#TODO
pass
##returns a dictionary mapping pieces to squares
def get_piece_map(self):
return self.__board.piece_map()
if __name__=="__main__":
g = Game()
import Game
import Display
class Main:
def __init__(self):
g = Game.Game()
d = Display.Display()
if __name__=="__main__":
m = Main()
PythonChess/src/Game/assets/black_bishop.png

7.64 KiB

PythonChess/src/Game/assets/black_horse.png

9.14 KiB

PythonChess/src/Game/assets/black_king.png

10.8 KiB

PythonChess/src/Game/assets/black_pawn.png

5.06 KiB

PythonChess/src/Game/assets/black_queen.png

11.8 KiB

PythonChess/src/Game/assets/black_rook.png

7.39 KiB

PythonChess/src/Game/assets/white_bishop.png

8.85 KiB

PythonChess/src/Game/assets/white_horse.png

8.86 KiB

PythonChess/src/Game/assets/white_king.png

10.1 KiB

PythonChess/src/Game/assets/white_pawn.png

5.72 KiB

PythonChess/src/Game/assets/white_queen.png

13.4 KiB

PythonChess/src/Game/assets/white_rook.png

8.29 KiB

import chess
squareMap = {
'a1': [0,0],
'b1': [100,0],
'c1': [200,0],
'd1': [300,0],
'e1': [400,0],
'f1': [500,0],
'g1': [600,0],
'h1': [700,0],
'a2': [0,100],
'b2': [100,100],
'c2': [200,100],
'd2': [300,100],
'e2': [400,100],
'f2': [500,100],
'g2': [600,100],
'h2': [700,100],
'a3': [0,200],
'b3': [100,200],
'c3': [200,200],
'd3': [300,200],
'e3': [400,200],
'f3': [500,200],
'g3': [600,200],
'h3': [700,200],
'a4': [0,300],
'b4': [100,300],
'c4': [200,300],
'd4': [300,300],
'e4': [400,300],
'f4': [500,300],
'g4': [600,300],
'h4': [700,300],
'a5': [0,400],
'b5': [100,400],
'c5': [200,400],
'd5': [300,400],
'e5': [400,400],
'f5': [500,400],
'g5': [600,400],
'h5': [700,400],
'a6': [0,500],
'b6': [100,500],
'c6': [200,500],
'd6': [300,500],
'e6': [400,500],
'f6': [500,500],
'g6': [600,500],
'h6': [700,500],
'a7': [0,600],
'b7': [100,600],
'c7': [200,600],
'd7': [300,600],
'e7': [400,600],
'f7': [500,600],
'g7': [600,600],
'h7': [700,600],
'a8': [0,700],
'b8': [100,700],
'c8': [200,700],
'd8': [300,700],
'e8': [400,700],
'f8': [500,700],
'g8': [600,700],
'h8': [700,700],
}
import chess, pygame
from squareMap import squareMap
#this is kinda sloppy, but since chess.Piece is implemented as a
#dataclass there isn't a better way to extend it
class piece:
"""
``P``, ``N``, ``B``, ``R``, ``Q`` or ``K`` for white
pieces or the lower-case variants for the black pieces.
"""
images = {
'P' : 'assets/white_pawn.png',
'N' : 'assets/white_knight.png',
'B' : 'assets/white_bishop.png',
'R' : 'assets/white_rook.png',
'Q' : 'assets/white_queen.png',
'K' : 'assets/white_king.png',
'p' : 'assets/black_pawn.png',
'n' : 'assets/black_knight.png',
'b' : 'assets/black_bishop.png',
'r' : 'assets/black_rook.png',
'q' : 'assets/black_queen.png',
'k' : 'assets/black_king.png',
}
def __init__(self, piecetype, color):
self.p = chess.Piece(piecetype, color)
self.img = pygame.image.load(self.images[self.p.symbol()])
self.rect = self.img.get_rect()
def move_to_square(self, square):
self.rect.x = squareMap[square][0]
self.rect.y = squareMap[square][1]
import chess
squareMap = {
chess.A1: [0,0],
chess.B1: [100,0],
chess.C1: [200,0],
chess.D1: [300,0],
chess.E1: [400,0],
chess.F1: [500,0],
chess.G1: [600,0],
chess.H1: [700,0],
chess.A2: [0,100],
chess.B2: [100,100],
chess.C2: [200,100],
chess.D2: [300,100],
chess.E2: [400,100],
chess.F2: [500,100],
chess.G2: [600,100],
chess.H2: [700,100],
chess.A3: [0,200],
chess.B3: [100,200],
chess.C3: [200,200],
chess.D3: [300,200],
chess.E3: [400,200],
chess.F3: [500,200],
chess.G3: [600,200],
chess.H3: [700,200],
chess.A4: [0,300],
chess.B4: [100,300],
chess.C4: [200,300],
chess.D4: [300,300],
chess.E4: [400,300],
chess.F4: [500,300],
chess.G4: [600,300],
chess.H4: [700,300],
chess.A5: [0,400],
chess.B5: [100,400],
chess.C5: [200,400],
chess.D5: [300,400],
chess.E5: [400,400],
chess.F5: [500,400],
chess.G5: [600,400],
chess.H5: [700,400],
chess.A6: [0,500],
chess.B6: [100,500],
chess.C6: [200,500],
chess.D6: [300,500],
chess.E6: [400,500],
chess.F6: [500,500],
chess.G6: [600,500],
chess.H6: [700,500],
chess.A7: [0,600],
chess.B7: [100,600],
chess.C7: [200,600],
chess.D7: [300,600],
chess.E7: [400,600],
chess.F7: [500,600],
chess.G7: [600,600],
chess.H7: [700,600],
chess.A8: [0,700],
chess.B8: [100,700],
chess.C8: [200,700],
chess.D8: [300,700],
chess.E8: [400,700],
chess.F8: [500,700],
chess.G8: [600,700],
chess.H8: [700,700],
}
pieceImages = {
'P' : 'assets/white_pawn.png',
'N' : 'assets/white_knight.png',
'B' : 'assets/white_bishop.png',
'R' : 'assets/white_rook.png',
'Q' : 'assets/white_queen.png',
'K' : 'assets/white_king.png',
'p' : 'assets/black_pawn.png',
'n' : 'assets/black_knight.png',
'b' : 'assets/black_bishop.png',
'r' : 'assets/black_rook.png',
'q' : 'assets/black_queen.png',
'k' : 'assets/black_king.png',
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment