Monday, 23 April 2018

Chess Game

The following is a revisit from Object Oriented Analysis Data (OOAD) assignment.

Introduction

In Object Oriented Analysis Data introduce us to programming language JAVA. Previously in other programming subject we use C++ as our primary language. The subject cover all advantages of object oriented such as Polymorphism, Inheritance, Encapsulation and Abstract. The purpose of the assignment is to use all object oriented advantages.


The Chess Game assignment is to create a chess application without use any library. The following is the few example of explicit and implicit rule : 

Explicit rules

  • It require to display the Chess Board
  • Chess Board will be 5x5
  • Each chess piece will have different type(SUN,MOON and STAR)
  • Each type will have different move list
  • Each player will have their own Chess Piece set
  • Each player will have their own turns
  • If player able to pin opponent Star chess piece it is a game over.

Inplicit rules

  • Player unable to move a chess piece if he/she click outside the board or chess box not belong to the chess piece move list
  • If player press chess box not belong to any chess piece, his/her will not end the turn

UML

Class Summary


Chess Board

The Chess Board will be holding/involving all the chess piece and chess box. The chess board also involving player object (player 1 and player 2).

Chess Box

Chess box is using extend of JButton class, this allow to use all thier method and added extra new method. In brief, the chess box have the same action listener. The different is where if the chess box is empty or not. If the chess piece is included inside the chess box. I will react a different from the empty chess box, the react will be different between each chess piece.

Chess Piece

The Chess Piece is divided into 3 different Piece: Sun, Moon Star. Basically divided the Chess Piece into parent-child base. Where the Chess Piece become the parent while the rest become a child class. This allow all child class have different method but different properties such as move list. Star will act as King in a normal chess game. Game is depend who can pin his/her opponent Star first.

Coordinate

Since many classes use 2 point as coordination reference (x-axis & y-axis), therefore I create a Coordinate to hold both value.

UI panel

The UI panel will display player action. Example current player turn, current chess piece and it move list. Commant Prompt show the action of player, for example if player press chess box contain chess piece it will display "Player1 is pressing box [1,4]".

Player Flowchart

On each turn, one player status will be "ready" while other is "moving".
  1. Player start with current player status is ready.
  2. Programme will wait player to click a chess box the programme will check rather it contain chess piece. If yes it will change the player status into moving.If does not contain it will be repeat this process
  3. Next the programme will be wating for next chess box to be click. If the next chess box is does not contain any chess piece, player status will revert back to ready and repeat the previous step. If the player click an empty chess box, the will move the chess piece and end his/her turn
  4. If the chess box contain player very own chess piece it will loop back to step 1, else chess box contain the oponnet chess piece. It will remove the opponent chess piece and move player chess piece.The player will end the turn

Game Flowchart

  1. Game start with player 1 move first
  2. Next it will check if player able pin Star chess piece
  3. If not it will switch player turn,else game will end

Game Layout

Chess Piece Move list

Sun

Star

Moon

Download

Chess Game with source code
Chess Game Jar

Bug

There is a bug where a chess piece can hop over.