0

I have a project to make in C-builder. I have to make Chess. The problem is that I have to make it using CLASSES. Like, class Board, class Square, class Piece. I can't find any helpful links.

If someone knows how to make classes and to move random the pieces on the board please help me. I was thinking about something like that: class Pawn : public class Piece.

Anyway, my real problem is this. For example, I'm trying to make class Piece and class Pawn. In class Piece I got 1 image that applies at all pieces depending by a code (#define PAWN 13). In class Pawn I need to load an image from file. How do I do that?

Look what I made until now:

File whRook.h :

class whRook : public Piesa
{
private:
        AnsiString strwhRookImg;
public:
        whRook(TForm*);
        void LoadImg();
};

File whRook.cpp :

whRook::whRook(TForm * form):Piesa(form){
             strwhRookImg = "graphics/bmp/wh_rook.bmp";
}

void whRook::LoadImg(){
             imPiesa->Picture->LoadFromFile(strwhRookImg);
}

File Piece.h :

class Piece
{
public:
       TImage *imPiesa;
} piece[32];

Errors: At TImage *imPiece:

Type name expected
Declaration missing ;
Weather Vane
  • 33,872
  • 7
  • 36
  • 56
  • Googling "object oriented chess" brought up [this answer](http://stackoverflow.com/a/4168110/2449857) on Stack Overflow. It's written in C# syntax, but hopefully you can interpret it and use it as a basis for a C++ design. – Jack Deeth Dec 12 '16 at 20:24
  • Possible duplicate of [Object Oriented Design for a Chess game](http://stackoverflow.com/questions/4168002/object-oriented-design-for-a-chess-game) – Jack Deeth Dec 12 '16 at 20:25
  • The other design has a `Piece` class, but doesn't derive to `Pawn`, `Rook` etc. Instead, the type of the `Piece` is stored as an enum data member. This makes sense as pieces can change type - specifically, promoting pawns. – Jack Deeth Dec 12 '16 at 20:29
  • @JackDeeth I saw that too. I made classes, but empty for now. Now I need to load image from file for each piece. – Mocanu Cristian Dec 12 '16 at 20:50

0 Answers0