I am new to Dev C++ and i am creating a program of a game of snake.
In Dev C++ the graphics open in WINDOWS BGI screen whereas the text gets shown in Text console(Dos).
1)i want to know how can i clear the WINDOWS BGI screen ?
2)how can i Close WINDOWS BGI screen so as to return to the text console?
#include<iostream>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int snake(int);
int main()
{
cout<<"WELCOME TO SNAKE WORLD\n PRESENTED BY PRABHJIT,RUHI AND SAURAV OF CS-11";
cout<<" RULES FOR THE GAME";
cout<<"KEYS---\n w- FORWARD\n a- LEFT TURN\n d- RIGHT TURN\n s- DOWN";
cout<<" PRESS MOVE(a) KEY TO CONTINUE.....";
cout<<"ENTER YOUR LEVEL\n";
cout<<"\n1.ROOKIE";
cout<<"\n2.CATCHING UP";
cout<<"\n3.MEDIUM";
cout<<"\n4.MASTER";
cout<<"\n5.THE KING\n";
int choice,prabh;
cin>>choice;
switch(choice)
{
case 1:prabh=100;
break;
case 2:prabh=70;
break;
case 3:prabh=50;
break;
case 4:prabh=30;
break;
case 5:prabh=10;
break;
default:cout<<"Wrong option entered...Exiting";
break;
}
snake(prabh);
return 0;
}
int snake(int z)
{int prabh;
prabh=z;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c://tc//");
cleardevice();
char ans;
rand();
int x=10,y=10,n=1,i;
int a=0,b=0,x1,y1;
loop:
x1=rand()%620;
y1=rand()%450;
setbkcolor ( WHITE );
again:
while(!kbhit())
{
cleardevice();
settextstyle(10 , 0 , 2);
outtextxy(x1,y1,"~");
for(i=1;i<=n;i++)
{
if(!kbhit())
{
x+=a;y+=b;
if((x-x1)*(x1-x)>=-25 && (y-y1)*(y1-y)>=-25)
{n++;goto loop;}
setcolor ( RED );
outtextxy(x,y,"");
delay(prabh);
}
else
{goto loop1;}
}
}
loop1:
ans=getch();
if(ans=='w'||ans=='W' && b<=1 && b!=5)
{a=0;b=-5;}
if(ans=='s'||ans=='S' && b<=460 && b!=-5)
{a=0;b=5;}
if(ans=='a'||ans=='A' && a<=1 && a!=5)
{a=-5;b=0;}
if(ans=='d'||ans=='D' && a<=630 && a!=-5)
{a=5;b=0;}
if(ans=='q'||ans=='Q')
{cout<<"GAME ABORTED";}
if((x<0)|(y<0)|(x>640)|(y>480))
{cout<<"GAME ABORTED"; /* over here i want to write the code that can close the Windows BGI screen and return me to text console*/
}
goto again;
return 0;
}