Tuesday, January 24, 2012

So where do we begin?

I was asked to develop a game using SDL during my graduation and I thought maybe I should give a short tutorial on how to develop a simple two player chess game! Exciting huh..?

I have used C++ with SDL here. And if you know about pointers and stuff in C/C++, it will be handy in knowing whats going on in the actual game.

Okay, I'll keep posting hints, tips and tricks on regular basis on how to solve simple chess game between two players. So far, I haven't had the chance to make some AI part for the computer. However, after completion of two player interface I'll start working on it and will keep posting regularly.

Moreover, I've already finished writing all the codes and the game is up and running perfectly. But, like philosopher Jagger once said, "You can't always get what you want". So, I'll be posting bits by bits and, anyone is up for discussion in the comment section!

So, would it work ?! ;)

class List
{
private:
class Piece
{
friend class List;
string name;
string start;
Piece *next;
int x, y, at;
char initials;
int player;

Piece(string id, string p, char init, int a, int b, int board, int numPlayer, Piece *nästa = NULL)
{
name = id;
start = p;
initials = init;
x = a;
y = b;
at = board;
player = numPlayer;
next = nästa;
}
};
Piece *head; // List header pointer
int length(Piece*); // implemented using recursion

public:
List()
{ head = NULL; }
~List();
void operator=(const List&); // overloaded operator
bool isEmpty(int,int);
bool isEnemy(int,int,int,int);
bool isLegal(int, int, int, int); //finds out if the move is legal or not
int getPlayer(int,int);
bool isKingSafe(int,int,int,int);// will the king be safe if i make this move or not???
char getName(int,int); //returns the initial of the piece
string getFullName(int,int); // full name of the peice
void appendNode(string, string, char, int, int, int, int);
//void insertNode(string, string);
void deleteNode(int,int);
void moveGenerator(int,int,int,int,int);
void make_Move(int,int,int,int);
int numNodes() { return length(head); } /* calls private function and returns length of the list */
bool pawn_move(int,int,int,int);
bool rook_move(int,int,int,int);
bool bishop_move(int,int,int,int);
bool knight_move(int,int,int,int);
bool king_move(int,int,int,int);
bool queen_move(int,int,int,int);
/* Shows all possible moves by calling each peices's move listings...*/
void get_PossibleMoves(int,int,vector&);
void possible_kingmoves(int,int,vector&);
void possible_rookmoves(int,int,vector&);
void possible_bishopmoves(int,int,vector&);
void possible_knightmoves(int,int,vector&);
void possible_pawnmoves(int,int,vector&);
bool king_Dying(int,int,int,int); /* Check if the king would be in danger */
bool isChecked( int );//returns true if the player in the argument is Checked by an opponent
bool handle_events( int );
void blink_screen( const vector& );
void show_king_saving_moves( int , vector& );
void showGreetings( int );
void setPiece(int,int,char);
};
// chesboard
List Temp;
List Chess;