Last active
August 29, 2015 14:16
-
-
Save kvalv/d8934a545ce5e478878a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package chess; | |
| import chess.ChessPiece; | |
| import chess.Color; | |
| import chess.PiecePosition; | |
| import java.util.Scanner; | |
| public class GameEnginge { | |
| static CheckBoard chessBoard = new CheckBoard(); | |
| GameEnginge () { | |
| } | |
| static void runGame () { | |
| addPieces(); | |
| Scanner inputScan = new Scanner ( System.in ); | |
| boolean play = true; | |
| while ( play ) { | |
| chessBoard.updateChessBoard(); | |
| chessBoard.printBoard(); | |
| System.out.print("enter move: "); | |
| String inputString = inputScan.nextLine(); | |
| if ( inputString.toUpperCase() == "Q" ) { play = false; } | |
| makeNewMove ( inputString ); | |
| } | |
| inputScan.close(); | |
| } | |
| static void addPieces () { | |
| Pawn pawn1 = new Pawn ( Color.BLACK, new PiecePosition (1,2), chessBoard ); | |
| Pawn pawn2 = new Pawn ( Color.BLACK, new PiecePosition (2,2), chessBoard ); | |
| Pawn pawn3 = new Pawn ( Color.BLACK, new PiecePosition (3,2), chessBoard ); | |
| Pawn pawn4 = new Pawn ( Color.BLACK, new PiecePosition (4,2), chessBoard ); | |
| Pawn pawn5 = new Pawn ( Color.BLACK, new PiecePosition (5,2), chessBoard ); | |
| Pawn pawn6 = new Pawn ( Color.BLACK, new PiecePosition (6,2), chessBoard ); | |
| Pawn pawn7 = new Pawn ( Color.BLACK, new PiecePosition (7,2), chessBoard ); | |
| Pawn pawn8 = new Pawn ( Color.BLACK, new PiecePosition (8,2), chessBoard ); | |
| King king1 = new King ( Color.BLACK, new PiecePosition (5,1), chessBoard ); | |
| Queen queen1 = new Queen ( Color.BLACK, new PiecePosition (4,1), chessBoard ); | |
| Rook rook1 = new Rook ( Color.BLACK, new PiecePosition (1,1), chessBoard ); | |
| Rook rook2 = new Rook ( Color.BLACK, new PiecePosition (8,1), chessBoard ); | |
| Bishop bishop1 = new Bishop ( Color.BLACK, new PiecePosition (3,1), chessBoard ); | |
| Bishop bishop2 = new Bishop ( Color.BLACK, new PiecePosition (6,1), chessBoard ); | |
| Knight knight1 = new Knight ( Color.BLACK, new PiecePosition (2,1), chessBoard ); | |
| Knight knight2 = new Knight ( Color.BLACK, new PiecePosition (7,1), chessBoard ); | |
| Pawn pawn11 = new Pawn ( Color.WHITE, new PiecePosition (1,7), chessBoard ); | |
| Pawn pawn12 = new Pawn ( Color.WHITE, new PiecePosition (2,7), chessBoard ); | |
| Pawn pawn13 = new Pawn ( Color.WHITE, new PiecePosition (3,7), chessBoard ); | |
| Pawn pawn14 = new Pawn ( Color.WHITE, new PiecePosition (4,7), chessBoard ); | |
| Pawn pawn15 = new Pawn ( Color.WHITE, new PiecePosition (5,7), chessBoard ); | |
| Pawn pawn16 = new Pawn ( Color.WHITE, new PiecePosition (6,7), chessBoard ); | |
| Pawn pawn17 = new Pawn ( Color.WHITE, new PiecePosition (7,7), chessBoard ); | |
| Pawn pawn18 = new Pawn ( Color.WHITE, new PiecePosition (8,7), chessBoard ); | |
| King king11 = new King ( Color.WHITE, new PiecePosition (5,8), chessBoard ); | |
| Queen queen11 = new Queen ( Color.WHITE, new PiecePosition (4,8), chessBoard ); | |
| Rook rook11 = new Rook ( Color.WHITE, new PiecePosition (1,8), chessBoard ); | |
| Rook rook12 = new Rook ( Color.WHITE, new PiecePosition (8,8), chessBoard ); | |
| Bishop bishop11 = new Bishop ( Color.WHITE, new PiecePosition (3,8), chessBoard ); | |
| Bishop bishop12 = new Bishop ( Color.WHITE, new PiecePosition (6,8), chessBoard ); | |
| Knight knight11 = new Knight ( Color.WHITE, new PiecePosition (2,8), chessBoard ); | |
| Knight knight12 = new Knight ( Color.WHITE, new PiecePosition (7,8), chessBoard ); | |
| } | |
| private static void makeNewMove ( String inputString ) { | |
| if ( inputString.length() != 4 || | |
| !"abcdefgh".contains(Character.toString(inputString.charAt(0))) || | |
| !"12345678".contains(Character.toString(inputString.charAt(1))) || | |
| !"abcdefgh".contains(Character.toString(inputString.charAt(2))) || | |
| !"12345678".contains(Character.toString(inputString.charAt(3)))) { | |
| throw new IllegalArgumentException( "illegal input"); | |
| } | |
| PiecePosition pieceToBeMovedPos = new PiecePosition ( Character.getNumericValue ( inputString.charAt(0) ) - 9, | |
| Character.getNumericValue(inputString.charAt(1) ) ); | |
| PiecePosition moveToPosition = new PiecePosition ( Character.getNumericValue(inputString.charAt(2)) - 9, | |
| Character.getNumericValue(inputString.charAt(3) ) ); | |
| if ( chessBoard.containsChessPiece ( pieceToBeMovedPos ) ) { | |
| ChessPiece pieceToBeMoved = chessBoard.getChessPiece( pieceToBeMovedPos ); | |
| pieceToBeMoved.move( moveToPosition ); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package chess; | |
| public class Knight extends ChessPiece { | |
| Knight ( Color knightColor, PiecePosition knightPosition, CheckBoard checkBoard ) { | |
| super( knightColor, knightPosition, checkBoard ); | |
| if ( knightColor == Color.WHITE ) { | |
| this.pieceString = "\u2658 "; | |
| } else { | |
| this.pieceString = "\u265E "; | |
| } | |
| } | |
| @Override | |
| public void move(PiecePosition moveTo) { | |
| // TODO Auto-generated method stub | |
| } | |
| @Override | |
| boolean isLegitimateMove(PiecePosition moveTo, CheckBoard chessBoard) { | |
| if ( ! chessBoard.isClearOfSight( this, moveTo, MoveType.THATHORSEMOVEYOUKNOW ) ) { return false; } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment