首页 > 代码库 > Pascal小游戏 随机函数

Pascal小游戏 随机函数

一个被人写滥了的小程序,新手学习,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.