Pascal小遊戲 隨機函數

來源:互聯網
上載者:User

標籤:os   for   div   re   c   ar   

一個被人寫濫了的小程式,新手學習,Pascal By Chaobs

初學者可以用它來學習隨機函數的運用,當然你完全可以自己寫一個隨機函數。

var
   player1,player2:longint;
   a,b,l,o,i,v:longint; w:boolean;
begin
   randomize;
   write(‘A=‘);readln(player1);
   write(‘B=‘);readln(player2);
   b:=1;
   i:=1;
   while(player1>0)and(player2>0)do
   begin
     if i=1 then
     begin
       a:=random(101)+1;
       if a<=70 then
       begin
         writeln(‘A against B,B has ‘,a,‘ damage.‘);
         player2:=player2-a;
       end;
       if (a>70)and(a<=80) then
       begin
         o:=random(30);
         writeln(‘A thumping B,B has ‘,a*2+o,‘ damage.‘);
         player2:=player2-a*2;
       end;
       if (a>80)and(a<=85) then
       begin
         o:=random(120);
         writeln(‘A restored ‘,a*2+o-50,‘ points.‘);
         player1:=player1+a*2+o-50;
       end;
       if (a>85)and(a<=90) then
       begin
         writeln(‘A launched combo. ‘);
         l:=100;
         w:=true;
         while w do
         begin
           o:=random(71);
           writeln(‘B has ‘,o,‘ damage.‘);
           player2:=player2-o;
           if l<random(80) then w:=false;
           l:=l-random(15);
         end;
       end;
       if (a>90)and(a<=95) then
       begin
         o:=random(300);
         writeln(‘A launch from exploding!‘);
         writeln(‘A has ‘,o div 2,‘ damage.‘);
         writeln(‘B has ‘,o+10,‘ damage.‘);
         player1:=player1-o div 2;

player2:=player2-(o+10);
       end;
       if (a>95)and(a<=97) then
       begin
         writeln(‘A midicine,restore ‘,400,‘ points!‘);
         player1:=player1+400;
       end;
       if (a>97)and(a<=100) then
       begin
         o:=random(100)+100;
         writeln(‘A vampire ‘,o,‘ points.‘);
         player1:=player1+o;
         player2:=player2-o;
       end;
       if (a=101) then
       begin
         writeln(‘A colossus heaven boxing! ‘);
         l:=100;
         o:=random(20)+1;
         for v:=1 to 100 do
         begin
           writeln(‘B has ‘,v*o,‘ damage.‘);
           player2:=player2-v*o;
           if l<random(80) then break;
           l:=l-random(15);
         end;
       end;
       i:=2;
       if player1<0 then player1:=0;
       if player2<0 then player2:=0;
       writeln(‘   A   ‘,player1);
       writeln(‘   B   ‘,player2);
       readln;
     end;
     if i=2 then
     begin
       a:=random(101)+1;
       if a<=70 then
       begin
         writeln(‘B against A,A has ‘,a,‘ damage.‘);
         player1:=player1-a;
       end;
       if (a>70)and(a<=80) then
       begin
         o:=random(30);
         writeln(‘B thumping A,A has ‘,a*2+o,‘ damage.‘);
         player1:=player1-a*2;

end;                                            
       if (a>80)and(a<=85) then
       begin
         o:=random(120);
         writeln(‘B restored ‘,a*2+o-50,‘ points.‘);
         player2:=player2+a*2+o-50;
       end;
       if (a>85)and(a<=90) then
       begin
         writeln(‘B launched combo. ‘);
         l:=100;
         w:=true;
         while w do
         begin
           o:=random(71);
           writeln(‘A has ‘,o,‘ damage.‘);
           player1:=player1-o;
           if l<random(80) then w:=false;
           l:=l-random(15);
         end;
       end;
       if (a>90)and(a<=95) then
       begin
         o:=random(300);
         writeln(‘B launch from exploding!‘);
         writeln(‘B has ‘,o div 2,‘ damage.‘);
         writeln(‘A has ‘,o+10,‘ damage.‘);
         player2:=player2-o div 2;
         player1:=player1-(o+10);
       end;
       if (a>95)and(a<=97) then
       begin
         writeln(‘B midicine,restore ‘,400,‘ points!‘);
         player2:=player2+400;
       end;
       if (a>97)and(a<=100) then
       begin
         o:=random(100)+100;
         writeln(‘B vampire ‘,o,‘ points.‘);
         player2:=player2+o;
         player1:=player1-o;
       end;
       if (a=101) then
       begin
         writeln(‘B colossus heaven boxing! ‘);
         l:=100;
         o:=random(20)+1;
         for v:=1 to 100 do
         begin
           writeln(‘A has ‘,v*o,‘ damage.‘);
           player1:=player1-v*o;
           if l<random(80) then break;
           l:=l-random(15);
         end;
       end;
       i:=1;
       if player1<0 then player1:=0;
       if player2<0 then player2:=0;
       writeln(‘   A   ‘,player1);
       writeln(‘   B   ‘,player2);
       readln;
     end;
   end;
   writeln;
   if player1>player2 then writeln(‘A WIN!‘)
   else if player2>player1 then writeln(‘B WIN!‘)
        else writeln(‘DRAW‘);
   readln;
end.

 

 

 

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.