
- •1 Постановка задачи
- •2 Алгоритмическое конструирование
- •2.1 Общая схема функционирования Функциональное назначение программного средства Предоставление пользователю возможности электронного прохождения игры «Pacman».
- •2.2 Алгоритмы работы
- •3 Программное конструирование
- •3.1 Описание типов
- •5 Список использованных источников
- •Наименование программы
- •Краткая характеристика области применения
3 Программное конструирование
3.1 Описание типов
SpriteABC |
Destroy – уничтожает спрайт |
Pacman |
x, y – координаты Pacman-а |
- |
Enemy |
x, y – координаты Enemy |
- |
emptyBlock |
x, y – координаты emptyBlock |
- |
FillBlock |
x, y – координаты FillBlock |
- |
Рисунок 8 – Uml таблица
КОНТРОЛЬНЫЙ ПРИМЕР
Экран Главного меню
Рисунок 9 – главный экран

Игровой процесс, запускается при нажатии кнопки –«New Game»
Рисунок 10 – Игровой процесс
Экран перехода на новый уровень
Рисунок 11 – Переход на следующий уровень
Экран победы, запускается при прохождении всех уровней
Рисунок 12 – Экран Победы
Рисунок 13 – Экран Поражения
5 Список использованных источников
1.Сайт«Википедия» [Электронный ресурс]-URL:http://ru.wikipedia.org/wiki/Pac-man
2.Сайт«ФриПэкмен» [Электронный ресурс]-URL:http://www.freepacman.org/
ПРИЛОЖЕНИЕ А. ТЕКСТЫ ОСНОВНЫХ ПРОГРАММНЫХ МОДУЛЕЙ
uses
GraphABC, ABCObjects, ABCSprites, Events;
const
C = 10;
type
position = record
x: integer;
y: integer;
end;
type
posEn = record
w: integer;
z: integer;
end;
pacman = class(spriteABC)
public
constructor create(x, y: integer);
begin
inherited Create(x, y, 'files\open.png');
Add('files\close.png');
AddState('close', 2);
Speed := 6;
end;
end;
enemy = class(spriteABC)
public
constructor create(x, y: integer);
begin
inherited Create(x, y, 'files\enemy.png');
end;
end;
apple_in = class(CircleABC)
public
constructor create(x, y: integer);
begin
inherited Create(x, y, 5, clRed);
end;
end;
var
pacmanchik: pacman;
Ap: array [1..c, 1..c] of apple_in;
mapArray: array [1..3] of string;
eN: enemy;
PosENEm: posEn;
game: boolean;
pos: position;
gameOv: RoundRectABC;
Filename: string;
Live, Nap, nLevel: integer;
sound: System.Media.SoundPlayer;
InfoString: RectangleABC;
Screen, NewGame, next, nextscreen, win: PictureABC;
var
anyBlock: SpriteABC;
type
tmap = array[1..c, 1..c] of char;
var
map: tmap;
type
emptyBlock = class(SpriteAbc)
constructor create(x, y: integer);
begin
inherited create(x, y, 'files\emptyBlock.png');
end;
end;
type
fillBlock = class(SpriteABC)
constructor create(x, y: integer);
begin
inherited create(x, y, 'files\fillBlock.png');
end;
end;
procedure ArrayOfMapSetup;
begin
mapArray[1] := ('maps\1.txt');
mapArray[2] := ('maps\2.txt');
mapArray[3] := ('maps\3.txt');
end;
procedure SetLevel(n: integer);
begin
Filename := mapArray[n];
end;
procedure ReadFileMap;
var
f: text;
i, j: integer;
begin
assign(f, Filename);
reset(f);
for i := 1 to c do
begin
for j := 1 to c do
read(f, map[j, i]);
readln(f);
end;
close(f);
end;
///процедура построения карты
procedure ReadMap();
begin
var i, j: integer;
begin
for i := 1 to c do
for j := 1 to c do
begin
case map[i, j] of
'1':
begin
anyBlock := new fillBlock(i * 50, j * 50);
anyBlock.ToFront;
end;
'0':
begin
anyBlock := new emptyBlock(i * 50, j * 50);
anyBlock.ToFront;
end;
'2':
begin
ap[i, j] := new apple_in((i * 50 + 25), (j * 50) + 25);
ap[i, j].ToFront;
Nap := Nap + 1;
end;
end;
end;
end;
end;
procedure CreateObjects(pos_x, pos_y: integer);
begin
pacmanchik := new pacman(pos.x, pos.y);
pacmanchik.ToFront;
end;
procedure CreateEnemy(pos_x, pos_y: integer);
begin
En := new enemy(posEnem.w, posEnem.z);
En.ToFront;
end;
procedure destroyObject;
begin
pacmanchik.Destroy();
end;
procedure ScreenUp;
begin
Window.Title := 'PACMAN RETURNS by Timofey Grintsevich';
screen := new PictureABC(0, 0, 'files\screen.png');
Screen.Center := WindowCenter;
SetWindowSize(600, 550);
end;
procedure GameOver;
begin
destroyObject;
GameOv := new RoundRectABC(100, 200, 400, 200, 30, Color.Violet);
GameOv.Center := Window.Center;
GameOv.Text := 'Game OVER';
game := false;
LockDrawingObjects;
Sleep(3000);
end;
procedure YouWin;
begin
Game := false;
nextscreen := new PictureABC(0, 0, 'files\sc.png');
win := new PictureABC(0, 0, 'files\win.png');
sleep(5000);
CloseWindow;
end;
procedure Gameproc;
begin
Live := 4;
Window.Title := 'Pacman';
SetWindowSize(600, 480);
ScreenUp;
NewGame := new PictureABC(320, 285, 'files\new.png');
SetWindowSize(600, 550);
RedrawObjects;
SetPenColor(clWhite);
ClearWindow(clWhite);
end;
procedure LiveOfPacman;
begin
Live := Live - 1;
destroyObject;
pos.x := 100;
pos.y := 100;
CreateObjects(pos.x, pos.y);
if Live = 0 then begin GameOver; end;
end;
procedure NewGameProc;
begin
NewGame.Visible := False;
Screen.Visible := false;
game := true;
pos.x := 100;
pos.y := 100;
posEnem.w := 450;
PosENEm.z := 200;
readFileMap;
ReadMap;
CreateObjects(pos.x, pos.y);
CreateEnemy(PosENEm.w, PosENEm.z);
InfoString := new RectangleABC(0, 0, Window.Width, 38, Color.black);
InfoString.Bordered := False;
InfoString.FontColor := clWhite;
InfoString.TextScale := 0.9;
end;procedure NextLevelScreen;
begin
nextscreen := new PictureABC(0, 0, 'files\sc.png');
next := new PictureABC(0, 0, 'files\next.png');
next.Center := windowCenter;
Sleep(2500);
end;
procedure NextLevel;
begin
game := false;
nLevel := nLevel + 1;
live:=live+1;
if nLevel = 4 then YouWin
else
begin
NextLevelScreen;
next.Visible := false;
SetLevel(nLevel);
NewGameProc;
end;
end;
procedure destroyAp;
begin
Ap[Trunc(pos.x / 50), Trunc(pos.y / 50)].Destroy;
map[trunc(pos.x / 50 ), trunc(pos.y / 50)] := (' ');
end;
procedure delAp;
begin
if map[trunc(pos.x / 50 ), trunc(pos.y / 50)] = (' ') then
Nap := Nap - 1;
end;
procedure rightMove;
var
i: integer;
begin
if (map[trunc(pos.x / 50 ) + 1, trunc(pos.y / 50)] <> '1') then
begin
for var j := 1 to 25 do
begin
pacmanchik.MoveOn(2, 0);
pos.x := pos.x + 2;
Sleep(12);
end;
end;
if (map[trunc(pos.x / 50 ), trunc(pos.y / 50)] = '2') then
begin
destroyAp;
delAp;
end;
end;
procedure LeftMove;
begin
begin
if (map[trunc(pos.x / 50.5 ), trunc(pos.y / 50)] <> '1') then
begin
for var j := 1 to 25 do
begin
pacmanchik.MoveOn(-2, 0);
pos.x := pos.x - 2;
Sleep(12);
end;
end;
if (map[trunc(pos.x / 50 ), trunc(pos.y / 50)] = '2') then
begin
destroyAp;
delAp;
end;
end;
end;
procedure DownMove;
begin
begin
if (map[trunc(pos.x / 50), trunc(pos.y / 50) + 1] <> '1') then
begin
for var j := 1 to 25 do
begin
pacmanchik.MoveOn(0, 2);
pos.y := pos.y + 2;
Sleep(12);
end;
end;
if (map[trunc(pos.x / 50 ), trunc(pos.y / 50)] = '2') then
begin
destroyAp;
delAp;
end;
end;
end;
procedure UpMove;
begin
begin
if (map[trunc(pos.x / 50.5 ) + 1, trunc(pos.y / 50.5)] <> '1') then
begin
for var j := 1 to 25 do
begin
pacmanchik.MoveOn(0, -2);
pos.y := pos.y - 2;
Sleep(12);
end;
end;
if (map[trunc(pos.x / 50 ), trunc(pos.y / 50)] = '2') then
begin
destroyAp;
delAp;
end;
end;
end;
procedure EnemyMove;
begin
if pos.Y = PosENEm.Z then
begin
if PosENEm.w > pos.x then
begin
if (map[trunc(PosENEm.w / 50.5 ), trunc(PosENEm.z / 50.5)] = '1') then
begin
for var I := 1 to 25 do
begin
eN.MoveOn(-2, 0);
PosENEm.w := PosENEm.w - 2;
Sleep(15);
if (PosENEm.w = pos.x) and (PosENEm.z = pos.y) then LiveOfPacman;
end;
end;
end;
if PosENEm.w < pos.x then
begin
if (map[trunc(PosENEm.w / 50.5 ) + 1, trunc(PosENEm.z / 50.5)] = '1') then
begin
for var I := 1 to 25 do
begin
eN.MoveOn(2, 0);
PosENEm.w := PosENEm.w + 2;
Sleep(15);
if (PosENEm.w = pos.x) and (PosENEm.z = pos.y) then LiveOfPacman;
end;
end;
end;
end;
if pos.x = PosENEm.w then
begin
if PosENEm.z > pos.y then
begin
if (map[trunc(PosENEm.w / 50.5 ) + 1, trunc(PosENEm.z / 50.5) - 1] = '1') then
begin
for var I := 1 to 25 do
begin
eN.MoveOn(0, -2);
PosENEm.z := PosENEm.z - 2;
Sleep(15);
if (PosENEm.w = pos.x) and ((PosENEm.z + 15) = pos.y) then LiveOfPacman;
end;
end;
end;
if PosENEm.z < pos.y then
begin
if (map[trunc(PosENEm.w / 50.5), trunc((PosENEm.z - 15) / 50.5) + 1] = '1') then
begin
for var I := 1 to 25 do
begin
eN.MoveOn(0, 2);
PosENEm.z := PosENEm.z + 2;
Sleep(15);
if (PosENEm.w = pos.x) and ((PosENEm.z) = pos.y) then LiveOfPacman;
end;
end;
end;
end;
end;
procedure KeyPress(Key: char);
begin
if (Key in ['G', 'П', 'g', 'п']) then
SetLevel(1);
NewGameProc;
end;
procedure MouseUp(x, y, mb: integer);
begin
if NewGame.PTInside(x, y) then
KeyPress('G');
end;
procedure ifNap;
begin
if Nap = 0 then
begin
Sleep(500);
NextLevel;
end;
end;
procedure ChangeInfoString;
begin
InfoString.Text := 'Жизней: ' + IntToStr(live) + ' Фруктов:' + IntToStr(Nap);
end;
procedure KeyDown(Key: integer);
begin
if game = true then
begin
case Key of
VK_Right: RightMove;
VK_Left: LeftMove;
VK_Up: UpMove;
VK_Down: DownMove;
end;
ChangeInfoString;
EnemyMove;
end;
ifnap;
end;
begin
nLevel := 1;
ArrayOfMapSetup;
screenUp;
sleep(5000);
Screen.Visible := false;
gameproc;
OnKeyDown := KeyDown;
OnKeyPress := KeyPress;
OnMouseUp := MouseUp;
LockDrawingObjects;
end.
«СОГЛАСОВАНО» «УТВЕРЖДЕНО»
Руководитель проекта зав. кафедрой ПОВТ и АС
«___»_____________2012г. «___»____________2012г.
Слоновский А.В. _____ Нейдорф Р.A. __________
Приложение Б. Техническое задание по ГОСТ 19.201-78 ЕСПД
А1. Введение