#include "graphics.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
enum Direction {LEFT, UP, RIGHT, DOWN};
const int Width = 15;
const int Height = 15;
const int CellSize = 30;
int Cell[Width][Height]={
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
};
void DrawField()
{
setcolor(WHITE);
rectangle(0, 0, 30 * Width, 30 * Height);
for (int i = 1; i < (Width - 1); i++)
line(i * CellSize, 1, i * CellSize, Height * CellSize);
for (i = 1; i <= (Height - 1); i++)
line(1, i * CellSize, Width * CellSize, i * CellSize);
setfillstyle(1, WHITE);
for (i = 0; i < Width; i++)
for (int j = 0; j < Height; j++)
if (Cell[j] == 1)
bar(i * CellSize, j * CellSize, (i + 1) * CellSize,
(j + 1) * CellSize);
}
class CharacterClass
{
int Radius;
int X, Y;
public:
CharacterClass();
void Draw();
void Erase();
void Move(int Cell[Width][Height], Direction dir);
};
CharacterClass::CharacterClass()
{
Radius = 15;
X = 7; Y = 0;
}
void CharacterClass::Draw()
{
setcolor(BLUE);
setfillstyle(1, BLUE);
fillellipse((2 * X + 1) * Radius, (2 * Y + 1) * Radius, Radius,
Radius);
}
void CharacterClass::Erase()
{
setcolor(BLACK);
setfillstyle(1, BLACK);
fillellipse((2 * X + 1) * Radius, (2 * Y + 1) * Radius, Radius,
Radius);
}
void CharacterClass::Move(int Cell[Width][Height], Direction dir)
{
Erase();
int Ok;
switch(dir)
{
case LEFT: if ((X > 0) && Cell[X - 1][Y] != 1) X--; break;
case UP: if (Y > 0 && Cell[X][Y - 1] != 1) Y--; break;
case RIGHT: if (X < Width && Cell[X + 1][Y] != 1) X++; break;
case DOWN: if (Y < Height && Cell[X][Y + 1] != 1) Y++; break;
}
Draw();
}
void main()
{
void GraphInit();
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
}
int exitOk = 0;
char c;
DrawField();
CharacterClass Character;
Character.Draw();
while (!exitOk)
{
c = getch();
switch (c)
{
case 27: exitOk = !0;
case 75: Character.Move(Cell, LEFT); break;
case 72: Character.Move(Cell, UP); break;
case 77: Character.Move(Cell, RIGHT); break;
case 80: Character.Move(Cell, DOWN); break;
}
DrawField();
}
closegraph();
}
Помогите
1.«Рыбки в аквариуме» плавают, пуская воздушные пузыри.
И еще, где тут ошибка?? При запуске виснет весь комп(((
Код: