faraon, совет: если ты показываешь кому код, то форматируй его перед этим, а то его никто и читать то не станет.
Даю один бесплатный урок форматирования кода. Форматировал программой indent и чуть руками. Потрачено две минуты, а хоть что-то можно прочесть.
#include <graphics.h>
#include <stdlib.h>
#include "keyboard.h"
#include <conio.h>
#define M_LEFT 1
#define M_RIGHT 480
#define M_TOP 1
#define M_BOTTOM 500
#define MIAU_X 500
#define MIAU_Y 420
#define ACTIVE_COLOR RED
#define PASSIVE_COLOR YELLOW
#define ACTIVE_BACK_COLOR BROWN
#define PASSIVE_BACK_COLOR DARKGRAY
#define BORDER_COLOR GREEN
#define kbSpace 32
// #define kbLeft 19
// #define kbRight 4
// #define kbEsc 27
// #define kbEnter 13
void Cat(void);
void Mouse(void);
void Dog(void);
void Sheep(void);
int GrMenu(char *Items[], int N, int Top, int Left, int Right, int Bottom);
void DrawMenu(char *Items[], int N, int Top, int Left, int Right,
int Bottom, int active);
void main(void)
{
char *Items[] = { "Dog", "Cat", "Mouse", "Sheep", "Exit" };
int choice, N = 5;
int a = DETECT, b;
initgraph(&a, &b, "");
setbkcolor(BLUE);
outtextxy(M_LEFT - 1, M_TOP + 10,
"This text typed only once!!!Then restored by menu function");
b = 1;
do
{
choice = GrMenu(Items, N, M_LEFT, M_RIGHT, M_TOP, M_BOTTOM);
switch (choice)
{
case -1:
case 4:
b = 0;
break;
case 0:
Dog();
break;
case 1:
Mouse();
break;
case 2:
Sheep();
break;
case 3:
Cat();
break;
}
} while (b);
closegraph();
}
int GrMenu(char *Items[], int N, int Left, int Top, int Right, int Bottom)
{
long sz = imagesize(Left, Top, Right, Bottom);
void *image = malloc(sz);
if (image == NULL)
return -1;
getimage(Left, Top, Bottom, Right, image);
int choice = 0, Done = 0;
do
{
DrawMenu(Items, N, Left, Top, Right, Bottom, choice);
int key = GetCh();
switch (key)
{
case kbLeft:
if (choice > 0)
choice--;
else
choice = N - 1;
break;
case kbRight:
if (choice < N - 1)
choice++;
else
choice = 0;
break;
case kbEsc:
choice = -1;
case kbEnter:
case kbSpace:
Done = 1;
break;
}
} while (!Done);
putimage(Left, Top, image, COPY_PUT);
free(image);
return choice;
}
void DrawMenu(char *Items[], int N, int Left, int Right, int Top,
int Bottom, int active)
{
setcolor(BORDER_COLOR);
rectangle(Left, Top, Right, Bottom);
setfillstyle(SOLID_FILL, PASSIVE_BACK_COLOR);
bar(Left + 1, Top + 1, Right - 1, Bottom - 1);
settextstyle(GOTHIC_FONT, HORIZ_DIR, 3);
settextjustify(CENTER_TEXT, CENTER_TEXT);
setfillstyle(SOLID_FILL, ACTIVE_BACK_COLOR);
int x;
int y = (Bottom + Top) / 2;
int dx = (Right - Left) / (N + 1);
int dy = (Bottom - Top) / 2;
for (int i = 0; i < N; i++)
{
x = Left + (i + 1) * dx;
if (i == active)
{
setcolor(BORDER_COLOR);
fillellipse(x, y, dx - 7, dy - 5);
setcolor(ACTIVE_COLOR);
}
else
setcolor(PASSIVE_COLOR);
outtextxy(x, y, Items[i]);
}
}
void Cat(void)
{
setcolor(RED);
settextstyle(0, VERT_DIR, 1);
settextjustify(LEFT_TEXT, TOP_TEXT);
setfillstyle(SOLID_FILL, GREEN);
bar(MIAU_X, MIAU_Y, MIAU_X + 100, MIAU_Y + 50);
outtextxy(MIAU_X, MIAU_Y, "Mi-a-au!!");
outtextxy(MIAU_X, MIAU_Y + 30, "push any key");
getch();
}
void Mouse(void)
{
setcolor(GREEN);
settextstyle(0, VERT_DIR, 1);
settextjustify(LEFT_TEXT, TOP_TEXT);
setfillstyle(SOLID_FILL, RED);
bar(MIAU_X, MIAU_Y, MIAU_X + 100, MIAU_Y + 50);
outtextxy(MIAU_X, MIAU_Y, "Pi-pi-pi");
outtextxy(MIAU_X, MIAU_Y + 30, "push any key");
getch();
}
void Dog(void)
{
setcolor(YELLOW);
settextstyle(0, VERT_DIR, 1);
settextjustify(LEFT_TEXT, TOP_TEXT);
setfillstyle(SOLID_FILL, BROWN);
bar(MIAU_X, MIAU_Y, MIAU_X + 100, MIAU_Y + 50);
outtextxy(MIAU_X, MIAU_Y, "Gaw-gav!!");
outtextxy(MIAU_X, MIAU_Y + 30, "push any key");
getch();
}
void Sheep(void)
{
setcolor(BLUE);
settextstyle(0, VERT_DIR, 1);
settextjustify(LEFT_TEXT, TOP_TEXT);
setfillstyle(SOLID_FILL, WHITE);
bar(MIAU_X, MIAU_Y, MIAU_X + 100, MIAU_Y + 50);
outtextxy(MIAU_X, MIAU_Y, "Be-e-e-e!!");
outtextxy(MIAU_X, MIAU_Y + 30, "push any key");
getch();
}