View Single Post
  #6 (permalink)  
Old 08-23-2006, 10:18 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,275
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

I'm a little rusty on Java, so my example will be in C++.
Code:
class piece
{
  public:
    bool moveTo(x,y);
    bool isThreatend();
    TYPE pieceType();
  private:
    COLOR color;
}

class pawn : piece
{
  private:
    bool EnPassante;
}

pawn myPawn;
piece myPiece;
myPiece has one data values: myPiece.color
myPawn has two data value: myPawn.color (inherited from the piece class) and myPawn.EnPassante
COLOR is an enumeration for the colors of chess pieces (Black and White).

Now I can make another class:

Code:
class Board
{
  public:
    void PlayGame();
  private:
    piece pieces[16][2];
}
This class has 32 pieces as data, each having a color and the ability to move.

Now, with a few more classes and some code for the methods, you have a chess program
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Reply With Quote