You are on page 1of 47

ADVENTUROUS ROAD RACING

A report submitted in partial fulfillment of requirements of the Mini Project of Bachelor of Technology In Computer Science and Engineering SAI VIKAS GUNTI (11003185) MANOJ KUMAR ANNBATTHINA (11003034) SAI VINOD MANNAM (11003179) SAI DINESH BOORSU (11003179)

Under the Guidance of DR.RAJESHWARA RAO

Department of Computer Science and Engineering KL University, Vaddeswaram, Guntur Dt. 2012-13

KL University Department of CSE

Certificate
This is to certify that the project work entitled ADVENTUROUS ROAD RACING being submitted to department of Computer Science and Engineering, KL University by SAI VIKAS GUNTI (11003185) in partial fulfillment for the Mini Project, is a bonafide work carried out by them under my supervision.

GUIDE DR. RAJESHWARA RAO

HOD, CSE (Dr.V.Srikanth)

Acknowledgement
I have taken efforts in this project. However, it would not have been possible without the kind, support and help of Dr. V. Srikanth, Professor & Head of the Department and Second year coordinator Mr. K.V.D.Kiran, Assistant Professor. I would like to extend my sincere thanks to all of them. I am highly indebted to DR. RAJESHWARA RAO, Professor for his guidance and constant supervision as well as for providing necessary information regarding the project & also for his support in completing the project. I would like to express my special gratitude and thanks to all the faculty and staff for giving me such attention and time. I would like to express my gratitude towards my parents for their kind co-operation and encouragement which help me in completion of this project. My thanks and appreciations also go to my friends in developing the project and people who have willingly helped me out with their abilities.

SAI VIKAS GUNTI (11003185) MANOJ KUMAR ANNABATTHINA (11003034) SAI VINOD MANNAM (11003104) SAI DINESH BOORSU (11003179)

Abstract

Our mini project tittle is ADVENTUROUS ROAD RACING USING C++ we students of II/IV computer science engineering has done a C++ program for car game. We have done this using the feature in c++ called class. We have used graphic features of c++. We have created different functions for different menus in the game. The main aim of this game is to ride a car using cursor keys. We can attain this by moving car away from the rectangular obstacles that we have encountered on the road. We have done this using dos box compiler. We had tried to reduce maximum problems in our program. Even though it may contains several technical and logical problems. We have done this for mini project as part our curriculum for the academic year 2012-2013......

Table of Content
Page No. 1. Introduction 2. Problem Statement 3. Problem Solution 4. Software and Hardware Specifications 5. Algorithm 6. Inputs 7. Source Code 8. Output Screen Shots 9. Conclusion 10. References 1-2 3 4 5 6-13 14 15- 34 35-40 41 42

1. INTRODUCTION
Our mini project title is adventurous car game using c++ For this we have used c++ programming We have used a special future in c++ called class. We have used many other graphic functions for this game design .. The main aim of this game is to ride a car using cursor keys .By moving away from the rectangular obstacles that we have encountered on the road will be rectangle obstacles on road we have to drive through that road by moving away from these obstacles .. These obstacles are created by using some graphic futures. The following are futures used for program coding : I) Class. II) Constructers III) Graphic functions.

I) Definition for class: Class: A class is a type definition of an Object Oriented Programming object in the C++ and C# languages. II) Definition for constructor:

III) Definition for graphic functions:


The graphic functions are mostly predefined functions in compiler which are used to create graphic objects on the screen. By using these features of c++ we have written code for the car the game by writing several functions we have achieved the task. The following are the features of our game : I) Easily accessible menu. II) Three chance every time. III) Fast moving attractive car. IV) Road full of obstacles. V) Attractive environment. VI) Saving scores. We have done this using dos box compiler. We had tried to reduce maximum problems in our program. Even though it may contains several technical and logical problems. We have done this for mini project as part our curriculum for the academic year 2012-2013......

2. PROBLEM STATEMENT

Comparison with real world: Many of us in this world have desire to ride a car with speed, and want to ride it in the adventurously, want to ride it in a road full of obstacles. This is one of the problems which leaded us to design this game. In reference to kids: Manly kids want to play car racing game which gives them lots of fun. They want to play the games which are having good graphical features. Different Colors gives them joy .so they wants to play mostly car games which are having color full environment .This is one of the problem which leads us to design the game like this. In reference to adults: Many of the employees and other business people have many problems and they came home with tiredness. In order to get relieved from that tiredness they want to play games. For such people we have designed this game. These are the main three problems which we have thought about for the design of the game.

3. PROBLEM SOLVING
We have discussed problems which we have thought for several days. Then we the team members discussed among us about these problems which several people are suffering in this world. Then our team members come up with a good idea to create a car game which consists of obstacles, good environment, and with color full car and road side environment.

Then we have decided to design a game with graphic features using c++ language. We have designed a game in which there are the features which are required for the different types of people which we have discussed before in the problem statement.

The game we have designed gives fun to kids, thrill to adults and refreshing to working people.

Thus we have named our game as Adventurous Road racing".

Then finally our car games which we have designed become the tool to solve those problems.

4.SOFTWARE AND HARDWARE REQUIREMENT


Software:
Dosbox0.74

Hardware:
*processor: Intel core i3-2310M (2.1 GHz, 3MB). *Operating system: Windows7 professional 64-bit/windows xp /windows vista/windows 98. * Ram: 4GB DDR3 1333 MHZ/2GB/any other lower (or) higher capacity rams. *Hard disk: 500GB 7200rpm/250 GB/ any other higher (or) lower capacity disk.

10

5. ALGORITHM
Step1:First create a class with named car; In this class define functions for score , and after that define a overload another function in that define level scores . In class car define variables for velocity, initiation of scores players names. Step2: create functions in which directions the car have to move . They are : void right() void right() void right() { if(car.cp<420) { car.cp+=10; } return; } void left() { if(car.cp>180) { car.cp-=10; } return; }

11

Step3: Initialize functions for store scores and display the score . Void score store () Here in this functions we have created a file and store players names in it. Use open& write functions. Void disp_score () Use if stream function to display the score. Step4: create function for display of car and to move it. Void bgmove () Here in this function we have graphic related functions like setcolor, Setfillstyle, bar, sector. In this function create obstacles using bar function in graphics mode. setcolor (RED); setfillstyle(SOLID_FILL,RED); sector(car.cp+20,330,0,180,20,30); setfillstyle(SOLID_FILL,YELLOW); bar3d(car.cp,333,car.cp+37,360,4,4); sector(car.cp+20,362,180,360,20,10); for(int i=car.init;i<70;i+=5) { setcolor(GREEN); setfillstyle(9,GREEN); bar(16*8,i*8,20*8,(i+2)*8); bar(60*8,i*8,64*8,(i+2)*8); }
12

Step5:Intialize functions for creation of logo, and create functions for loss and win of game and score of game. Void logo() In this function use graphic mode functions setcolor, Settextstyle, outtextxy, bar3d, setfillstyle Void loss () If we hit the obstacle then we will lose one chance Void over() If loss three chances then this function will be executed. Void win() If we win two levels then this function will be executed. void logo () { for(int i=1;i<250;i++) { setcolor(YELLOW);setfillstyle(SOLID_FILL,YELLOW); settextstyle(4,HORIZ_DIR,5); outtextxy(100,100,"adventerous ROAD"); outtextxy(200,140,"RACING"); bar3d(50,200,550,220,10,40); setcolor(GREEN); settextstyle(1,HORIZ_DIR,2); outtextxy(100,400,"LOADING");setfillstyle(SOLID_FILL,GREEN); bar(190,400,190+i,420); delay(25);
13

} delay(2000); cleardevice(); return; void loss(void) { setcolor(10); settextstyle(2,0,9); outtextxy(180,150,"ONE CHANCE LOST"); delay(1000); return; } void win() { cleardevice(); for(int k=0;k<2;k++) { for(int i=0;i<15;i++) { setcolor(i); settextstyle(4,0,5); outtextxy(200,100,"Congrats!!"); setcolor(i+1); outtextxy(150,200,"You won the race");

14

delay(150); } } delay(3000); score_store(); return; } Step6:create function for play in this step Here in this function we have assign keys to run the car In this function we have used a keyword called as kbhit() if(kbhit()) { m=getch(); switch(m) { case LEFT: left(); break; case RIGHT: right(); break; case 'q':exit(0); } } else{ delay(100); }

15

} getch(); return(0); } Step7: create function for menu of game Void main() Here in this function use graphic mode functions for display of menu . These functions are setcolor, outtextxy, settextstyle Next by using switch case define up and down movement of cursor. switch(a) { case UP:if(p>140) { p-=30; s--; } break; case DOWN:if(p<260) { p+=30; s++; } break; case ENTER:a=1;
16

break; default:break; } } while(a!=1); switch(s) { case 1:play(); break; case 2:disp_score(); break; case 3:help(); break; case 4:about(); break; case 5:exit(0); default:cprintf("Invalid choice"); break; } } while(t==0); getch(); }

17

Step 8: Write main() function with graphics initiations and close it .

void main() { int gdriver=DETECT,gmode,errorcode; initgraph(&gdriver,&gmode,"");cleardevice(); logo(); menu(); closegraph(); }

18

6. INPUTS

Class input: Create a class using a name called car, define all variables required for the coding and function members inside the class. Constructer input: Create a constructer and write the code . Graphical input: The predefined graphical functions are used in this coding they are: Setcolor. Settextstyle. Outtextxy. Ifstream. Setfillstyle. Sector. Setfillstyle. Bar3d. Kbhit.

19

7. SOURCE CODE
#include<conio.h> #include<process.h> #include<stdio.h> #include<dos.h> #include<stdlib.h> #include<fstream.h> #include<graphics.h> #define LEFT 75 #define RIGHT 77 #define UP 72 #define DOWN 80 #define ENTER 13 class CAR { public: int vel,cp,init,op1,op2,op3,level; long score; long lev_score[5]; char player[20]; CAR::CAR() { level=1; vel=1;
20

cp=300; init=0; op1=0; op2=-20; op3=-40; score=0; lev_score[0]=10000;lev_score[1]=30000;lev_score[2]=60000;lev_score[3]=100 000;lev_score[4]=150000; } }car; int randx(void) { int x=random(56*8); if(x<22*8) { x=x+(22*8); } return(x); } void right() { if(car.cp<420) { car.cp+=10; }
21

return; } void left() { if(car.cp>180) { car.cp-=10; } return; } void score_store() { cleardevice(); setcolor(4); settextstyle(2,0,6); outtextxy(10,0,"Your score is"); gotoxy(20,2);cout<<car.score; outtextxy(10,40,"Enter your name to store :");gotoxy(35,4); gets(car.player); ofstream score; score.open("score.dat",ios::app);score<<"\n"; score.write(car.player,20);score<<car.score; score.close(); }

22

void disp_score() { cleardevice(); setcolor(5); settextstyle(2,0,9); outtextxy(200,20,"SCORE BOARD"); ifstream score("score.dat"); char ch; int i=0;gotoxy(1,5); while(score.get(ch)) { score.seekg(i,ios::beg); score.get(ch); cout<<ch; i++; } getch(); return; } void bgmove() { if(car.init>5) { car.init=1; }

23

else { car.init+=car.vel; } setcolor(RED); setfillstyle(SOLID_FILL,RED); sector(car.cp+20,330,0,180,20,30); setfillstyle(SOLID_FILL,YELLOW); bar3d(car.cp,333,car.cp+37,360,4,4); sector(car.cp+20,362,180,360,20,10); for(int i=car.init;i<70;i+=5) { setcolor(GREEN); setfillstyle(9,GREEN); bar(16*8,i*8,20*8,(i+2)*8); bar(60*8,i*8,64*8,(i+2)*8); } return; } void opp1(int x1) { if(car.op1<600) { car.op1+=10;

24

setfillstyle(1,RED); bar3d(x1,car.op1,x1+30,car.op1+30,2,3); } else { car.op1=0; } return; } void opp2(int x2) { if(car.op2<600) { car.op2+=10; setfillstyle(1,YELLOW); bar3d(x2,car.op2,x2+30,car.op2+30,2,3); } else { car.op2=0; } return; } void opp3(int x3)

25

{ if(car.op3<600) { car.op3+=10; setfillstyle(1,BLUE); bar3d(x3,car.op3,x3+30,car.op3+30,2,3); } else { car.op3=0; } return; } int check(int x,int op,int cp) { int a[31],b[31],c[40],d[50]; for(int i=0;i<30;i++) { a[i]=x+i; } for(i=0;i<30;i++) { b[i]=op+i; }

26

for(i=0;i<40;i++) { c[i]=cp+i; } for(i=0;i<50;i++) { d[i]=300+i; } for(i=0;i<40;i++) { for(int j=0;j<50;j++) { for(int k=0;k<30;k++) { if(a[k]==c[i]&&b[k]==d[j]) return 1; } } } return 0; } void logo () { for(int i=1;i<250;i++)

27

{ setcolor(YELLOW);setfillstyle(SOLID_FILL,YELLOW); settextstyle(4,HORIZ_DIR,5); outtextxy(100,100,"adventerous ROAD"); outtextxy(200,140,"RACING"); bar3d(50,200,550,220,10,40); setcolor(GREEN); settextstyle(1,HORIZ_DIR,2); outtextxy(100,400,"LOADING");setfillstyle(SOLID_FILL,GREEN); bar(190,400,190+i,420); delay(25); } delay(2000); cleardevice(); return; } void loss(void) { setcolor(10); settextstyle(2,0,9); outtextxy(180,150,"ONE CHANCE LOST"); delay(1000); return; }

28

void over(void) { for(int i=1;i<35;i++) { cleardevice();delay(20); settextstyle(1,0,6);setcolor(RED); outtextxy(150,100,"GAME OVER"); delay(20); } delay(2000);cleardevice(); score_store(); getch(); return; } void score() { car.score=car.score+11*car.vel; setcolor(5); settextstyle(2,0,6); outtextxy(530,12,"Score "); gotoxy(75,2); cout<<car.score; return; }

29

void win() { cleardevice(); for(int k=0;k<2;k++){ for(int i=0;i<15;i++) { setcolor(i); settextstyle(4,0,5); outtextxy(200,100,"Congrats!!"); setcolor(i+1); outtextxy(150,200,"You won the race"); delay(150); } } delay(3000); score_store(); return; } void level(void) { int level=car.level; if(car.score>car.lev_score[level-1]) { if(car.level<5)

30

{ car.level++; if(car.vel<4) { car.vel++;} cleardevice(); settextstyle(2,0,3); setcolor(4); outtextxy(4,12,"Level"); gotoxy(5,1); cout<<car.level; } else {win();}} settextstyle(2,0,6); setcolor(5); outtextxy(4,12,"Level"); gotoxy(8,2); cout<<car.level; return; } void about() { char opt;

31

while(!kbhit()) { for(int i=300;i<600;i++) { cleardevice(); setcolor(9); settextstyle(4,0,5); setfillstyle(9,12); outtextxy(220,0,"ABOUT"); bar(220,60,370,62); settextstyle(2,0,5); setcolor(2); outtextxy(20,100,"We had completed our work as a part of our computer science miniproject work."); outtextxy(3,115,"We had tried to reduce maximum problems in our program. Eventhough it may "); outtextxy(3,130,"consist several technical and logical problems."); outtextxy(3,165,"WE ARE........."); outtextxy(3,180,"Wait a moment to enter menu...."); setcolor(6); settextstyle(2,0,6); outtextxy(600-i,600-i,"sai vikas gunti"); outtextxy(i-150,215,"manoj kumar annabathinna"); outtextxy(i-30,i-130,"vinod sai mannam"); outtextxy(600-i,i-150,"sai dinesh boorsu");
32

outtextxy(350,600-i,"kluniversity"); setfillstyle(1,4); bar3d(180,380,450,460,4,6); setcolor(1); settextstyle(2,0,10); outtextxy(280,380,"Section F"); outtextxy(215,420,"20012-2013"); delay(60); } } getch(); return; } int play(void) { int life=3,m,x1,x2,x3,s; re: while(life) { cleardevice(); if(car.op1==0) { x1=randx(); car.op1++;

33

} else { opp1(x1); } if(car.op2==0) { x2=randx(); car.op2++; } else if(car.op2<1) {car.op2++;} else { opp2(x2); } if(car.op3==0) { x3=randx(); car.op3++; } else if(car.op3<1) {car.op3++;} else

34

{ opp3(x3); } setcolor(10); setfillstyle(0,0); bar3d(0,0,80,70,4,3); bgmove(); level(); score(); settextstyle(2,0,6); setcolor(5); outtextxy(4,44,"Life"); gotoxy(8,4);cout<<life; if(check(x2,car.op2,car.cp)||check(x1,car.op1,car.cp)||check(x3,car.op3,car.cp)) { loss(); life--; if(life==0) { over(); } car.op1=1; car.op2=-16; car.op3=-32;

35

goto re; } if(kbhit()) { m=getch(); switch(m) { case LEFT: left(); break; case RIGHT: right(); break; case 'q':exit(0); } } else{ delay(100); } } getch(); return(0); } void help() { cleardevice(); settextstyle(4,0,6);setcolor(13);

36

outtextxy(200,10,"HELP");textcolor(YELLOW);gotoxy(3,6); cout<<"\n\n\n\n\n\n\nDPR (adventerous Road Racing is a simple game in which you have to lead a car by avoiding blocks on road.\nYou have to use the following keys to controll the car\n\n->UP\t--\tForward movement\n->LEFT\t-\tLeftside movement\n->RIGHT\t--\tRightside movement\n->q\t--\tExit from game at any time\n"; getch(); return; } void menu() { int s=1,t=0,a,p=140; do { do { cleardevice(); setcolor(YELLOW); settextstyle(1,0,4); outtextxy(230,30,"MENU"); setfillstyle(1,2); bar(140,80,400,82); settextstyle(1,0,1); setcolor(10); outtextxy(220,137,"PLAY GAME"); outtextxy(220,167,"SCORES");
37

outtextxy(220,197,"HELP"); outtextxy(220,227,"ABOUT"); outtextxy(220,257,"EXIT"); setcolor(RED); rectangle(200,p,350,p+20); a=getch(); switch(a) { case UP:if(p>140) {p-=30; s--;} break; case DOWN:if(p<260) {p+=30; s++;}; break; case ENTER:a=1; break; default:break; } }while(a!=1); switch(s) { case 1:play();

38

break; case 2:disp_score(); break; case 3:help(); break; case 4:about(); break; case 5:exit(0); default:cprintf("Invalid choice"); break; } }while(t==0); getch(); } void main() { int gdriver=DETECT,gmode,errorcode; initgraph(&gdriver,&gmode,"");cleardevice(); logo(); menu(); closegraph(); }

39

8. OUTPUT SCREENS 1)

This output screen shows the opening screen of the game.

40

2)

This output screen shows the menu of the game and we have to Select the appropriate menu which we required

41

3)

This output screen shows the scoreboard of the players who played game .

42

4)

This output screen shows the help menu of the game which will be more help full for new users.

43

5)

This output screen shows the about menu in the game which says about game developers.

44

6)

This output screen shows the main screen of the game while car is running.

45

10.CONCLUSION

Thus we the students of II/IV computer science department have designed a car game as our mini project. This Adventurous road racing game is game designed by team work our team members, the credits must belongs to all the members in our team. It is a very easy game with only one car with colorful environment around the car ,and hope this will liked by many. We had tried to reduce maximum problems in our program. Even though it may contains several technical and logical problems. We have done this for mini project as part our curriculum for the academic year 2012-2013...... Finally we hope that there will some enjoyment for those who play our game . We are very much thankful to our guide Dr.Rajeshwara Rao sir for his guidance and prior encouragement . We sincerely thankful to Mrs.Diyva mam(asso.professer)department of computer science kl university for her guidance in making of reports and for outcome this final document of our mini project.

46

10.REFERENCES
THE COMPLETE REFRENCE TO C++ BY HERBERT SCHILDT. C++ HOW TO PROGRAM BY DEITEL&DEITEL. http://www.freecodesource.com. http://www.sourcecodesworld.com/source http://cplus.about.com

47