Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 01.06.2010, 21:15   #1
olikik
 
Регистрация: 31.05.2010
Сообщений: 5
По умолчанию заменить использование метки циклом

Помогите пожалуйста в этой программе заменить использование метки , циклом:

Код:
program sheapkiller;
uses crt,graph;
const d=10000;
label 1;
var
s:string;
score,x2,x,y,gm,gd:integer;
ch:char;
b:boolean;
procedure sheapcl(xx,yy:integer);
begin
setlinestyle(solidln,0,ThickWidth);
setcolor(0);
setfillstyle(solidfill,0);
line(xx-10,yy+5,xx+10,yy+5);
setcolor(0);
sector(xx,yy,0,360,5,20);
setcolor(0);
setfillstyle(solidfill,0);
sector(xx-14,yy+7,0,360,2,12);
sector(xx+14,yy+7,0,360,2,12);
end;

procedure sheapris(xx,yy:integer);
begin
setlinestyle(solidln,0,ThickWidth);
setcolor(yellow);
setfillstyle(solidfill,red);
line(xx-10,yy+5,xx+10,yy+5);
setcolor(red);
sector(xx,yy,0,360,5,20);
setcolor(lightcyan);
setfillstyle(solidfill,lightcyan);
sector(xx-14,yy+7,0,360,2,12);
sector(xx+14,yy+7,0,360,2,12);
end;
begin
randomize;
clrscr;
initgraph(gm,gd,'');
1:
cleardevice;
settextstyle(0,0,1);
y:=0;
sheapris(320,450);
x:=320;
x2:=random(580);
repeat
setcolor(green);
str(score,s);
s:='SCORE->'+s;
outtextxy(10,10,s);
setlinestyle(0,0,0);
b:=keypressed;
if y>=480 then begin y:=0; x2:=random(580); end;
setcolor(0);
rectangle(x2,y,x2+60,y+60);
y:=y+1;
setcolor(lightgreen);
rectangle(x2,y,x2+60,y+60);
delay(round(d/20));
if ((y+60)>=430) and (x2<=(x+14)) and ((x-14)<=(x2+60)) then
begin
settextstyle(0,0,5);
cleardevice;setcolor(yellow); outtextxy(180,200,'YOU LAST');
readkey; readkey;
goto 1; end;

if b=true then begin
ch:=readkey;
if (ch=chr(75)) and (x>30) then begin sheapcl(x,450); x:=x-30; sheapris(x,450); end;
if (ch=chr(77)) and (x<610) then begin sheapcl(x,450); x:=x+30; sheapris(x,450); end;
if ch=chr(32) then begin setlinestyle(0,0,0); setcolor(yellow);
line(x,420,x,0); delay(d);
setcolor(0); line(x,420,x,0);
if (x>=x2) and (x<=x2+60) then begin
setcolor(0);
str(score,s);
s:='SCORE->'+s;
outtextxy(10,10,s);
score:=score+10;
setcolor(0);
rectangle(x2,y,x2+60,y+60);
y:=0; x2:=random(600);
end;
end;
end;
until ch=chr(27);
end.

Последний раз редактировалось Stilet; 02.06.2010 в 10:36.
olikik вне форума Ответить с цитированием
Старый 01.06.2010, 21:20   #2
L_M
Форумчанин Подтвердите свой е-майл
 
Регистрация: 25.02.2008
Сообщений: 289
По умолчанию

Вообще-то странная конструкция... Мне кажется это невозможным, потому как начало цикла repeat расположено между метой и переходом. Это так и должно быть? То есть код верен?
Упс...

Последний раз редактировалось L_M; 01.06.2010 в 21:35.
L_M вне форума Ответить с цитированием
Старый 01.06.2010, 23:23   #3
olikik
 
Регистрация: 31.05.2010
Сообщений: 5
По умолчанию

ну как бы программа работает..
olikik вне форума Ответить с цитированием
Старый 01.06.2010, 23:27   #4
Serge_Bliznykov
Старожил
 
Регистрация: 09.01.2008
Сообщений: 26,229
По умолчанию

Код:
program sheapkiller;
uses crt, graph;
const d = 10000;
var
  s: string;
  score, x2, x, y, gm, gd: integer;
  ch: char;
  b: boolean;
  PartyLost : boolean;

procedure sheapcl(xx, yy: integer);
begin
  setlinestyle(solidln, 0, ThickWidth);
  setcolor(0);
  setfillstyle(solidfill, 0);
  line(xx - 10, yy + 5, xx + 10, yy + 5);
  setcolor(0);
  sector(xx, yy, 0, 360, 5, 20);
  setcolor(0);
  setfillstyle(solidfill, 0);
  sector(xx - 14, yy + 7, 0, 360, 2, 12);
  sector(xx + 14, yy + 7, 0, 360, 2, 12);
end;

procedure sheapris(xx, yy: integer);
begin
  setlinestyle(solidln, 0, ThickWidth);
  setcolor(yellow);
  setfillstyle(solidfill, red);
  line(xx - 10, yy + 5, xx + 10, yy + 5);
  setcolor(red);
  sector(xx, yy, 0, 360, 5, 20);
  setcolor(lightcyan);
  setfillstyle(solidfill, lightcyan);
  sector(xx - 14, yy + 7, 0, 360, 2, 12);
  sector(xx + 14, yy + 7, 0, 360, 2, 12);
end;

begin
  randomize;
  clrscr;
  initgraph(gm, gd, '');
  repeat
    cleardevice;
    settextstyle(0, 0, 1);
    y := 0;
    score := 0;
    sheapris(320, 450);
    x := 320;
    x2 := random(580);
    PartyLost := false;
    repeat
      setcolor(green);
      str(score, s);
      s := 'SCORE->' + s;
      outtextxy(10, 10, s);
      setlinestyle(0, 0, 0);
      b := keypressed;
      if y >= 480 then begin y := 0; x2 := random(580); end;
      setcolor(0);
      rectangle(x2, y, x2 + 60, y + 60);
      y := y + 1;
      setcolor(lightgreen);
      rectangle(x2, y, x2 + 60, y + 60);
      delay(round(d / 20));
      if ((y + 60) >= 430) and (x2 <= (x + 14)) and ((x - 14) <= (x2 + 60)) then
      begin
        settextstyle(0, 0, 5);
        cleardevice; setcolor(yellow); outtextxy(180, 200, 'YOU LOST');
        PartyLost := true;
        readkey; readkey;
      end
      else begin
        if b = true then begin
          ch := readkey;
          if (ch = chr(75)) and (x > 30) then begin sheapcl(x, 450); x := x - 30; sheapris(x, 450); end;
          if (ch = chr(77)) and (x < 610) then begin sheapcl(x, 450); x := x + 30; sheapris(x, 450); end;
          if ch = chr(32) then begin setlinestyle(0, 0, 0); setcolor(yellow);
            line(x, 420, x, 0); delay(d);
            setcolor(0); line(x, 420, x, 0);
            if (x >= x2) and (x <= x2 + 60) then begin
              setcolor(0);
              str(score, s);
              s := 'SCORE->' + s;
              outtextxy(10, 10, s);
              score := score + 10;
              setcolor(0);
              rectangle(x2, y, x2 + 60, y + 60);
              y := 0; x2 := random(600);
            end;
          end;
        end;
     end;
   until PartyLost or (ch = chr(27));
  until ch = chr(27);
end.
1) добавил выход по Esc даже во время игры
2) у Вас счёт не сбрасывался после проигрыша... Если это сознательно было сделано - тогда Score := 0 вынесите до repeat
3) Вы проиграли по английски будет You Lost
4) для форматирования кода используйте специальный тэг [сode] (это кнопочка с решёточкой # )


L_M, именно поэтому ему препод и сказал убрать goto - потому что переходить можно хоть из середины цикла, хоть в середину цикла - в нарушение всех мыслимых и немыслимых правил построения нормальной программы... ;(
Serge_Bliznykov вне форума Ответить с цитированием
Старый 02.06.2010, 00:01   #5
olikik
 
Регистрация: 31.05.2010
Сообщений: 5
По умолчанию

Serge_Bliznykov спасибо вам огромное)))))Вы мне оч помогли)))))
p.s.я не "он" а "она"=)))
olikik вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Метки в Tbarseries (Delphi 7) Николай ПН Помощь студентам 0 31.03.2010 18:40
Создание метки FUNNY_SAM Общие вопросы C/C++ 0 23.12.2009 15:58
Вывод текста на метки HellMercenariess Общие вопросы Delphi 6 16.10.2009 14:30
Не работают метки ИВэТэшка Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 2 22.07.2009 22:05
Метки в делфи Neymexa Помощь студентам 1 29.01.2009 16:52