怎么用freepascal编游戏

当然可以了。编程序写到手腕酸到时候敲一个游戏进去是最好不过到啦。

用pascal有一点点麻烦,但是也是可以轻松实现的。不过用delphi更方便。

用pascal可以用面向单元的程序,但是不怎么好看。给你一点样本代码吧。

俄罗斯方块:

USESCrt;

CONST

Change:Array[0..6,0..3,0..7]OfByte=(((0,1,1,1,2,1,3,1),(1,0,1,1,1,2,1,3),(0,1,1,1,2,1,3,1),(1,0,1,1,1,2,1,3)),

((1,0,0,1,1,1,2,1),(1,0,1,1,1,2,2,1),(0,1,1,1,2,1,1,2),(1,0,0,1,1,1,1,2)),

((1,0,2,0,1,1,2,1),(1,0,2,0,1,1,2,1),(1,0,2,0,1,1,2,1),(1,0,2,0,1,1,2,1)),

((1,0,2,0,0,1,1,1),(0,0,0,1,1,1,1,2),(1,0,2,0,0,1,1,1),(0,0,0,1,1,1,1,2)),

((0,0,1,0,1,1,2,1),(1,0,0,1,1,1,0,2),(0,0,1,0,1,1,2,1),(1,0,0,1,1,1,0,2)),

((1,0,2,0,1,1,1,2),(0,0,0,1,1,1,2,1),(1,0,0,2,1,1,1,2),(2,2,0,1,1,1,2,1)),

((0,0,1,0,1,1,1,2),(2,0,0,1,1,1,2,1),(2,2,1,0,1,1,1,2),(0,2,0,1,1,1,2,1)));

VAR

Board:Array[0..3,0..11,1..25]OfByte;

Players,N,Nowx,Nowy,Kind,Trans,Speed:Byte;

Time,Score:Word;

Now:Array[0..7]OfByte;

PROCEDUREFurbish;

VARB,C:Byte;

Begin

ForC:=24Downto2DoBegin

Gotoxy(1,C);

ForB:=1To10Do

IfBoard[0,B,C]=0ThenWrite('')

ElseWrite('圹');

End;

End;

PROCEDUREClear;

VarA,B,C:Byte;D:Boolean;

Begin

ForA:=24Downto1Do

Begin

D:=True;

ForB:=1To10Do

IfBoard[0,B,A]=0ThenD:=False;

IfD=TrueThen

Begin

Score:=Score+10;Gotoxy(1,1);Write(Score:5,'0');

ForC:=ADownto2Do

ForB:=1To10Do

Board[0,B,C]:=Board[0,B,C-1];

A:=A+1;

End;

End;

Furbish;

End;

FUNCTIONCanmove(X,Y:Byte):Boolean;

BEGIN

Canmove:=True;

IfBoard[0,X+Now[0],Y+Now[1]]>0ThenCanmove:=False;

IfBoard[0,X+Now[2],Y+Now[3]]>0ThenCanmove:=False;

IfBoard[0,X+Now[4],Y+Now[5]]>0ThenCanmove:=False;

IfBoard[0,X+Now[6],Y+Now[7]]>0ThenCanmove:=False;

End;

PROCEDUREClean;

Begin

Gotoxy((Nowx+Now[0])*2-1,Nowy+Now[1]);Write('');

Gotoxy((Nowx+Now[2])*2-1,Nowy+Now[3]);Write('');

Gotoxy((Nowx+Now[4])*2-1,Nowy+Now[5]);Write('');

Gotoxy((Nowx+Now[6])*2-1,Nowy+Now[7]);Write('');

End;

PROCEDUREShow;

Begin

Gotoxy((Nowx+Now[0])*2-1,Nowy+Now[1]);Write('圹');

Gotoxy((Nowx+Now[2])*2-1,Nowy+Now[3]);Write('圹');

Gotoxy((Nowx+Now[4])*2-1,Nowy+Now[5]);Write('圹');

Gotoxy((Nowx+Now[6])*2-1,Nowy+Now[7]);Write('圹');

End;

BEGIN

Fillchar(Board,Sizeof(Board),0);

Randomize;Score:=0;

ForN:=1To24Do

Board[0,0,N]:=1;

ForN:=1To24Do

Board[0,11,N]:=1;

ForN:=1To10Do

Board[0,N,25]:=1;

Window(31,2,50,25);Textcolor(White);Textbackground(Blue);

Clrscr;Window(31,2,51,25);

Speed:=1;

Kind:=Random(7);Trans:=Random(4);Nowx:=4;Nowy:=1;

ForN:=0To7Do

Now[N]:=Change[Kind,Trans,N];

WhileCanmove(Nowx,Nowy)Do

Begin

Repeat

Clean;Nowy:=Nowy+1;Show;

Repeat

IfKeypressedThen

CaseUpcase(Readkey)Of

#0:CaseReadkeyOf

#75:IfCanmove(Nowx-1,Nowy)ThenBeginClean;Nowx:=Nowx-1;Show;End;

#77:IfCanmove(Nowx+1,Nowy)ThenBeginClean;Nowx:=Nowx+1;Show;End;

#80:BeginClean;Repeat

IfCanmove(Nowx,Nowy+1)ThenNowy:=Nowy+1;

UntilNot(Canmove(Nowx,Nowy+1));Show;End;

#61:BeginGotoxy(9,12);Write('Pause');RepeatDelay(1000);UntilKeypressed;Furbish;End;

End;

#27:Exit;

'',#13:Begin

Clean;Trans:=Trans+1;

IfTrans=4ThenTrans:=0;

ForN:=0To7Do

Now[N]:=Change[Kind,Trans,N];

IfNot(Canmove(Nowx,Nowy))ThenBeginTrans:=Trans-1;ForN:=0To7Do

Now[N]:=Change[Kind,Trans,N];Show;End

ElseShow;

End;

End;

UntilNot(Keypressed);

Delay((10-Speed)*50);

UntilNot(Canmove(Nowx,Nowy+1));

Score:=Score+1;Gotoxy(1,1);Write(Score:5,'0');Speed:=(ScoreDiv300)+1;

Board[0,Nowx+Now[0],Nowy+Now[1]]:=1;

Board[0,Nowx+Now[2],Nowy+Now[3]]:=1;

Board[0,Nowx+Now[4],Nowy+Now[5]]:=1;

Board[0,Nowx+Now[6],Nowy+Now[7]]:=1;

Clear;

Kind:=Random(7);Trans:=Random(4);Nowx:=4;Nowy:=1;

ForN:=0To7Do

Now[N]:=Change[Kind,Trans,N];

End;

Gotoxy(7,12);Write('GAMEOVER');Readln;

END.

免责声明:本站发布的游戏攻略(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场。
如果本文侵犯了您的权益,请联系站长邮箱进行举报反馈,一经查实,我们将在第一时间处理,感谢您对本站的关注!