Arrays Pascal中的数组问题

Arrays Pascal中的数组问题,arrays,pascal,Arrays,Pascal,我是帕斯卡阵列的新手,我非常想学习它们,因为我的梦想是开发游戏。我开始创建一个游戏,其中有一个玩家可以像波浪一样移动(就像Geonetry Dash游戏,但更简单一些),使用键“w”和“s”。问题是它不起作用。我很想追踪玩家,但好像没用!请告诉我怎么了 program gameArrays; uses crt; (*only crt*) var nx: array[1..20] of integer; ny: array[1..20] of integer

我是帕斯卡阵列的新手,我非常想学习它们,因为我的梦想是开发游戏。我开始创建一个游戏,其中有一个玩家可以像波浪一样移动(就像Geonetry Dash游戏,但更简单一些),使用键“w”和“s”。问题是它不起作用。我很想追踪玩家,但好像没用!请告诉我怎么了

program gameArrays;
uses crt;     (*only crt*)
var
nx: array[1..20] of integer;                
ny: array[1..20] of integer;
x,y:integer; {*Not much used.. y not used but x only once*}
input:char;  {*Input from player*}
f,l:integer;  {*I don't know how to explain these elements.. see the code and you will understand*}
 begin
 clrscr;
 x:=10;
 nx[1]:=x;    (*nx[X] is the trail of the player.. so nx[10] is 1 so it is the last*)
 nx[2]:=x-1;
 nx[3]:=x-2;
 nx[4]:=x-3;
 nx[5]:=x-4;
 nx[6]:=x-5;
 nx[7]:=x-6;
 nx[8]:=x-7;
 nx[9]:=x-8;
 nx[10]:=x-9;
 gotoxy(nx[1],15);   (*player is  on x:10 y:15*)
 write('�');
 ny[1]:=15;
 for f:=1 to 10 do
     ny[f]:=15;           (*ny is the trail that moves up and down following the player and all are y:20 at beginning*)
 repeat
 input:=readkey;   (*if input is w then player moves up, if input is s then player moves down*)
 if input='w' then
    repeat
    for f:=1 to 10 do
        begin
             gotoxy(nx[f],ny[f]);
             write(' ');
        end;            (*delete recent activities on the screen*)
    for f:=2 to 10 do
        ny[f]:=ny[f]-1;  (*once the  "repeat until" ends, ny[2 to 10] changes.. for ex y:2 become y:1 and y:3 become y:2*)
    for f:=1 to 10 do
        begin
             gotoxy(nx[f],ny[f]);  (*write all*)
             write('�');
        end;
    ny[1]:=ny[1]-1;
    delay(100);
    until keypressed;
 if input='s' then
    repeat
    for f:=1 to 10 do
        begin
             gotoxy(nx[f],ny[f]);
             write(' ');
        end;
    for f:=2 to 10 do
        ny[f]:=ny[f]+1;
    for f:=1 to 10 do
        begin
             gotoxy(nx[f],ny[f]);
             write('�');
        end;
    ny[1]:=ny[1]+1;
    delay(100);
    until keypressed;
 until input='q';
  end.

虽然我不知道你们是如何尝试这个解决方案的,但根据经验,我可以告诉你们,对象是做这些事情的最佳方式。下面的计划产生了我相信你的目标

program gameArrays;
uses crt;
type
   piece= object
    x,y:integer;
    S:char;
   end;
var
  trail:array[0..11] of piece;{we want 11 images trailing behind}
  i,e:integer;
  input:char;
  distancemax:integer;
  distance:integer;
  run:boolean; {you should know}
begin
  distancemax:=length(trail)-1;
  distance:=distance;

for i:=0 to length(trail)-1 do {incase you change the amount of images trailing}
begin
    trail[i].y:=15;
    trail[i].x:=15;{all pieces are originally in one position then stretch out}
end;

for i:=0 to length(trail)-2 do {passing characters to the trail pieces so you can see them}
  trail[i].S:=char(2);
  {loop ends here}
  trail[length(trail)-1].S:='O'; {giving the head a different character}
  run:=true;

  while run do
  begin
    clrscr;
    for i:=0 to length(trail)-1 do {drawing}
    begin
      gotoxy(trail[i].x,trail[i].y);
      write(trail[i].S);
    end;

    if distance<distancemax then {there is a limit to how far the body should stretch}
    begin
      for i:=0 to distance do
        dec(trail[i].x); {stretches out one at a time starting from the tail}
      {loop ends here}
      inc(distance); {increases the distance at each frame}
    end;

     for i:=0 to length(trail)-2 do {makes pieces from the tail up copy the y value of the one ahead /except for the head/}
       trail[i].y:=trail[i+1].y;

    if keypressed then input:=readkey; {prevent waiting for a keypress}

    case char(input) of {button press responses}
      'w':if trail[0].y>1 then dec(trail[length(trail)-1].y);
      's':if trail[0].y<25 then inc(trail[length(trail)-1].y);
      'q':run:=false;
    end;
    delay(100);
  end;
end.      
编程游戏阵列;
使用阴极射线管;
类型
工件=物体
x、 y:整数;
S:char;
结束;
变量
trail:工件的数组[0..11];{我们希望后面有11张图片}
i、 e:整数;
输入:字符;
distancemax:整数;
距离:整数;
运行:布尔;{你应该知道}
开始
距离最大值:=长度(轨迹)-1;
距离:=距离;
对于i:=0到长度(trail)-1{如果您更改了尾随图像的数量}
开始
轨迹[i].y:=15;
trail[i].x:=15;{所有部件最初处于一个位置,然后伸展}
结束;
对于i:=0到长度(trail)-2执行{将字符传递到trail片段以便可以看到它们}
trail[i].S:=char(2);
{循环到此结束}
轨迹[长度(轨迹)-1].S:='O';{给头部一个不同的字符}
run:=真;
边跑边做
开始
clrsc;
对于i:=0到长度(trail)-1 do{drawing}
开始
gotoxy(trail[i].x,trail[i].y);
写入(trail[i].S);
结束;
如果距离为1,则为dec(trail[长度(trail)-1].y);

“s”:如果跟踪[0].yit不起作用,则它不是一个有用的问题描述,除非您具体描述了它不起作用的方式。请这样做。试着描述代码的哪些部分不起作用。您期望的行为是什么,代码会做什么。优秀的开发人员还必须学习如何缩小问题范围并正确描述问题:-)顺便说一句:注释应该描述您为什么要做某事,而不是做什么。