Background

This project was primarily designed for a semester project for “Computer Programming”. This project, as its title “BAGHACHAL(TWO PLAYER)” suggests, is an attempt to develop a game that is not only a game but it’s an approach to create much more complicatedsoftware like these.

We will not boast that the project is complete by itself and bug-free at its present version; however, we believe it can serve as a starting point for future who want to develop more interactive and user friendly software.

In our point of view we find students playing various kinds of games built with a very good graphics and control. Well at the same time they are cheering about the games they forget their potentiality that they are also able to build such kind of games. Well we are just trying to show them that we can also develop such kind of software and gaming stuffs but with right kind of dedication and logical thinking.

We sincerely hope that the program fulfils its purpose and proves helpful to anyone who might use it on the entertainment basis as well as logical basis.

Anyone wishing to improve and upgrade the program is very welcome to do so.

Developers:-Saraju palukasi and Ksitiz shrestha

PROGRAM THEORY AND DISCUSSION

  1. ALGORITHM

main()

As the program is run, it starts executing from main function. Many functions like Print(), load(), display(), box(), initialize(), and genmove() functions are called here for different functions. As it calls genmove() function the movement box take place. And the main function is never called again. So the program never terminates from the main function in this project.

Algorithm for function main()

Step 1: Start

Step 2: Initialize graphics variables as:

Int gdrive=0,gmode;

And initialize graphics as:

Initgraph(&gdriver,&gmode,”C:\\TC\\BGI”);

Step 3: Call the function Print() to show welcome and game instruction.

Step 4: Call the function load() to display loading screen.

Step 5: Call the function display() to show board.

Step 6: Call function box() to show movable box.

Step 7: Call function intitialize() to shoe position of the tigers.

Step 8: Call function genmove() to move box.

Step 9: End

Print():

This function just displays different information about the game e.g. the rules of the games, instructions and the control keys. Neither any value is passed to this function nor it returns any.

Algorithm for function Print():

Step 1: Start

Step 2: Display:“Welcome to the Nepal's ancient game BAGHACHAL in computer.”

Step 3:Make the screen still until any character is entered by the user using getch() function.

Step 4: Display:

“Game instructions:

->Use arrow keys to move the box.

->For move the tiger fix the box in a tiger and press enter...

->And move box to desire position and press enter again.

->For goat just press enter at the desire position.

->After placing 20 goat you can move goat just like tiger.

->goats are need to place in those position so that tiger can't kill.

->Tiger kill the goat by jumping over the goat with valid move.

->If there is no extra valid move of the tiger then goat win.

->If tiger kill 6 goats then tiger win

->If you want to exit game press esc.

Press any key to play game...”

Step 5: Once again make the screen still until the user enters any character

Step 6: Check if(getch()==27)

Step 7: If yes exit the game, else continue the game.

Step 8: End.

load():

The function load() display the loading on the screen for the while. Its display as the game is loading which show the game attractive.

Algorithm for the function load():

Step 1: declare variables row, col, r, c.

Step 2: declare double q.

Step 3: display “loading…”

Step 4: for r =1 to r<=20

For q=0 to q<=1000000.

Display “”.

Step 5: delay for 1 second.

Step 6: display “press any key to start….”.

Step 7: End.

display():

The function display show the board on the screen. It is the display of the board which need for the playing the game.

Algorithm for the function display():

Step 1: start.

Step 2: declare variables I and j.

Step 3: set color for the board.

Step 4: draw boxes for the board as

For i=75 to i<=375

j=75 to j<=375

rectangle(i-20,j-20,i+20,j+20).

Step 5: draw lines in the board as

Using for loop.

Step 6: End.

box():

The function put the pixel on the board where the tigers and goats can place or move in the board.

Algorithm for the function box():

Step 1: start.

Step 2:declare variables i,j.

Step 3: for i=1 to i<=5

For j=1 to j<=5

Putpixel(i*75,j*75,2).

Is i==1 and j==1? If yes

Putpixel(i*75,j*75,3)

Is i==5 and j==1? If yes

Putpixel(i*75,j*75,3)

Is i==1 and j==s? if yes

Putpixel(i*75,j*75,3)

Is i==5 and j==5? If yes

Putpixel(i*75,j*75,3)

Step 4: End.

initialize():

The function just display the tigers in their initial position in the board. This function call the function puttiger() as its required.

Algorithm for function initialize():

Step 1: Start.

Step 2 : declare i and j.

Step 3 : for i=1 and i<=375

For j=75 and j<=375

Is getpixel(i,j)==3 puttiger(i,j,6)

Step 4: End.

genmove():

The function is for the check of the turn of the player, goat remaining, goat killed and the game wining. It display the those thing at the side of the display where we know those things.

Algorithm for function genmove():

Step 1: start.

Step 2: declare variables i, goatphase=0.

Step 3: check is game==0 if yes then continue

Is main count ==1? If yes

Display “goat’s turn”

Is goatphase<20? If yes

Placegoat()

Display “goat remaining: %d”,19-goatphase.

goatphase++.

Else

goatmove();

maincount++.

Is maincount>1? If yes

Display “tiger’s turn”.

tigermove().

maincount=1.

Step 4: is game==1? If yes

Display “tiger wins”

Display “Thank you for playing”.

Step 5: End.

puttiger():

The function is for the shape of the tiger. The shape of the tiger is made by using simple graphics like circle, ellipse ect.

Algorithm for the function puttiger():

Step 1: start.

Step 2: declare variables x,y,color,c.

Step 3: set color for the filled shapes as

Setfillstyle(SOLID_FILL,color).

Step 4: set color for the tiger as

Setcolor(color).

Step 5: make circle for tiger shape as

Circle(x,y,15).

Step 6: make ears of the tiger as

Fillellipse(x-13,y-12,4,6).

Fillellipse(x+13,y-12,4,6).

Step 7: make eyes and mouth of the tiger as

Circle(x-7,y-5,3).

Circle(x+7,y-5,3).

Circle(x,y+6,4).

Step 8: put pixel on the tiger.

Step 9: End.

putgoat():

The function is for the shape of the goat. The shape of the goat is made as tiger shap.

Algorithm for the function putgoat():

Step 1: start.

Step 2: define variables x,y,color,c.

Step 3: set color for the filled shapes as

Setfillstyle(SOLID_FILL,color).

Step 4: set color for the goat as

Setcolor(color).

Step 5: make shape of the goat as

Fillellipse(x,y,17).

Fillellipse(x-12,y-12,6,4).

Fillellipse(x+12,y-12,6,4).

Step 6: put pixel on the goat.

Step 7: End.

selectbox():

The function is for the draw selection box on the board. The selection box select the positions of the goats and the tiger during the game.

Algorithm for the function selectbox():

Step 1: start.

Step 2: define variables x,y,color.

Step 3: set color for the box.

Step 4: make rectangle box as

Rectangle(x-25,y-25,x+25,y+25).

Step 5: end.

putcol():

The function check the valid move of the tiger. It provide red pixel if the tiger can move on those position. The function call ppcol() function.

Algorithm for the function putcol():

Step 1: start.

Step 2: declare variables x, y, i, j, cnt=0.

Step 3: for i=75 to i<=375

For j=75 to 375

cnt++

Is x==I and y==j? if yes

Call the function ppcol()

Step 4: End.

ppcol():

The function check the valid moves of the tiger. If there is any valid move of the tiger then the function place red pixel on the valid position for the tiger. The function is simply the rule for the tiger move and the killing of the goat by tiger. This function use lots of goto function. The goto function is applicable for the jumping from one step to another step directly if the condition is correct.

Algorithm for the function ppcol():

Step 1: start.

Step 2: declare variables x,y,cnt,I,j,tp.

Step 3: input tp=cnt%2.

Step 4: is tp==1? If yes

For i=x-75 to i<=x+75

For j=y-75 to j<=y+75

Is x==i and y==j? if yes then

Goto ppp.

Is i>=75 and i<=375 and j>=75 and j<=375 and getpixel(I,j)==2 ? if yes then

putpixel(i,j,4).

ppp:

For i=x-150 to i<=x+150

For j=y-150 to j<=y+150

Is x==I and y==j? if yes then goto qqq.

Is i>=75 and i<=375 and j>=75 and j<=375 and getpixel(I,j)==2 and getpixel((x+i)/2,(y+j)/2)==1 ? if yes then

Putpixel(i,j,6);

qqq:

Step 5: is tp==0? If yes then

for i=x-150 to i<=x+150

Is x==t? if yes then goto rrr.

Is i>=75 and i<=375 and getpixel(i,y)==2 and getpixet ((x+i)/2,y)==1? If yes then putpixel(I,y,6).

rrr:

for j=y-150 to j<=y+150

Is y==j ?if yes then goto sss.

Is j>=75 and j<=375 and getpixel(x,j)==2 and getpixet (x,(j+y)/2)==1? If yes then putpixel(I,y,6).

sss:

for i=x-17 to t<=x+75

Is x==i ? if yes then goto ttt.

Is i>=75 and i<=375 and getpixel (i,y)==2

Putpixel(I,y,4).

ttt:

for j=y-75 toj<=y+75

Is y==j ? if yes then goto uuu.

Is j>=75 and j<=375 and getpixel(x,j)==2)

putpixel(x,j,4);

uuu:

Step 6: End.

gputcol():

The function check the valid move of the goat. The function call gppcol() function.

Algorithm for the function gputcol():

Step1: start.

Step 2: declare variables x,y,i,j,cnt=0

Step 3: for i=75 to i<=375

For j=75 to j<=375

cnt++

Is x==i and y==j ?if yes then

Call function gppcol().

Step 4: End.

gppcol():

Step 1: start.

Step 2: declare variable x,y,cnt,I,j,tp.

Step 3: input tp=cnt%2.

Step 4: is tp==1 ? is yes then

For i=x-75 to i<=x+75

For j=y-75 to j<=y+75

Is x==i and y==j ? if yes then goto aaa.

Is i>=75 and i<=375 and j>=75 and j<=375 and getpixel(i,j)==2 ? if yes then

Putpixel(i,j,4).

aaa:

Step 5: is tp==0 ? if yes then

for i=x-75 to i<=x+75

is x==i ? if yes then goto bbb.

is i>=75 and i<=375 and getpixel (i,y)==2 ? if yes then

putpixel(i,j,4).

bbb:

for j=y-75 to j<=y+75

is y==j ? if yes then goto ccc.

is j>=75 and j<=375 and getpixel(x,j)==2 ? if yes then

putpixel(x,j,4).

ccc:

Step 6: End.

placegoat():

The function is for place the goat on the board. In this function we move the box by giving ascii value for up, down, left and down. It also display the invalid move if there if place goat in invalid place.

Algorithm for the function placegoat():

Step 1: start.

Step 2: declare variables a,x=75,y=75,chk=0.

Step 3: call the function selectbox().

Step 4: while(1)

input a=getch().

is a==27 ?if yes then

display “Thank you for playing “

display “Developed by:-

Saraju palukasi

Ksitiz Shrestha.”

exit(1).

delete selection box by making box color black.

is a==72 and y!=75 ? if yes then

input y=y-75.

is a==80 and y!=375 ? if yes then

input y=y+75.

is a==75 and x!=75 ? if yes then

input x=x-75.

is a==77 and x!=375 ? if yes then

input x=x+75.

is a==13 ? if yes then

is getpixel(x,y)==2 ? if yes then

call the fuction putgoat ().

call the function slectbox () for delete selection box.

else

display “Invalid move”

call the function selectbox ().

call the function display ().

Step 5: End.

goatmove():

The function make the goat move by selecting to them by selection box. The function call many functions like putgoat(), removered(), display() etc as its requirement.

Algorithm for the function goatmove():

Step 1:start.

Step 2: declare variables a, x=75, y=75, count=1, initx, inity.

Step 3: call the function selectbox().

Step 4: while(1)

input a=getch().

is a==27 ?if yes then

display “Thank you for playing “

display “Developed by:-

Saraju palukasi

Ksitiz Shrestha.”

exit(1).

delete selection box by making box color black.

is a==72 and y!=75 ? if yes then

input y=y-75.

is a==80 and y!=375 ? if yes then

input y=y+75.

is a==75 and x!=75 ? if yes then

input x=x-75.

is a==77 and x!=375 ? if yes then

input x=x+75.

is a==13 ? if yes then

is count==1 and getpixel(x,y)==1 ? if yes then

input initx=x.

input inity=y.

call the function gputcol().

call the function putgoat() for deleting existing goat by giving black color.

call the function display().

call the function checkred().

is tmove!=0 ? if yes then

count++.

else

call the function putgoat().

else is count==2? if yes then

is getpiel(x,y)==4 ? if yes then

call the function putgoat().

call the function removered().

call the function selectbox() for the delete box.

call the function display().

else

display “Invalid move”

call the function selectbox().

call the function display().

Step 5: End.

removered():

The function remove the red pixel from the board. It first check red pixel on the board and change it into green pixel.

Algorithm for the function removered():

Step 1: start.

Step 2: declare variables i,j.

Step 3: for i=75 to i<=375.

for j=75 to j<=375.

is getpixel(i,j)==4 or getpixel(i,j)==6 ? if yes then

putpixel(i,j,2).

Step 4: End.

tigermove():

The function make the tiger move by selecting to them by selection box. The function call many functions like puttiger(), checkred(), removered(), display() etc as its requirement.

Algorithm for the function tigermove():

Step 1:start.

Step 2: declare variables a, x=75, y=75, count=1, initx, inity.

Step 3: call the function selectbox().

Step 4: while(1)

input a=getch().

is a==27 ?if yes then

display “Thank you for playing “

display “Developed by:-

Saraju palukasi

Ksitiz Shrestha.”

exit(1).

delete selection box by making box color black.

is a==72 and y!=75 ? if yes then

input y=y-75.

is a==80 and y!=375 ? if yes then

input y=y+75.

is a==75 and x!=75 ? if yes then

input x=x-75.

is a==77 and x!=375 ? if yes then

input x=x+75.

is a==13 ? if yes then

is count==1 and getpixl(x,y)==3 ? if yes then

input intx=x.

input inty=y.

call the function putcol().

call the function puttiger() for remove the tiger from that position.

call function display().

call the function checkred().

is tmove!=0 ? if yes then

count++.

else

call the function put tiger().

else is count==2 ? if yes then

is getpixel(x,y)==6

call the function putgoat() for remove the goat.

call the function display().

ngoat++.

display “Dead goats :ngoat”

call the function putiger()

call the function removered()

call the function selectbox() for remove box from that position.

call the function display().

else

display “Invalid move”.

call the function selectbox().

call the function display().

Step 5: End.

checkred():

The function check the position of the red pixel on the board and check for tiger moves.

Algorithm for the function checkred():

Step 1: start.

Step 2: declare variables i,j.

Step 3: input tmove=0.

Step 4: for i=75 to i<=375

for j=75 to j<=375

is getpixel(i,j)==4 or getpixel(i,j)==6 ? if yes then

tmove++.

Step 5: End.

  1. SOURCE CODE

/*********Bchal.c*************/

/*******header files************/

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<time.h>

/***********function declaration************/

void display();

void box();

void puttiger(int,int,int,int);

void putgoat(int,int,int,int);

void selectbox(int,int,int);

void gppcol(int,int,int);

void ppcol(int,int,int);

void initialize();

void putcol(int,int);

void gputcol(int,int);

void checkred();

void removered();

void placegoat();

void goatmove();

void tigermove();

void genmove();

void Print();

void load();

/****************Globle varible******************/

int maincount=1,game=0,ngoat=0,tmove=0;

/*************Main function of the program.***************/

void main()

{

int gdriver=0,gmode,a;

initgraph(&gdriver,&gmode,"C:\\TC\\BGI");

Print();

cleardevice();

load();

cleardevice();

display();

box();

initialize();

genmove();

getch();

}

/********************Function to draw board******************/

void display()

{

int i,j;

setcolor(7);

for(i=75;i<=375;i+=75) // draw boxes in the board.

{

for(j=75;j<=375;j+=75)

{

rectangle(i-20,j-20,i+20,j+20);

}

}

for(i=95;i<=95*4;i+=75) // draw lines in the board.

{

for(j=75;j<=75*5;j+=75)

{

line(i,j,i+35,j);

line(j,i,j,i+35);

}

}

for(i=95,j=95;i<=95*4,j<=95*4;i+=75,j+=75)

{

line(i,j,i+35,j+35);

}

for(i=355,j=95;i>=95,j<=95*4;i-=75,j+=75)

{

line(i,j,i-35,j+35);

}

for(i=205,j=95;i>=95,j<=205;i-=75,j+=75)

{

line(i,j,i-35,j+35);

}

for(i=355,j=245;i>=245,j<=355;i-=75,j+=75)

{

line(i,j,i-35,j+35);

}

for(i=245,j=95;i<=355,j<=205;i+=75,j+=75)

{

line(i,j,i+35,j+35);

}

for(i=95,j=245;i<=205,j<=355;i+=75,j+=75)

{

line(i,j,i+35,j+35);

}

}

/*****************Function to put pixel on board.********************/

void box()

{

int i,j;

for(i=1;i<=5;i++)

{

for(j=1;j<=5;j++)

{

putpixel(i*75,j*75,2);

if(i==1&j==1)

putpixel(i*75,j*75,3);

if(i==5&j==1)

putpixel(i*75,j*75,3);

if(i==1&j==5)

putpixel(i*75,j*75,3);

if(i==5&j==5)

putpixel(i*75,j*75,3);

}

}

}

/*********************Function to draw tiger shape****************/

void puttiger(x,y,color,c)

{

setfillstyle(SOLID_FILL,color);

setcolor(color);

{

circle(x,y,15);

fillellipse(x-13,y-12,4,6);

fillellipse(x+13,y-12,4,6);

circle(x-7,y-5,3);

circle(x+7,y-5,3);

circle(x,y+6,4);

}

putpixel(x,y,c);

}

/**************Funtion to draw goat shap*******************/

void putgoat(x,y,color,c)

{

setfillstyle(SOLID_FILL,color);

setcolor(color);

{

fillellipse(x,y,10,17);

fillellipse(x-12,y-12,6,4);

fillellipse(x+12,y-12,6,4);

}

putpixel(x,y,c);

}

/*****************Function to draw slection box.****************/

void selectbox(x,y,color)

{

setcolor(color);

rectangle(x-25,y-25,x+25,y+25);

}

/***********check for the valid move for the goat***************/

void gppcol(x,y,cnt)

{

int i,j,tp;

tp=cnt%2;

if(tp==1)

{

for(i=x-75;i<=x+75;i+=75)

{

for(j=y-75;j<=y+75;j+=75)

{

if(x==i&y==j) goto aaa;

if(i>=75&i<=75*5&j>=75&j<=75*5&getpixel(i,j)==2)

{

putpixel(i,j,4);

}

aaa:

}

}

}

if(tp==0)

{

for(i=x-75;i<=x+75;i+=75)

{

if(x==i) goto bbb;

if(i>=75&i<=75*5&getpixel(i,y)==2)

{

putpixel(i,y,4);

}

bbb:

}

for(j=y-75;j<=y+75;j+=75)

{

if(y==j) goto ccc;

if(j>=75&j<=75*5&getpixel(x,j)==2)

{

putpixel(x,j,4);

}

ccc:

}

}

}

/***********check for the valid move for the tiger***************/

void ppcol(x,y,cnt)

{

int i,j,tp;

tp=cnt%2;

if(tp==1)

{

for(i=x-75;i<=x+75;i+=75)

{

for(j=y-75;j<=y+75;j+=75)

{

if(x==i&y==j) goto ppp;

if(i>=75&i<=75*5&j>=75&j<=75*5&getpixel(i,j)==2)

{

putpixel(i,j,4);

}

ppp:

}

}

for(i=x-2*75;i<=x+2*75;i+=75*2)

{

for(j=y-2*75;j<=y+2*75;j+=75*2)

{

if(x==i&y==j) goto qqq;

if(i>=75&i<=75*5&j>=75&j<=75*5&getpixel(i,j)==2&getpixel((x+i)/2,(y+j)/2)==1)

{

putpixel(i,j,6);

}

qqq:

}

}

}

if(tp==0)

{

for(i=x-2*75;i<=x+2*75;i+=2*75)

{

if(x==i) goto rrr;

if(i>=75&i<=75*5&getpixel(i,y)==2&getpixel((x+i)/2,y)==1)

{

putpixel(i,y,6);

}

rrr:

}

for(j=y-2*75;j<=y+2*75;j+=2*75)

{

if(y==j) goto sss;

if(j>=75&j<=75*5&getpixel(x,j)==2&getpixel(x,(j+y)/2)==1)

{

putpixel(x,j,6);

}

sss:

}

for(i=x-75;i<=x+75;i+=75)

{

if(x==i) goto ttt;

if(i>=75&i<=75*5&getpixel(i,y)==2)

{

putpixel(i,y,4);

}

ttt:

}

for(j=y-75;j<=y+75;j+=75)

{

if(y==j) goto uuu;

if(j>=75&j<=75*5&getpixel(x,j)==2)

{

putpixel(x,j,4);

}

uuu:

}

}

}

/******Function to put tigers in there potion in initial phase*********/

void initialize()

{

int i,j;

for(i=1*75;i<=5*75;i+=75)

{

for(j=1*75;j<=5*75;j+=75)

{

if(getpixel(i,j)==3) puttiger(i,j,6,3);

}

}

}

/**********check the position of the tiger*********/

void putcol(x,y)

{

int i,j,cnt=0;

for(i=75;i<=5*75;i+=75)

{

for(j=75;j<=5*75;j+=75)

{

cnt++;

if(x==i&y==j)

ppcol(x,y,cnt);

}

}

}

/*********check the position of the goat**********/

void gputcol(x,y)

{

int i,j,cnt=0;

for(i=75;i<=5*75;i+=75)

{

for(j=75;j<=5*75;j+=75)

{

cnt++;

if(x==i&y==j)

gppcol(x,y,cnt);

}

}

}

/************Fuction to check red pixel in the board**************/

void checkred()

{

int i,j;

tmove=0;

for(i=1*75;i<=5*75;i+=75)

{

for(j=1*75;j<=5*75;j+=75)

{

if(getpixel(i,j)==4||getpixel(i,j)==6) tmove++;

}

}

}

/***************Function to remove red pixel in the board*************/

void removered()

{

int i,j;

for(i=1*75;i<=5*75;i+=75)

{

for(j=1*75;j<=5*75;j+=75)

{

if(getpixel(i,j)==4||getpixel(i,j)==6) putpixel(i,j,2);

}

}

}

/***************Function to place goats***************/

void placegoat()

{

int a,x=75,y=75,chk=0;

selectbox(x,y,3);

while(1)

{

a=getch();

if(a==27)

{

cleardevice();

gotoxy(26,5);

printf("Thank you for playing\n");

gotoxy(2,23);

printf("Developed by:-\nSaraju Paluksai\nKsitiz Shrestha.");

getch();

exit(1); }

selectbox(x,y,0);

if(a==72&y!=75)

y-=75;

if(a==80&y!=75*5)

y+=75;

if(a==75&x!=75)

x-=75;

if(a==77&x!=75*5)

x+=75;

if(a==13)

{

if(getpixel(x,y)==2)

{