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

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

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

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 16.12.2010, 23:04   #1
DevilSun
Новичок
Джуниор
 
Регистрация: 16.12.2010
Сообщений: 3
Восклицание Вместо меток использовать процедуры=(.

Помогите пожалуйста с курсачом.Прога работает и все сделано, но дело в том что я писал через метки, а препод не принимает.Прошу помочь перевести мою прогу в процедуры, а то у самого не получается( не работает(

Код:
program X_and_O;
uses crt;
var f : array[0..2,0..2] of integer; {pole}
    game,pcalc,ccalc : word;
    wv : integer;
    p1,c1,xcur,ycur,sv,sv2,sv3,int,m : byte;
    com,p2,c2 : char;
    move : boolean;
label start,plr_play,com_play,cp2,newgame,ng2,win,endgame;
begin
 int:=1;
 p1:=10;
 p2:='X';
 c1:=14;
 c2:='O';
 randomize;
 textbackground(2);
 goto newgame;

 {==================New Game==================================}
start:
 clrscr;
 f[0,0]:=0;
 f[0,1]:=0;
 f[0,2]:=0;
 f[1,0]:=0;
 f[1,1]:=0;
 f[1,2]:=0;
 f[2,0]:=0;
 f[2,1]:=0;
 f[2,2]:=0;
 textbackground(2);
 clrscr;
 textcolor(1);
 gotoxy(3,4);
 write('Player:    Computer(');
 case int of
  0 : write(' Hard');
  1 : write(' Norm');
  2 : write(' Easy');
 end;
 write('): 0');
 gotoxy(3,5);
 write('Game: 1');
 textbackground(7);
 textcolor(8);
 gotoxy(1,1);
 clreol;
 write(#24#25#26#27,' >> cursor movement    space >> go    1 >> New game    2 >> Exit      ');
 textbackground(2);
 if move then goto plr_play else goto com_play;

{=======================Player's turn==================================}
plr_play:
 if (game=100) or (game=200) or (game=300) then goto endgame;
 textcolor(1);
 gotoxy(10,4);
 write(pcalc);
 gotoxy(24,4);
 case int of
  0 : write('Hard');
  1 : write('Norm');
  2 : write('Easy');
 end;
 write('): ');
 write(ccalc);
 gotoxy(9,5);
 case game of
  0..100 : wv:=100-game;
  101..200 : wv:=200-game;
  else wv:=300-game;
 end;
 write(game,'(Remained until the end ',wv,' games)');
 gotoxy(35,10);
 write('ЪДДДВДДДВДДДї');
 gotoxy(35,11);
 write('і   і   і   і');
 gotoxy(35,12);
 write('ГДДДЕДДДЕДДДґ');
 gotoxy(35,13);
 write('і   і   і   і');
 gotoxy(35,14);
 write('ГДДДЕДДДЕДДДґ');
 gotoxy(35,15);
 write('і   і   і   і');
 gotoxy(35,16);
 write('АДДДБДДДБДДДЩ');
 sv:=0;
 repeat
  sv2:=f[trunc(sv/3),sv mod 3];  {trunc ysekaet do celogo chisla}
  if sv2<>0 then
               begin
                     gotoxy(trunc(sv/3)*4+37,(sv mod 3)*2+11);
                     if sv2=1 then
                                 begin textcolor(p1);
                                       write(p2);
                                 end
                               else
                                  begin textcolor(c1);
                                        write(c2);
                                  end;
               end;
  sv:=sv+1;
  until sv=9;
  textcolor(5);
  gotoxy(xcur*4+38,ycur*2+11);
  write('');
  sv:=0;
  repeat
    wv:=f[sv,0]+f[sv,1]+f[sv,2];
    if (wv=3) or (wv=-3)
       then goto win;
       wv:=f[0,sv]+f[1,sv]+f[2,sv];
    if (wv=3) or (wv=-3)
       then goto win;
       sv:=sv+1;
  until sv=3;
  wv:=f[0,0]+f[1,1]+f[2,2];
  if (wv=3) or (wv=-3)
     then goto win;
  wv:=f[2,0]+f[1,1]+f[0,2];
  if (wv=3) or (wv=-3)
     then goto win;
  if (f[0,0]<>0) and (f[0,1]<>0) and (f[0,2]<>0)
     and (f[1,0]<>0) and (f[1,1]<>0) and (f[1,2]<>0)
     and (f[2,0]<>0) and (f[2,1]<>0) and (f[2,2]<>0)
 then
    begin
        f[0,0]:=0;
        f[0,1]:=0;
        f[0,2]:=0;
        f[1,0]:=0;
        f[1,1]:=0;
        f[1,2]:=0;
        f[2,0]:=0;
        f[2,1]:=0;
        f[2,2]:=0;
        gotoxy(8,8);
        textcolor(14);
        write('Draw.       ');
        game:=game+1;
        if move
           then move:=false
           else move:=true;
        readkey;
        gotoxy(8,8);
        write('             ');
        if move
           then goto plr_play
           else goto com_play;
    end;
 com:=readkey;
 case com of
  '1' : goto newgame;
  '2' : exit;
  ' ' : if f[xcur,ycur]=0
           then begin f[xcur,ycur]:=1;
                      goto com_play;
                end;
  #27 : exit;
  #0 :
  begin
   com:=readkey;
   case com of
    #72 : if ycur>0
             then ycur:=ycur-1;
    #75 : if xcur>0
             then xcur:=xcur-1;
    #77 : if xcur<2
             then xcur:=xcur+1;
    #80 : if ycur<2
             then ycur:=ycur+1;
   end;
  end;
 end;
 goto plr_play;
DevilSun вне форума Ответить с цитированием
Старый 16.12.2010, 23:08   #2
DevilSun
Новичок
Джуниор
 
Регистрация: 16.12.2010
Сообщений: 3
По умолчанию

Код:
{=====================Computer's turn=============================}
com_play:
 if (game=100) or (game=200) or (game=300)
    then goto endgame;
 sv:=0;
 repeat
  sv2:=f[trunc(sv/3),sv mod 3];
  if sv2<>0
  then
     begin
          gotoxy(trunc(sv/3)*4+37,(sv mod 3)*2+11);
          if sv2=1
             then
                begin textcolor(p1);
                      write(p2);
                end
             else
                begin textcolor(c1);
                      write(c2);
                end;
     end;
  sv:=sv+1;
 until sv=9;
 sv:=0;
 repeat
  wv:=f[sv,0]+f[sv,1]+f[sv,2];
  if (wv=3) or (wv=-3)
     then goto win;
  wv:=f[0,sv]+f[1,sv]+f[2,sv];
  if (wv=3) or (wv=-3)
     then goto win;
  sv:=sv+1;
 until sv=3;
 wv:=f[0,0]+f[1,1]+f[2,2];
 if (wv=3) or (wv=-3)
    then goto win;
 wv:=f[2,0]+f[1,1]+f[0,2];
 if (wv=3) or (wv=-3)
    then goto win;
 if (f[0,0]<>0) and (f[0,1]<>0) and (f[0,2]<>0)
    and (f[1,0]<>0) and (f[1,1]<>0) and (f[1,2]<>0)
    and (f[2,0]<>0) and (f[2,1]<>0) and (f[2,2]<>0)
    then goto plr_play;
 if int=2
    then goto cp2;
 sv:=random(int+2);
 if (sv=2) and (int<>0)
    then goto cp2;
 if (f[1,1]=0) and (random(3)<>2)
    then
       begin f[1,1]:=-1;
       goto plr_play;
       end;
 sv:=0;
 repeat
  if (f[sv,0]+f[sv,1]+f[sv,2]=2) or (f[sv,0]+f[sv,1]+f[sv,2]=-2)
     then
        begin
             sv2:=0;
             repeat
             if f[sv,sv2]=0
                then f[sv,sv2]:=-1;
                     sv2:=sv2+1;
             until sv2=3;
             goto plr_play;
        end;
  if (f[0,sv]+f[1,sv]+f[2,sv]=2) or (f[0,sv]+f[1,sv]+f[2,sv]=-2)
     then
        begin
             sv2:=0;
             repeat
                   if f[sv2,sv]=0
                      then f[sv2,sv]:=-1;
                           sv2:=sv2+1;
             until sv2=3;
             goto plr_play;
        end;
  sv:=sv+1;
 until sv=3;
 if (f[0,0]+f[1,1]+f[2,2]=2) or (f[0,0]+f[1,1]+f[2,2]=-2)
    then
       begin
            if f[0,0]=0
               then f[0,0]:=-1;
            if f[1,1]=0
               then f[1,1]:=-1;
            if f[2,2]=0
               then f[2,2]:=-1;
            goto plr_play;
       end;
 if (f[2,0]+f[1,1]+f[0,2]=2) or (f[2,0]+f[1,1]+f[0,2]=-2)
    then
       begin
           if f[2,0]=0
              then f[2,0]:=-1;
           if f[1,1]=0
              then f[1,1]:=-1;
           if f[0,2]=0
              then f[0,2]:=-1;
           goto plr_play;
       end;
cp2:
 repeat
  sv:=random(10);
  if f[trunc(sv/3),sv mod 3]=0
     then
         begin f[trunc(sv/3),sv mod 3]:=-1;
               goto plr_play;
         end;
 until sv=11;
 goto plr_play;

{============================Game Settings==============================}
newgame:
 clrscr;
 textcolor(1);
 write('   Setting up a new game');
 gotoxy(4,7);
 write('1 >> Computer intelligence: ');
 gotoxy(4,8);
 write('2 >> You"ll play');
 gotoxy(4,11);
 write('5 >> First move');
 gotoxy(4,14);
 textcolor(1);
 write('Space >> start game    esc >> exit');
ng2:
 textcolor(14);
 gotoxy(31,7);
 case int of
  0 : write('Hard');
  1 : write('Norm');
  2 : write('Easy');
 end;
 gotoxy(26,8);
 if p2='X'
    then write('X')
    else write('O');
 gotoxy(20,11);
 case m of
  0 : write('Random  ');
  1 : write('Your    ');
  2 : write('Copmuter');
 end;
 gotoxy(4,9);
 textcolor(p1);
 write('3 >> Your color');
 gotoxy(4,10);
 textcolor(c1);
 write('4 >> Color computer');
 com:=readkey;
 case com of
  '1' : if int>0
           then dec(int)
           else int:=2;
  '2' : if p2='X'
           then
              begin p2:='O';
                    c2:='X';
              end
           else
              begin p2:='X';
                    c2:='O';
              end;
  '3' : begin if p1<15
                 then p1:=p1+1
                 else p1:=0;
              if p1=2
                 then p1:=3;
        end;
  '4' : begin if c1<15
                 then c1:=c1+1
                 else c1:=0;
              if c1=2
                 then c1:=3;
        end;
  '5' : if m<2
           then m:=m+1
           else m:=0;
  #27 : exit;
  ' ' :
  begin
   sv:=random(2);
   case m of
    0 : if sv<1
           then move:=true
           else move:=false;
    1 : move:=true;
    2 : move:=false;
   end;
   game:=1;
   pcalc:=0;
   ccalc:=0;
   goto start;
  end;
 end;
 goto ng2;
DevilSun вне форума Ответить с цитированием
Старый 16.12.2010, 23:09   #3
DevilSun
Новичок
Джуниор
 
Регистрация: 16.12.2010
Сообщений: 3
По умолчанию

Код:
{=======================Win===========================================}
win:
 gotoxy(8,8);
 clreol;
 if wv=3
    then
       begin pcalc:=pcalc+1;
             textcolor(4);
             write('You win!');
       end
    else
        begin textcolor(8);
              write('You lost.');
              ccalc:=ccalc+1;
        end;
 game:=game+1;
 f[0,0]:=0;
 f[0,1]:=0;
 f[0,2]:=0;
 f[1,0]:=0;
 f[1,1]:=0;
 f[1,2]:=0;
 f[2,0]:=0;
 f[2,1]:=0;
 f[2,2]:=0;
 readkey;
 gotoxy(1,8);
 clreol;
 if move
    then move:=false
    else move:=true;
 if move
    then goto plr_play
    else goto com_play;

{=============================Game over===============================}
endgame:
 delay(6400);
 while keypressed do readkey;
 clrscr;
 textcolor(7);
 gotoxy(35,3);
 if game<300
    then
        write('Tournament is over.')
        else write('Geme over.');
 textcolor(5);
 if pcalc>ccalc
    then
        begin gotoxy(15,6);
              write('You won with a score of ',pcalc,':',ccalc,' Congratulations!');
        end;
 if pcalc=ccalc
    then
        begin gotoxy(36,6);
              write('Drow. ',pcalc,':',ccalc);
        end;
 if pcalc<ccalc
    then
        begin gotoxy(15,6);
              write('Sorry,you lost by a score ',pcalc,':',ccalc);
        end;
 window(5,10,80,25);
 textcolor(14);
 write('Computer intilekt: ');
 case int of
  0 : writeln('Hard.');
  1 : writeln('Norm.');
  2 : writeln('Easy.');
 end;
 writeln;
 writeln('   Assessment of your abilities :');
 writeln('Winnings: ',round(pcalc/game*100),'%');
 writeln('Losses: ',round(ccalc/game*100),'%');
 writeln('Game to a draw: ',100-round(pcalc/game*100)-round(ccalc/game*100),'%');
 writeln;
 writeln('Computer experience:');
 textcolor(4);
 wv:=round(pcalc/game*100);
 case int of
  1 : dec(wv,-5);
  2 : dec(wv,-10);
 end;
 case wv of
  -10..-6 : write('"Well, and the brake!"');
  -5..0 : write('"do not know how to play."');
  1..10 : write('"Surely someone is worse?"');
  11..20 : write('"You need a good workout!"');
  21..30 : write('"Sucks play."');
  31..40 : write('"Say the least not very."');
  41..50 : write('"Not bad, not bad, but can be much better."');
  51..60 : write('"Good result. Though of course it is possible and better...');
  61..70 : write('"Play good!"');
  71..80 : write('"Cool game! You how many megabytes of memory?"');
  81..90 : write('"Good result! Oh, I would so..."');
  91..97 : write('"Great game!!!"');
  98..100 : begin textcolor(6);
                  write('"Are you a supercomputer?!"');
            end;
 end;
 writeln;
 writeln;
 writeln;
 textcolor(1);
 if game<300
    then write('Space >> continue the game    esc >> Exit')
    else write('Press any key to exit.');
 window(1,1,80,25);
 if game<300
    then
       repeat
           com:=readkey;
           case com of
           ' ' : begin inc(game);
                    if move
                       then move:=false
                       else move:=true;
                 goto start;
                 end;
           #27 : exit;
           end;
       until com=#27
    else
 begin
  readkey;
  exit;
 end;
 window(1,1,80,25);
 goto start;
end.
DevilSun вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Report Server. Как использовать хранимые процедуры? Сергей089 SQL, базы данных 0 19.10.2010 10:43
Title на форме. Как можно перерисовать caption на form? Или убрать его и вместо использовать картинки Шульц Общие вопросы Delphi 37 02.10.2010 09:46
Как вместо статических локальных переменных использовать переменные объявленные в namespace? Oleg_SK Общие вопросы C/C++ 25 05.07.2010 18:46
Что можно использовать вместо динамических массивов. Evgen1503 Общие вопросы Delphi 8 14.01.2010 21:54
Описание меток Yura_S Общие вопросы Delphi 5 20.10.2009 22:29