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.

 

 

 

 
posted @   Chaobs  阅读(680)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示