Written some cool source code? Upload it to Programmer's Heaven.

View \A GREAT GAME.CPP

1 great game - written in C

Submitted By: shahkar786
Rating: starstarstarhalf star (Rate It)


#include <conio.h>
 #include<graphics.h>
 #include <stdio.h>
 #include<process.h>
 #include<dos.h>
static int mx,my,click;
union REGS regs,regs1;
void intro();
void getmouse();
void mousepos();
void points();
void main(void)
{
        int a=DETECT,b,c,x,y,x1,y1,s=50,x2=200,y2=300,p=0,p1=0;
        initgraph(&a,&b,"");
        x=x1=getmaxx()/2;
        y=y1=getmaxy()/2;
        settextstyle(3,0,6);
        outtextxy(330,40,"RULES");
        settextstyle(3,1,2);
        outtextxy(10,100,"PLAYER 2      PLAYER 1");
        settextstyle(1,0,1);
        outtextxy(40,120,"Keyboard player should touch the big circle of mouse");
        settextstyle(1,0,1);
        outtextxy(40,140,"and should escape from the small cirle of the mouse ");
        settextstyle(1,0,1);
        outtextxy(40,160,"player using arrows ");
        settextstyle(1,0,1);
        outtextxy(40,280,"Mouse player should touch the keyboard circle with the ");
        settextstyle(1,0,1);
        outtextxy(40,300,"small circle above the screen using left click, right click");
        settextstyle(1,0,1);
        outtextxy(40,320,"and both clicks to bring the circle down saving the big circle ");
        getch();
        cleardevice();
        settextstyle(2,0,6);
        outtextxy(200,100,"target score 200");
        getch();
        for(;;)
        {
                 getmouse();
                 mousepos();
                 circle(x2,y2,20);
                 while(kbhit())
                     c=getch();
                 cleardevice();
                 setcolor(2);
                 circle(x,y,40);
                 setlinestyle(1,2,3);
                 setcolor(2);
                 line(x1,y1,x,y);
                 setcolor(14);
                 gotoxy(3,30);
                 printf("points of keyboard player  are %d  points of mouse player 1 are %d",p,p1);
                 setlinestyle(5,6,70);
                 rectangle(20,20,getmaxx()-20,getmaxy()-20);
                 circle(mx,my,65);
                 if(p1>=200)
                 {
                        clearviewport();
                        settextstyle(1,0,5);
                        outtextxy(100,200,"mouse player wins");
                        delay(2000);
                        getch();
                        exit(2);
                 }
                        if(p>=200)
                        {
                                  cleardevice();
                                  settextstyle(1,0,5);
                                  outtextxy(100,200,"keyboard player wins");
                                  delay(2000);
                                  getch();
                                  exit(2);
                        }
                        if(mx<x+105&&mx>x-105&&my<y+105&&my>y-105)
                        {
                                p+=10;
                                delay(500);
                                points();
                        }
                        if(x2<x+45&&x2>x-45&&y2<y+45&&y2>y-45)
                        {
                                p1+=10;
                                delay(500);
                                points();
                        }
                        if(c==77) //>
                        {
                                if(x<getmaxx()-90)
                                x+=s;
                        }
                        if(c==72) //^
                        {
                                if(y>90)
                                y-=s;
                         }
                         if(c==75) //<
                         {
                                if(x>80)
                                 x-=s;
                         }
                         if(c==80) //v
                         {
                                if(y<getmaxy()-90)
                                y+=s;
                         }
                         if(c==77&&c==80) // >  v
                         {
                         if(x<getmaxy()-40)
                         x+=s;
                         if(y<getmaxy()-40)
                         y+=s;
                         }
                         if(c==72&&c==75) //^   <
                         {
                         if(y>40)
                         y-=s;
                         if(x>40)
                         x-=s;
                         }
                         if(c==75&&c==80) //<   v
                         {
                         if(x>40)
                         x-=s;
                         if(y<getmaxy()-40)
                         y+=s;
                         }
                         if(c==80&&c==75) //v   <
                         {
                         if(y<getmaxy()-40)
                         y+=s;
                         if(x>20)
                         x-=s;
                         }
                         if(click==2) //>       right
                         {
                         if(x2<getmaxx()-40)
                         x2+=s;
                         }
                         if(click==0) //^      no click
                         {
                         if(y2>40)
                         y2-=s;
                         }
                         if(click==1) //<       left
                         {
                         if(x2>40)
                         x2-=s;
                         }
                         if(click==3) //v       both
                         {
                         if(y2<getmaxy()-40)
                         y2+=s;
                         }
         }
}
void getmouse()
{
        int86(51,&regs,&regs1);
        regs.x.ax=1;
}
void mousepos()
{
        regs.x.ax=3;
        int86(51,&regs,&regs1);
        click=regs1.x.bx;
        mx=regs1.x.cx;
        my=regs1.x.dx;

}
void points()
{
          settextstyle(3,0,12);
          outtextxy(100,200,"+ 10");
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.