Hi.
I'm creating a game, and I want when the user pressed on the Quit button,
a window will appear asking the user if he is sure he wishes to quit the game (Are You Sure? Yes/No buttons).
I don't really know how to approach creating this window..
Note that I wrote Yes/No
buttons using the mouse, not with the keyboard..
I'm not asking that someone will write me the entire code,
but advices or some guidance would be much appreciated.
Thanks.
Heres the page where I want to write this code:
(I'll do this window opening on both Quit buttons on the two different functions.. is it a problem that I want to do it in the same page?)
CODE
#include <graphics.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "d:\1vs100\button.h"
#include "d:\1vs100\mouse.h"
#include "d:\1vs100\screens.h"
#include "d:\1vs100\high.h"
#include "d:\1vs100\game.h"
#include "d:\1vs100\ins.h"
void start()
{
int c,d,i,status,places=2;
int color,k,x1_coords=237,x2_coords=231,x3_coords=237;
char a1[8]="",a2[9]="",a3[9]="",name[8],id[9],school[9];
button *array;
array=(button*)malloc(places*sizeof(button)); // array of button
if (array==NULL) // if memory=not enough room > NULL
{
printf("Not enough memory to allocate buffer!\n");
getch();
exit(0);
}
array[0]=InitButton(245,115,340,145,0,13,"Menu");
array[1]=InitButton(245,155,340,185,0,13,"Quit");
setfillstyle(8,9); // s,c
bar(15,480,0,0); // left frame
bar(0,15,640,0); // up frame
bar(623,480,640,0); // right frame
bar(0,480,640,465); // down frame
setcolor(9); // light blue
settextstyle(4,0,4); // f,d,s
outtextxy(187,50,"1 Against 100");
setcolor(13); // purple
line(248,275,339,275); // seperate line
rectangle(247,205,339,340); // box
delay(1800);
circle(293,219,10); // stick head
delay(450);
line(293,229,293,252); // stick body
delay(450);
line(314,230,294,240); // stick right arm
line(271,230,292,240); // stick left arm
delay(450);
line(293,253,300,272); // stick right leg
line(293,253,286,272); // stick left leg
delay(590);
line(260,290,260,324); // (1) digget one
circle(284,310,13); // (0) first digget zero
circle(317,310,13); // (0) second digget zero
delay(500);
randomize();
settextstyle(7,0,3); // f,d,s
strcpy(name,"Oren Paz");
strcpy(id,"201447281");
strcpy(school,"Ort Holon");
for(k=0;k<4;k++)
{
color = ( color + rand() ) %15 +1;
setcolor(color);
a1[k]+=name[k];
outtextxy(x1_coords,350,name);
x1_coords+=1.5;
delay(74);
setcolor(15);
outtextxy(x1_coords,350,name);
}
for(k=0;k<4;k++)
{
color = ( color + rand() ) %15 +1;
setcolor(color);
a2[k]+=id[k];
outtextxy(x2_coords,380,id);
x2_coords+=1.5;
delay(74);
setcolor(15);
outtextxy(x2_coords,380,id);
}
for(k=0;k<4;k++)
{
color = ( color + rand() ) %15 +1;
setcolor(color);
a3[k]+=school[k];
outtextxy(x3_coords,410,school);
x3_coords+=1.5;
delay(74);
setcolor(15);
outtextxy(x3_coords,410,school);
}
for(i=0;i<places;i++) DrawButton(array[i]);
mouse_cursor_on();
while(1)
{
for (i=0;i<places;i++)
{
read_mouse(&c,&d,&status); // coords&click type
if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
{
sound(250);
delay(50);
nosound();
if (BPos(array[i])==0) // if not pressed
{
array[i].pos=1;
DrawButton(array[i]);
delay(200); // illusion of button being pressed
array[i].pos=0;
DrawButton(array[i]);
if (i==0) // Start
{
mouse_cursor_off();
clearviewport();
free(array);
menu();
}
if (i==1) // Exit
{
closegraph();
free(array);
sound(250);
delay(4);
nosound();
exit(1);
}
} // end if
if (BPos(array[i])==1)
{
array[i].pos=0;
DrawButton(array[i]);
if (i==2)
{
closegraph();
free(array);
sound(250);
delay(4);
nosound();
exit(1);
} // end if
break;
} // end if
} // end if
} // end for
} // end while
} // end start
void menu()
{
int c,d,i,status,places=5;
button *array;
char name[16]="\0";
array=(button*)malloc(places*sizeof(button)); // array of button
if (array==NULL) // if memory=not enough room > NULL
{
printf("Not enough memory to allocate buffer!\n");
getch();
exit(0);
}
array[0]=InitButton(245,110,340,145,0,13,"Start");
array[1]=InitButton(245,180,340,215,0,13,"Load Game");
array[2]=InitButton(245,250,340,285,0,13,"Instructions");
array[3]=InitButton(245,320,340,355,0,13,"High Scores");
array[4]=InitButton(245,390,340,425,0,13,"Quit");
setfillstyle(8,9); // s,c
bar(15,480,0,0); // left frame
bar(0,15,640,0); // up frame
bar(623,480,640,0); // right frame
bar(0,480,640,465); // down frame
setcolor(9); // light blue
settextstyle(4,0,4); // f,d,s
outtextxy(187,50,"1 Against 100");
for(i=0;i<places;i++) DrawButton(array[i]);
mouse_cursor_on();
while(1)
{
for (i=0;i<places;i++)
{
read_mouse(&c,&d,&status);
if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
{
sound(250);
delay(50);
nosound();
if (BPos(array[i])==0) // if not pressed
{
array[i].pos=1;
DrawButton(array[i]);
delay(200); // illusion of button being pressed
array[i].pos=0;
DrawButton(array[i]);
if (i==0) // Start
{
mouse_cursor_off();
clearviewport();
free(array);
game1(1,name);
}
if (i==1) // Load Game
{
mouse_cursor_off();
clearviewport();
free(array);
ins();
}
if (i==2) // Instructions
{
mouse_cursor_off();
clearviewport();
free(array);
ins();
}
if (i==3) // High Score
{
mouse_cursor_off();
clearviewport();
free(array);
high();
}
if (i==4) // Exit
{
closegraph();
free(array);
sound(250);
delay(4);
nosound();
exit(1);
}
} // end if
if (BPos(array[i])==1)
{
array[i].pos=0;
DrawButton(array[i]);
if (i==2)
{
closegraph();
free(array);
sound(250);
delay(4);
nosound();
exit(1);
} // if
break;
} // if
} // if
} // for
} // while
} // menu func