Pascal小游戏 双人射击
一个双人的游戏 Pascal源码附上
只要俩人不脑残,一下午玩不完。。。
又是控制台游戏中的一朵奇葩。
Free Pascal 射击游戏
Program shooting_game;
uses crt;
const cz:array[1..4,1..2] of -1..1=((0,1),(1,0),(0,-1),(-1,0));
var i,j,xz1,yz1,y1,xz2,yz2,y2,t1,t2,t3,k,v1,v2:integer;
ch:char;
a:array[1..20] of integer;
procedure priter;
begin
gotoxy(1,1);
textbackground(green);
for i:=1 to 20 do
begin
for j:=1 to 40 do
write(' ');
writeln;
end;
end;
procedure priv;
begin
gotoxy(1,1);
write('v1:',v1:3,' v2:',v2:2);
end;
procedure start;
begin
priter;
textcolor(black);
textbackground(green);
gotoxy(1,1);
write('Really? ');
ch:=readkey;
for i:=3 downto 1 do
begin
write(i);
sound(1871);
delay(500);
nosound;
delay(500);
write(#8);
end;
write('Go!!!');
sound(2500);
delay(500);
nosound;
end;
procedure GameOver(p:integer);
begin
if p=1 then begin gotoxy(1,y1);write(']*');end;
if p=2 then begin gotoxy(39,y2);write('*[');end;
textcolor(green);
textbackground(black);
gotoxy(10,10);
p:=3-p;
write('Player ',p:1,' is Win!!!');
repeat ch:=readkey;until ord(ch)=13;
textbackground(black);
ClrScr;
halt;
end;
procedure over(p:integer);
begin
if p=1 then begin dec(v1);gotoxy(1,y1);write(']*');end;
if p=2 then begin dec(v2);gotoxy(39,y2);write('*[');end;
priv;
if v1=0 then gameover(1);
if v2=0 then gameover(2);
end;
procedure go;
begin
textbackground(black);
ClrScr;
for i:=1 to 20 do a[i]:=38;
textbackground(green);
textcolor(black);
priter;
gotoxy(1,2);
y1:=1;
write(']>');
gotoxy(39,2);
write('<[');
gotoxy(1,1);
y1:=2;t1:=0;t2:=0;t3:=0;y2:=2;v1:=10;v2:=10;
priv;
while true do
begin
delay(1);
inc(t1,1);
if t1=1000 then
begin
inc(t2);
if t2=60 then begin t2:=0;inc(t3);end;
end;
if keypressed then
begin
ch:=readkey;
if (ch='i') and (y1>2) then
begin
gotoxy(1,y1);
write(' ');
dec(y1);
gotoxy(1,y1);
write(']>');
end;
if (ch='k') and (y1<20) then
begin
gotoxy(1,y1);
write(' ');
inc(y1);
gotoxy(1,y1);
write(']>');
end;
if (ch='q') then break;
if (ch='f')and(xz1=0) then
begin
xz1:=3;
yz1:=y1;
end;
{play2}
if (ch='8') and (y2>2) then
begin
gotoxy(39,y2);
write(' ');
dec(y2);
gotoxy(39,y2);
write('<[');
end;
if (ch='5') and (y2<20) then
begin
gotoxy(39,y2);
write(' ');
inc(y2);
gotoxy(39,y2);
write('<[');
end;
if (ch='0')and(xz2=0) then
begin
xz2:=37;
yz2:=y2;
end;
end;{end of keyprssed}
if (t1 mod 5=0)and(xz1<>0) then
begin
if xz1>38 then
begin
gotoxy(xz1,yz1);
write(' ');
if yz1=y2 then Over(2);
xz1:=0;
yz1:=0;
end
else
begin
gotoxy(xz1,yz1);
write(' .');
inc(xz1);
end;
end;
{play2}
if (t1 mod 5=0)and(xz2<>0) then
begin
if xz2<2 then
begin
gotoxy(xz2,yz2);
write(' ');
if yz2=y1 then Over(1);
xz2:=0;
yz2:=0;
end
else
begin
gotoxy(xz2-1,yz2);
write('. ');
dec(xz2);
end;
end;
end;{end of while}
end; {end of go}
begin
start;
go;
end.
不要想你能为世界做什么,想想你该为世界做什么!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端