Большой Воронежский Форум
» Программирование>Помогите пжл!!!!паскаль!!!перевод из статики в динамику!!!
jakysh 14:15 17.06.2008
Доброго времени суток!!!честное слово знал бы как перевел бы...
требуют чтобы был или стек или очередь!!!для меня это вообще не ясно как это сделать!!!
Помогите пжл!!!а то меня выпруть прям с первого курса(((
задача изначальная такая:
комната разделена на 6ть квадратов 5ть из них заполнены мебелью, необходимо сначала расставить так сказать мебель а потом поменять кресло и шкаф местами!!!
вот изходник::
program mebel;
uses Crt, Graph; {подключение дополнительных модулей}

type TPole = array[1..3,1..2] of Integer; {определяем тип - поле}
{поле для игры}
var pole: TPole; {поле игры, где 0 -пустая клетка,}
{1-стоит шкаф,}
{2-стоит кресло,}
{3-стоит стоит стул 1}
{4-стоит стоит стул 2}
{5-стоит стоит стол}


grDriver: Integer;
grMode: Integer;
ErrCode: Integer;
Xs,Ys, {первоначальные координаты места шкафа}
Xk,Yk, {первоначальные координаты места кресла}
Flag_R:integer; {флаг расстановки на поле, мебели}

{процедура очистки экрана}
procedure Clr;
begin
SetFillStyle(0,0);
Bar(0,0,GetMaxX,GetMaxY);
end;

{вывод подсказки в левом верхнем углу экрана}
procedure Help;
begin
SetTextStyle(0,0,0);
SetColor(3);
Rectangle(10,10,163,180);
OutTextXY(15,15,'Ypravlenie');
{ OutTextXY(15,30,' - Peredvijenie');}
OutTextXY(15,45,'"Probel" - Hod');
OutTextXY(15,60,'"ESC" - Vihod');
SetFillStyle(1,4);
Bar(15,75,15+30,75+30);
OutTextXY(50,87,'-Shkaf');
SetFillStyle(1,5);
Bar(15,110,15+30,110+30);
OutTextXY(50,122,'-Kreslo');
SetFillStyle(1,6);
Bar(15,145,15+30,145+30);
OutTextXY(50,157,'-Stol ili Stul');

end;

procedure Init (var Pole: TPole);
var X, Y: Integer;
begin
for X := 1 to 3 do
for Y := 1 to 2 do
Pole[X,Y] := 0;
Flag_R:=0;
end;

function Prover(Pole:TPole;x,y:integer):boolean;
var
flag:boolean;
begin
flag:=false;
if (x=1) and (y=1) and ((Pole[x,y+1]=0) or (Pole[x+1,y]=0)) then flag:=true;
if (x=2) and (y=1) and ((Pole[x-1,y]=0) or (Pole[x,y+1]=0) or (Pole[x+1,y]=0) ) then flag:=true;
if (x=3) and (y=1) and ((Pole[x-1,y]=0) or (Pole[x,y+1]=0)) then flag:=true;

if (x=1) and (y=2) and ((Pole[x,y-1]=0) or (Pole[x+1,y]=0)) then flag:=true;
if (x=2) and (y=2) and ((Pole[x-1,y]=0) or (Pole[x,y-1]=0) or (Pole[x+1,y]=0)) then flag:=true;
if (x=3) and (y=2) and ((Pole[x-1,y]=0) or (Pole[x,y-1]=0)) then flag:=true;

Prover:=flag;
end;



procedure Proris_pole(Pole: TPole);
var i,j,X,Y:integer;
begin
{Clr;}
SetColor(1);
j:=75;
for i:=1 to 4 do
begin
Line(GetMaxX div 2-j,GetMaxY div 2-50,GetMaxX div 2-j,GetMaxY div 2+50);
j:=j-50;
end;
j:=50;
for i:=1 to 3 do
begin
Line(GetMaxX div 2-75,GetMaxY div 2-j,GetMaxX div 2+75,GetMaxY div 2-j);
j:=j-50;
end;
i:=GetMaxX div 2-65;
for X := 1 to 3 do
begin
j:=GetMaxY div 2-40;
for Y := 1 to 2 do
begin
case Pole[X,Y] of
0: SetFillStyle(1,0);
1: SetFillStyle(1,4);
2: SetFillStyle(1,5);
3: SetFillStyle(1,6);
4: SetFillStyle(1,6);
5: SetFillStyle(1,6);
end;
Bar(i,j,i+30,j+30);
j:=j+50;
end;
i:=i+50;
end;
end;

procedure Kursor;
var
xx,yy,ii,jj,x,y,i,j:integer;
c:char;
flag:boolean;
begin
x:=1;y:=1;
i:=GetMaxX div 2-65;
j:=GetMaxY div 2-40;
SetColor(11);
Rectangle(i,j,i+30,j+30);
flag:=true;
while(flag) do
begin
c:=readkey;
case c of
#75:
if(x-1>0) then
begin
i:=i-50;
x:=x-1;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
end;
#77:
if(x+1<4) then
begin
i:=i+50;
x:=x+1;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
end;
#72:
if(y-1>0) then
begin
j:=j-50;
y:=y-1;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
end;
#80:
if(y+1<3) then
begin
j:=j+50;
y:=y+1;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
end;
#32:
begin
if(pole[x,y]=0) and (Flag_R<5)then
begin
inc(Flag_R);
if(Flag_R=1) then
begin
Xs:=x;
Ys:=y;
end;
if(Flag_R=2) then
begin
Xk:=x;
Yk:=y;
end;
pole[x,y]:=Flag_R;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
end
else
if(Prover(pole,x,y)) then
begin
for ii := 1 to 3 do
for jj := 1 to 2 do
if pole[ii,jj] = 0 then
begin
xx:=ii;
yy:=jj;
end;
ii:=pole[xx,yy];
pole[xx,yy]:=pole[x,y];
pole[x,y]:=ii;
Proris_pole(pole);
SetColor(11);
Rectangle(i,j,i+30,j+30);
if(pole[Xs,Ys]=2)and(pole[Xk,Yk]=1)then
begin
flag:=false;
end;
end;
end;
#27:begin
flag:=false;
end;
end; {end case}
end;{end while}
OutTextXY(GetMaxX div 2-100,GetMaxY div 2+120,'<<<GAME OVER>>>');
end;

BEGIN
grDriver := Detect;
InitGraph(grDriver, grMode,'D:\bp\bgi');
ErrCode := GraphResult;
if ErrCode = grOk then
begin
Init(pole);
Help;
Proris_pole(pole);
Kursor;
Readkey;
CloseGraph;
end
else
Writeln('Ошибка инициализации нрафического режима:', GraphErrorMsg(ErrCode));
end. [Ответ]
-=leo=- 14:55 17.06.2008
jakysh,
нууу..что такое указатель хоть знаем? [Ответ]
-=leo=- 14:56 17.06.2008

Сообщение от :
BEGIN
grDriver := Detect;
InitGraph(grDriver, grMode,'D:\bp\bgi');
ErrCode := GraphResult;
if ErrCode = grOk then
begin
Init(pole);
Help;
Proris_pole(pole);
Kursor;
Readkey;
CloseGraph;
end
else
Writeln('Ошибка инициализации нрафического режима:', GraphErrorMsg(ErrCode));
end.

господи..это откуда?? где же ты учишься? [Ответ]
jakysh 15:59 17.06.2008
а что?)))всё так хреново???
ну если не трудно сделайте из этого "г_о_в_н_а" что-то похожее на конфетку...или пусть даже останется говно но только с динамическими данными [Ответ]
jakysh 16:00 17.06.2008
pointer знаю но толка от этого))) [Ответ]
jakysh 18:11 19.06.2008
ну помогите лучше чем издеваться!!! [Ответ]
jakysh 11:26 21.06.2008
????фсё тема умерла??? [Ответ]
dn2k4 16:31 22.06.2008

Сообщение от jakysh:
????фсё тема умерла???

Ну, если ты с алгоритмом сумел справиться, то наверно да =) [Ответ]
jakysh 10:23 24.06.2008
dn2k4, тут без какого либо алгоритма относящегося к графам)))
название тему звучит помогите с переводом в динамику...я её неправильно написал)))переведите в динамику пжл кому не тяжело!!!
спасибо!!! [Ответ]
Вий 13:14 03.07.2008
переведи все массивы с прямым направлением движения в очередь, где FIFO в стек... [Ответ]
dn2k4 16:27 03.07.2008
Вий, в стек не получится, если ты сделаешь -1, то там будет чистый LIFO [Ответ]
Вверх