Monday 27 January 2014

Writing your own TWO-PLAYER CHESS GAME -

TWO PLAYER CHESS GAME
Introduction
·         Basic graphics user interface implemented with 2D shapes and graphics.
·         Almost similar to chess game present in windows.
·         When a chess piece is clicked all possible moves of former is highlighted with blue squares.
·         Have the feature of pawn promotion.

Language Used
JAVA
Implementation
User defined classes
·         public class chess_2p
·         public class kchess


public class chess_2p
Important Methods
Description
public static void main(String[] args)
Starting point of the program.Ensures data in program are initialized only once.
private static void createAndShowGUI()
Creates new Jframe and embeds an instance of kchess in it.
Kchess class defines the complete game.

class kchess extends JPanel
Important variables
Description
int x[]=new int[120]
Keeps the x-coordinate for all the squares in
the window.

int y[]=new int[120]
Keeps the y-coordinate for all the squares in
the window.

int mousex
Holds the x-coordinate of the place where the mouse is clicked.
int mousey
Holds the y-coordinate of the place where the mouse is clicked.

int flag[]=new int[120]
Index represents the position and values inside it represent wether chess piece is present or not.
1 to 16-red chess pieces
48-63-white chess pieces
0-represent no chess pieces
int f[]=new int[40]
Holds all possible moves if chess piece is clicked.
User defined methods
Important Methods
Description
Kchess() constructer
Calls dinit() function.
Sets the background and foegroung color.
Adds mouselistner adapter.
private void dinit()
Initializes array x and y.
private int get_pos(int x,int y)
Returns the number which is the position of
Square clicked.
private void set1(Graphics g)
Draws all the red chess pieces.
private void set2(Graphics g)
Draws all the white chess pieces.
private void clear_f()
Clears the f array.
Sets the value to 999.

private boolean comp_r(int k)
Returns true if  square is in the possible moves of the selectd chess piece.

private void intro(Graphics g)
Draws the descriptive representation of chess pieces on left side of the window.

private void draw_knight(Graphics g,int k)
Draws knight at kth position square.

private void draw_pawn(Graphics g,int k)
Draws pawn at kth position square.

private void draw_king(Graphics g,int k)
Draws king at kth position square.

private void draw_queen(Graphics g,int k)
Draws queen at kth position square.

private void draw_rook(Graphics g,int k)
Draws rook at kth position square.

private void draw_bishop(Graphics g,int k)
Draws rook at kth position square.

private void set_property(Graphics g,int k)
If chess piece is present at the kth square then it changes the color of all possible moves of the chess piece to blue.
The possible moves are identified by values
present in array f.
private void set_pawn(int k)
Sets the value of array f according to all possible moves of selected white pawn.
private void set_rook(int k)
Sets the value of array f according to all possible moves of selected white rook.
private void set_king(int k)
Sets the value of array f according to all possible moves of selected white king.
private void set_bishop(int k)
Sets the value of array f according to all possible moves of selected white bishop.
private void set_queen(int k)
Sets the value of array f according to all possible moves of selected white queen.
private void set_knight(int k)
Sets the value of array f according to all possible moves of selected white knight.
private void draw_rect(Graphics g)
Draws and fill the squares.
private void set_com_pawn(int k)
Sets the value of array f according to all possible moves of selected red pawn.
private void set_com_rook(int k)
Sets the value of array f according to all possible moves of selected red rook.
private void set_com_king(int k)
Sets the value of array f according to all possible moves of selected red king.
private void set_com_bishop(int k)
Sets the value of array f according to all possible moves of selected red bishop.
private void set_com_queen(int k)
Sets the value of array f according to all possible moves of selected red queen.
private void set_com_knight(int k)
Sets the value of array f according to all possible moves of selected red knight.
Overriden methods
protected void paintComponent(Graphics g)
Draws the 8X8 chess board.
Calls intro() method to draw chess pieces description.
public void update(Graphics g)
Called through repaint() when event(mouse click) occurs.
If chess piece clicked-all possible moves are shown through blue squares.
If blue square is clicked-the selected chess piece moves to the desired position.

References
The complete references JAVA by Herbert Schildt .

Internet 


SNAPSHOTS







MINESWEEPER in turbo c

Introduction
Minesweeper is a single player game. The objective of the game is to clear an abstract minefield without detonating the mine.
Developed In
C(with 32 bit turbo c compiler)
Input
a - Moves the cursor left.
s - Moves the cursor down.
w - Moves the cursor up.
d - Moves the cursor right.
e - Enter key.
x - Exit key.
Feature
·         Made on the input/output console without the use of Graphics function.
·         Interface of the game is developed using textbackground color and text color.
·         Bombs are placed randomly each time the game starts.
Implementation
Important variables
Description
Int a[110]
Index represent the position and value  represent thr presence of bomb or not.
0-bomb
9-no bomb in the surrounding
After enter(e) all values are increased with 10.
Static int c
Current cursor position.
int r1,r2,r3
Random variables
User defined function
Important functions
Description
int main()
Placing of bomb at random places.
Counting the total number of bombs in surrounding.
Call to graphics function.
void graphics(int a[110])
Renders the graphics for interface.
int cursor()
Returns the position of the cursor.
void gamechanger(int a[110],int j)
Unlocks the area until it encounters number or boundary.

References
Let us c-Yeshvant Kanethkar
Minesweeper
Snapshot 1


Snapshot 2