Mert Us Matthew Hannay Logan Starr
Dependencies: mbed 4DGL-uLCD-SE
Diff: main.cpp
- Revision:
- 7:9e01c9a334dc
- Parent:
- 6:1c4dd5e24b8d
- Child:
- 8:928d5d33258f
diff -r 1c4dd5e24b8d -r 9e01c9a334dc main.cpp --- a/main.cpp Mon Nov 14 21:36:39 2022 +0000 +++ b/main.cpp Wed Nov 16 01:06:20 2022 +0000 @@ -6,6 +6,8 @@ enum Piece {e, wK, bK, wQ, bQ, wR, bR, wB, bB, wN, bN, w, b}; +enum GameState {whiteSelecting, whitePickedUp, blackSelecting, blackPickedUp}; + struct pixelCoord { uint8_t x; uint8_t y; @@ -489,6 +491,10 @@ } // gets the pixel coordinates of the top left of the square + pixelCoord getTopLeftOfSquare(boardPos pos) + { + return getTopLeftOfSquare(pos.row, pos.column); + } pixelCoord getTopLeftOfSquare(int row, int column) { pixelCoord topLeft; @@ -500,6 +506,10 @@ // PIECE MOVEMENT AND GRAPHICS FUNCTIONS // returns the piece at a given location + Piece getPiece(boardPos pos) + { + return getPiece(pos.row, pos.column); + } Piece getPiece(int row, int column) { return boardState.getPiece(row, column); @@ -508,6 +518,10 @@ /* puts the bit representation of a piece at the set position of the board assumes that the position of the board is emptied beforehand */ + void placePieceAndDraw(Piece piece, boardPos pos) + { + placePieceAndDraw(piece, pos.row, pos.column); + } void placePieceAndDraw(Piece piece, int row, int column) { boardState.placePiece(piece, row, column); @@ -545,6 +559,10 @@ /* removes a piece from the set position of the board returns the bit representation of the piece */ + Piece removePieceAndDraw(boardPos pos) + { + return removePieceAndDraw(pos.row, pos.column); + } Piece removePieceAndDraw(int row, int column) { Piece removedPiece = boardState.removePiece(row, column); @@ -562,6 +580,10 @@ /* moves a piece from one position to another returns the captured piece */ + Piece movePieceAndDraw(boardPos startPos, boardPos endPos) + { + return movePieceAndDraw(startPos.row, startPos.column, endPos.row, endPos.column); + } Piece movePieceAndDraw(int startRow, int startColumn, int endRow, int endColumn) { Piece movingPiece = removePieceAndDraw(startRow, startColumn); @@ -573,6 +595,10 @@ // SQUARE BORDER GRAPHICS FUNCTIONS // removes selection border around square + void unselectSquare(boardPos pos) + { + unselectSquare(pos.row, pos.column); + } void unselectSquare(int row, int column) { pixelCoord tl = getTopLeftOfSquare(row, column); @@ -585,6 +611,11 @@ uLCD.rectangle(tl.x, tl.y, tl.x + 15, tl.y + 15, color); } + // draws the hover border around square + void hoverSquare(boardPos pos) + { + hoverSquare(pos.row, pos.column); + } void hoverSquare(int row, int column) { pixelCoord tl = getTopLeftOfSquare(row, column); @@ -592,6 +623,10 @@ } // draws selection border around square + void selectSquare(boardPos pos) + { + selectSquare(pos.row, pos.column); + } void selectSquare(int row, int column) { pixelCoord tl = getTopLeftOfSquare(row, column); @@ -599,7 +634,78 @@ } }; +// game variables +GameBoard gameBoard; +GameState state = whiteSelecting; +boardPos cursorPos = (boardPos) +{ + 3, 4 +}; +boardPos selectedPos = (boardPos) +{ + 3, 4 +}; + +// callbacks +void joyStickUp() +{ + if (cursorPos.row < 7) + { + boardPos nextPos; + nextPos.row = cursorPos.row + 1; + nextPos.column = cursorPos.column; + gameBoard.unselectSquare(cursorPos); + gameBoard.hoverSquare(nextPos); + cursorPos = nextPos; + } +} + +void joyStickDown() +{ + if (cursorPos.row > 0) + { + boardPos nextPos; + nextPos.row = cursorPos.row - 1; + nextPos.column = cursorPos.column; + gameBoard.unselectSquare(cursorPos); + gameBoard.hoverSquare(nextPos); + cursorPos = nextPos; + } +} + +void joyStickLeft() +{ + if (cursorPos.column > 0) + { + boardPos nextPos; + nextPos.row = cursorPos.row; + nextPos.column = cursorPos.column - 1; + gameBoard.unselectSquare(cursorPos); + gameBoard.hoverSquare(nextPos); + cursorPos = nextPos; + } +} + +void joyStickRight() +{ + if (cursorPos.column < 7) + { + boardPos nextPos; + nextPos.row = cursorPos.row; + nextPos.column = cursorPos.column + 1; + gameBoard.unselectSquare(cursorPos); + gameBoard.hoverSquare(nextPos); + cursorPos = nextPos; + } +} + +void joyStickPressed() +{ + // state machine goes here +} + int main() { + gameBoard = GameBoard(); return 0; } \ No newline at end of file