感谢上外静中任淳同学提供
 
uses crt;
label
  h;         //h是重新开始游戏
const
  y1=18;
  y2=18;       //p1,p2的纵坐标
var
  x1,x2:byte;  //p1,p2的横坐标
  act:byte;    //p2动作
  sec,sec1:integer;  //时间间隔
  p,q:byte;  //p1,p2的生命值
  ek:byte;   //用于增强p2防御力
  c:char;    //用于读取键盘敲击的键
  m,e:char;  //p1,p2的朝向(判断往哪里攻击)
  i,j:byte;  //循环变量
  ys1,ys2:byte; //p1,p2的颜色
  l,r:boolean;  //l:p1是否胜利  r:p2是否胜利
  f:boolean;    //游戏是否结束
  y,n:boolean;  //判断玩家是否继续
 
procedure start;
begin
  clrscr;
  textcolor(lightmagenta);
  writeln('Fighting Game');
  textcolor(magenta);
  writeln('a: left');
  writeln('d: right');
  writeln('j: attack');
  writeln('space: pause');
  textcolor(yellow);
  writeln('You are p1.');
  while not keypressed do x1:=10;
  clrscr;
  textcolor(lightgreen);
  gotoxy(34,10);
  write('ARE YOU READY? ');  //倒计时
  textcolor(lightred);
  for i:=3 downto 1 do begin
    write(i);
    sound(100);
    delay(1000);
    write(#8);
    nosound;
  end;
  clrscr;
  textcolor(lightblue);
  gotoxy(40,10);
  write('GO!');
  sound(1000);
  delay(1000);
  nosound;
  clrscr;
end;
 
procedure life;  //打印生命值
begin
  p:=10;
  q:=10;
  gotoxy(11,1);
  textcolor(ys1);
  for i:=1 to p do write('+');
  gotoxy(33,1);
  write('p1');
  textcolor(lightred);
  write('    VS    ');
  textcolor(ys2);
  write('p2');
  gotoxy(61,1);
  for i:=1 to q do write('+');
end;
 
procedure me;  //打印p1
begin
  textcolor(ys1);
  gotoxy(x1,y1-1);
  write('*');
  gotoxy(x1,y1);
  write('|');
  gotoxy(x1,y1+1);
  write('^');
end;
 
procedure enemy;  //打印p2
begin
  textcolor(ys2);
  gotoxy(x2,y2-1);
  write('*');
  gotoxy(x2,y2);
  write('|');
  gotoxy(x2,y2+1);
  write('^');
end;
 
procedure floor;  //地板
begin
  textbackground(green);
  for i:=20 to 25 do
    for j:=1 to 80 do begin
      gotoxy(j,i);
      write(' ');
    end;
  textbackground(black);
end;
 
procedure a;  //p1向左
begin
  if x1>1 then begin
    gotoxy(x1,y1-1);
    write(' ');
    gotoxy(x1,y1);
    write(' ');
    gotoxy(x1,y1+1);
    write(' ');
    x1:=x1-1;
  end;
    m:='a';
    me;
    enemy;
end;
 
procedure d;  //p1向右
begin
  if x1<80 then begin
    gotoxy(x1,y1-1);
    write(' ');
    gotoxy(x1,y1);
    write(' ');
    gotoxy(x1,y1+1);
    write(' ');
    x1:=x1+1;
  end;
    m:='d';
    me;
    enemy;
end;
 
procedure s;  //p1攻击
begin
  textcolor(ys1);
  if (m='a') and (x1>1) then begin
    gotoxy(x1-1,y1);
    write('-');
    if x1>=3 then begin
      gotoxy(x1-2,y1);
      write('(');
    end;
    if (x1-1=x2) or (x1-2=x2) then begin
      ek:=ek+1;
      if (q>0) and (ek=10) then begin
        q:=q-1;
        ek:=0;
      end;
      gotoxy(70-q,1);
      write(' ');
      textcolor(lightred);
      gotoxy(x2,y2-1);
      write('*');
      gotoxy(x2,y2+1);
      write('^');
      delay(50);
    end;
    delay(50);
    gotoxy(x1-1,y1);
    write(' ');
    if x1>=3 then begin
      gotoxy(x1-2,y1);
      write(' ');
    end;
  end
  else if (x1<80) and (m='d') then begin
    gotoxy(x1+1,y1);
    write('-');
    if x1<=78 then write(')');
    if (x1+1=x2) or (x1+2=x2) then begin
      ek:=ek+1;
      if (q>0) and (ek=10) then begin
        q:=q-1;
        ek:=0;
      end;
      gotoxy(70-q,1);
      write(' ');
      textcolor(lightred);
      gotoxy(x2,y2-1);
      write('*');
      gotoxy(x2,y2+1);
      write('^');
      delay(50);
    end;
    delay(50);
    gotoxy(x1+1,y1);
    write(' ');
    if x1<=78 then begin
      gotoxy(x1+2,y1);
      write(' ');
    end;
  end;
  if q=0 then begin
    f:=false;
    r:=false;
  end;
  me;
  enemy;
end;
 
procedure je;  //p2向左
begin
  if x2>1 then begin
    gotoxy(x2,y2-1);
    write(' ');
    gotoxy(x2,y2);
    write(' ');
    gotoxy(x2,y2+1);
    write(' ');
    x2:=x2-1;
  end;
  e:='j';
  me;
  enemy;
end;
 
procedure le;  //p2向右
begin
  if x2<80 then begin
    gotoxy(x2,y2-1);
    write(' ');
    gotoxy(x2,y2);
    write(' ');
    gotoxy(x2,y2+1);
    write(' ');
    x2:=x2+1;
  end;
  e:='l';
  me;
  enemy;
end;
 
procedure k;  //p2攻击
begin
  textcolor(ys2);
  if (e='j') and (x2>1) then begin
    gotoxy(x2-1,y2);
    write('-');
    if x2>=3 then begin
      gotoxy(x2-2,y2);
      write('(');
    end;
    if (x2-2=x1) or (x2-1=x1) then begin
      if p>0 then p:=p-1;
      gotoxy(11+p,1);
      write(' ');
      textcolor(lightred);
      gotoxy(x1,y1-1);
      write('*');
      gotoxy(x1,y1+1);
      write('^');
      delay(50);
    end;
    delay(50);
    gotoxy(x2-1,y2);
    write(' ');
    if x2>=3 then begin
      gotoxy(x2-2,y2);
      write(' ');
    end;
  end
  else if (e='l') and (x2<80) then begin
    gotoxy(x2+1,y2);
    write('-');
    if x2<=78 then begin
      gotoxy(x2+2,y2);
      write(')');
    end;
    if (x2+1=x1) or (x2+2=x1) then begin
      if p>0 then p:=p-1;
      gotoxy(11+p,1);
      write(' ');
      textcolor(lightred);
      gotoxy(x1,y1-1);
      write('*');
      gotoxy(x1,y1+1);
      write('^');
      delay(50);
    end;
    delay(50);
    gotoxy(x2+1,y2);
    write(' ');
    if x2<=78 then write(' ');
  end;
  if p=0 then begin
    f:=false;
    l:=false;
  end;
  me;
  enemy;
end;
 
begin  //主程序
  cursoroff;
  randomize;
h:l:=true;  //判断p1胜利
  r:=true;  //判断p2胜利
  f:=true;  //判断游戏是否结束
  sec:=(random(2)+1)*50;  //p2动作时间间隔
  sec1:=0;  //时间间隔
  x1:=10;   //p1横坐标位置
  m:='d';   //p1面向的方向(d右,a左)
  ys1:=14;  //定义p1的颜色(黄色)
  x2:=71;   //p2横坐标位置
  e:='j';   //p2面向的方向(l右,j左)
  ys2:=8;   //定义p2的颜色(暗灰色)
 
  start;  //操作说明
  life;   //显示生命值
  me;     //显示p1
  enemy;  //显示p2
  floor;  //显示地板
 
  while f do begin
    if keypressed then begin
      c:=readkey;
      if c=' ' then begin
        gotoxy(38,12);
        textcolor(lightmagenta);
        write('PAUSE');
        c:='p';
        while c<>' ' do
          if keypressed then c:=readkey;
        gotoxy(38,12);
        write('     ');      //擦除'pause'
      end;                   //暂停
 
      if c='a' then a;
      if c='d' then d;
      if c='j' then s;       //左右和攻击
    end;
 
    delay(5);
    sec1:=sec1+5;            //时间暂停
    if sec1>=sec then begin  //随机时间间隔到达后
      sec1:=0;
      sec:=(random(2)+1)*50;
 
      act:=random(2);
      if abs(x1-x2)>=3 then
      begin
        if x2<x1 then le else je;
      end                    //判断p1朝哪个方向走
      else                   //当p1,p2间距小于3,即x1,x2在攻击范围内时
      begin
 
        if x1<x2 then        //p1在p2左面
          if e='l' then le     //p2背对p1时
                   else k      //p2正对p1时
 
        else if x2<x1 then   //p1在p2右面
          if e='j' then je     //p2背对p1时
                   else k      //p2正对p1时
 
        else if x2=x1 then   //p1,p2重叠时
        case act of
          0: je;
          1: le;
        end;                 //在p1,p2在同一位置时控制p2离开
 
      end;
    end;
  end;
 
  delay(500);
  sound(100);       //以下是判断p1,p2哪方胜利还是平手
  if l then begin   //如果p1胜利
    gotoxy(x2,y2-1);
    write(' ');
    gotoxy(x2,y2);
    write(' ');
    gotoxy(x2,y2+1);
    write(' ');
    textcolor(ys2);
    gotoxy(x2-1,y2+1);
    write('>-*');
    delay(2000);
    nosound;
    clrscr;
    sound(1000);
    textcolor(yellow);
    gotoxy(37,10);
    write('YOU WIN!');
  end
  else if r then begin  //如果p2胜利
    gotoxy(x1,y1-1);
    write(' ');
    gotoxy(x1,y1);
    write(' ');
    gotoxy(x1,y1+1);
    write(' ');
    textcolor(ys1);
    gotoxy(x1-1,y1+1);
    write('*-<');
    delay(2000);
    nosound;
    clrscr;
    sound(1000);
    textcolor(lightred);
    gotoxy(37,10);
    write('YOU LOSE');
  end
  else begin   //平手
    gotoxy(x1,y1-1);
    write(' ');
    gotoxy(x1,y1);
    write(' ');
    gotoxy(x1,y1+1);
    write(' ');
    gotoxy(x2,y2-1);
    write(' ');
    gotoxy(x2,y2);
    write(' ');
    gotoxy(x2,y2+1);
    write(' ');
    textcolor(ys1);
    gotoxy(x1-1,y1+1);
    write('*-<');
    textcolor(ys2);
    gotoxy(x2-1,y2+1);
    write('>-*');
    delay(2000);
    nosound;
    clrscr;
    sound(1000);
    textcolor(lightgreen);
    gotoxy(36,10);
    write('nobody wins');
  end;
  delay(5000);
  nosound; //以下为判断是否继续
  clrscr;
  y:=true;
  n:=false;
  textcolor(7);
  gotoxy(38,11);
  write('REPLAY?');
  gotoxy(24,12);
  write('(A: right D: left Enter: dicide)');
 
  while c<>#13 do begin
    gotoxy(36,13);
    if y then textcolor(blink) else textcolor(7);
    write('yes');
    textcolor(7);
    write('     ');
    if n then textcolor(blink) else textcolor(7);
    write('no');
    if keypressed then begin
      c:=readkey;
      if c='a' then begin
        y:=true;
        n:=false;
      end
      else if c='d' then begin
        y:=false;
        n:=true;
      end
      else if c=#13 then
        if y then goto h;  //重新开始
    end;
  end;
end.

Fighting Game的更多相关文章

  1. HDU4930 Fighting the Landlords 模拟

    Fighting the Landlords Fighting the Landlords Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  2. Z - Fighting 和 Depth-bias

    Depth-bias操作在clipping之后进行实施,所以depth-bias对几何clipping没有影响. 另外需要注意的是:对一个给定体元(primitive),bias值是一个常量,在进行差 ...

  3. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  4. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  5. URAL 2025. Line Fighting (math)

    2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...

  6. 【翻唱】Keep On Fighting

    http://video.yingtu.co/0/77868591-502c-4af1-853b-d313e83c94a9.mp4 Keep On Fighting

  7. hdu4930 Fighting the Landlords(模拟 多校6)

    题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...

  8. HDU 4930 Fighting the Landlords(扯淡模拟题)

    Fighting the Landlords 大意: 斗地主... . 分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black ...

  9. Fighting regressions with git bisect---within git bisect algorithm

    https://www.kernel.org/pub/software/scm/git/docs/git-bisect-lk2009.html Fighting regressions with gi ...

随机推荐

  1. $('div','li'),$('div , li'),$('div li')的区别

    要搞清楚$('div','li') 和 $('div , li') 和 $('div li') 区别: $('div','li'):是$(子,父),是从父节点里找子,而不是找li外面的div $('d ...

  2. .htaccess的301重定向代码

    把不带www的域名301到带www的域名 RewriteEngine On RewriteCond %{http_host} ^example.com$ [NC] RewriteRule ^(.*)$ ...

  3. 【仿真】【modelsim】:verilog功能仿真流程

    一.编写verilog源文件,在diamond中编译.编写testbench文件.在diamond设置中将仿真工具设置为modelsim,运行仿真向导 二.自动进入modelsim, 编译全部 运行仿 ...

  4. 1172. Ship Routes

    http://acm.timus.ru/problem.aspx?space=1&num=1172 水题DP   大整数直接上java 代码: import java.math.BigInte ...

  5. C# 文件夹加密

    可以加密文件内容,也可以对文件夹本身进行加密,本文对文件夹加密. 一.指定或生成一个密钥 1)指定的密钥 /// <summary> /// 密钥,这个密码可以随便指定 /// </ ...

  6. ubuntu SecureCRT破解

    操作过程: 操作过程都在终端中执行.Ubuntu 的破解 : 下载程序:   wget 链接: https://pan.baidu.com/s/1nvdJl7j 密码: 2ryk 运行破解 /usr/ ...

  7. SQL升级脚本实现按版本差异化升级

    目前的项目里面,升级脚本是一个SQL文件,无论软件从哪个版本升级,都会把SQL文件里面的语句全部执行一遍,这样存在两个问题: 1.SQL升级文件很庞大,几M很常见,导致文件的加载很慢: 2.重复执行脚 ...

  8. Linux的yum源的配置

    yum实际上是管理的rpm软件包 只要连接网络就可以使用在线的yum源,不用配置本地yum源 网络yum源/etc/yum.repos.d/fedora.repo(Fedora)[fedora]nam ...

  9. E1_1 用邻接矩阵存储有向图,并输出各顶点的出度和入度

    参考书:图论算法理论.实现及应用(北京大学出版社) 输入数据:(test.txt) 程序: /* 邻接矩阵存储有向图 */ #include <cstring> #include < ...

  10. JM8.6学习

    1. vs2010 设置参数 编译运行JM8.6 (参考http://bbs.chinavideo.org/forum.php?mod=viewthread&tid=15695&hig ...