Lập trình game trên pascal

... việc thiết kế, xây dựng chương trình, thao tác, quản lý, Ở thế hệ này người lập trình phải dùng ngôn ngữ máy tuyệt đối để lập trình. Khái niệm ngôn ngữ lập trình và hệ điều hành chưa được ... người vận hành, người lập trình, và người bảo trì. Ngôn ngữ lập trình Assembly và Fortran ra đời trong thời kỳ này. Với các máy tính thế hệ này để thực hiện một thao tác, lập trình viên dùng Assembly ... các tiến trình, chương trình trong quá trình điều khiển sự hoạt động của hệ thống. Khi người sử dụng cần thực hiện một chương trình hay khi một chương trình cần nạp thêm một tiến trình mới...

Dark_phoenix
Chủ tịch




Tổng số bài gửi : 390
Age : 28
Đến từ [Location] : 1 nơi nào đó trên Trái Đất
Job/hobbies : Nhìu lém
Tâm trạng :

Năng lượng : 34
Điểm thưởng : 1
Registration date : 03/03/2008

Tiêu đề: Game bằng pascal   
Tue Aug 12, 2008 10:59 am
Audition Offline bằng Pascal:
Code:

Program ve_duong_tu_dong;
uses crt,graph;
type
diem = record
t_d:byte;
x: integer;
y:integer;
end;
var
n,i,j,gd,gm,x1,x2,y1,y2,l,m:integer;
a:array[1..100] of diem;
b,a1,c,b1:array[1..100] of integer;
fv:text;
procedure linenn[x1,y1,x2,y2:integer]; { ve duong }
begin
setcolor[9];
setlinestyle[0,0,3];
settextstyle[4,0,1];
line[x1,y1,x2,y2]; moveto[x2,y2];
moverel[-5,5]; linerel[5,-5];
moverel[-5,-5];linerel[5,5];
delay[4000];
end;
procedure nhap_diem;
begin
write['nhap vao cac diem can ve[m< 23 vi file co 23 diem] m= ']; readln[m];
for i:=1 to m do
begin
write['b1[',i,']=']; readln[b1[i]];
end;
end;
Procedure mang_diem;
Begin
assign[fv,'d:\nut.txt'];
reset[fv];
readln[fv,n];
begin
j:=0;
while not[seekeof[fv]] do
begin
j:=j+1;
readln[fv,a1[j],b[j],c[j]];
a[j].t_d:=a1[j];
a[j].x:=b[j];
a[j].y:=c[j];
end;
end;
close[fv];
End;
Begin
gd:=detect;
nhap_diem;
initgraph[gd,gm,''];
If GraphResult GrOk Then
Halt[1];
setbkcolor[white];
setcolor[red];
mang_diem;
i:=1;
while i< m do
begin
j:=i+1;
linenn[a[b1[i]].x,a[b1[i]].y,a[b1[j]].x,a[b1[j]].y];
i:=j;
end;
readln;
closegraph;
End.

Caro :Code:

uses crt;
const
edge=0; us=1; them=2; none=3;
gridsize=15;
maxmoves=200;
alphabet=96;
null=' ';
type
squares=edge..none;
smallint=0..gridsize;
byte=0..255;
cardinal=0..65535;
line=array[0..9] of squares;
var
grid: array[1..gridsize,1..gridsize] of squares;
name: array[squares] of char;
icol, irow: array[1..4] of -1..1;
play: packed array[1..maxmoves] of record
rowfield, colfield: smallint;
end;
v, vals: array[1..4] of integer;
i,j,r,c: smallint;
onboard: set of smallint;
move: cardinal;
endgame: squares;
yourturn: boolean;
topvalue: integer;
response: char;

Rắn săn mồi:
Code:

program ranbo;
uses crt,dos;
type
TPoint=record
x,y:byte;
end;

ran=array[1..100] of TPoint; {tôi khai báo lai cho d? coi}

var
conran:ran;
x,y, x1,y1, l, huong :byte;
tocdo, diem :integer;
kt :char; {k0 dùng}
ranchet :boolean;
{-------------------------------------------------------}
procedure setcusor[bot,top:byte];
var
regs:registers;
begin
regs.ah:=1; regs.ch:=bot; regs.cl:=top;
intr[$10,regs];
end;
{-------------------------------------------------------}
procedure ngaunhien;
begin
x1:=random[30]+5; y1:=random[20]+2;
kt:=chr[random[25]+65];
gotoxy[x1,y1]; write[kt];
end;
{-------------------------------------------------------}
procedure vekhung;
var
j:byte;
begin
clrscr;
textcolor[white];
gotoxy[1,1];
for j:=1 to 40 do write[#177];

gotoxy[1,24];
for j:=1 to 40 do write[#177];

for j:=2 to 24 do
begin
gotoxy[1,j]; write[#177];
gotoxy[40,j];write[#177];
end;
gotoxy[8,24];
textcolor[lightred];
writeln['Nhap phim Esc de thoat'];
end;
{-------------------------------------------------------}
procedure ranchay;
var rk:char;
begin
if keypressed then {neu an co an phim thi}
begin
rk:=readkey; {b?n thi?u} {d?c xem phím nào v?a b?m}
if rk=#27 then halt[1]; {neu la esc thoat}
if rk=#0 then rk:=readkey; {neu la phim dieu khien[control key], d?c lai de lay ma}
huong:=ord[rk];
end;

case huong of
80: inc[y];
72: dec[y];
77: inc[x];
75: dec[x];
end;

if [y=1] or[y=24] or[x=40] or[x=1] then ranchet:=true;
end;
{-------------------------------------------------------}
procedure init;
var
j:byte;
begin
randomize;
textmode[co40];
tocdo:=200;
diem:=0;
vekhung;
l:=3;
x:=10;y:=10;

huong:=0; {+ nen khoi tao huong}

for j:=1 to l+1 do
begin
conran[j].x:=30+j; conran[j].y:=10;
end;

ngaunhien;
setcusor[32,3];
ranchet:=false;
end;
{-------------------------------------------------------}
procedure thuchien;
var
i:byte;
begin
init;
i:=4;
repeat
ranchay;
dec[i];
gotoxy[conran[i].x,conran[i].y];
write[' '];
conran[i].x:=x; conran[i].y:=y;
textcolor[lightred];
gotoxy[4,1];
write[' DIEM ',diem];

if [diem>0] and [ diem mod 200=0] then
begin
diem:=diem+50;
gotoxy[6,12];
textcolor[white];
textbackground[red];
writeln['KHA LAM ! = MOI BAN TIEP TUC'];
repeat until keypressed;
textbackground[0];
clrscr;
vekhung;
if tocdo>=100 then tocdo:=tocdo-50;
if diem>=400 then l:=3;
i:=l;
end;
if [x=x1] and [y=y1] then
begin
l:=l+1; ngaunhien;
diem:=diem+10;
end;
gotoxy[x1,y1];
write[kt];
textcolor[lightcyan];
gotoxy[conran[i].x,conran[i].y];
write[#219];
if i=1 then i:=l+1;
delay[tocdo];
until ranchet;
gotoxy[15,11]; write[' BAN DA THUA '];
gotoxy[5,12];
write[' Nhan phim bat ki de choi tiep '];
end;

{-------------------------------------------------------}
BEGIN
repeat
clrscr;
thuchien;
kt:=readkey;
until kt=#27;
clrscr;
END.

Dark_phoenix
Chủ tịch




Tổng số bài gửi : 390
Age : 28
Đến từ [Location] : 1 nơi nào đó trên Trái Đất
Job/hobbies : Nhìu lém
Tâm trạng :

Năng lượng : 34
Điểm thưởng : 1
Registration date : 03/03/2008

Tiêu đề: Re: Game bằng pascal   
Tue Aug 12, 2008 11:01 am
Trò bắn ô vuông:
Code:

{$G+}

const
vga:word=$a000;

type tbullet=array[0..1] of byte; {2 places for x,y coords, row and collom}
{yeah, i do records too, but this is easier for 'me' to follow}
label newgame; {been easier to 0 score, but i was doing other stuff}
var
bullet:tbullet;
x,y:integer; {bullet coords}
virscr:pointer;
score:integer;
fofs,fseg,Vaddr,px,py:word;
pbtimer,cenergy,penergy,range,cx,cy:integer;
cxd,cyd:shortint;

{ mouse routines ----------------------------------------------------------- }

function mouseinstalled:boolean; assembler; asm
xor ax,ax; int 33h; cmp ax,-1; je @skip; xor al,al; @skip: end;

function getmousex:word; assembler; asm
mov ax,3; int 33h; mov ax,cx end;

function getmousey:word; assembler; asm
mov ax,3; int 33h; mov ax,dx end;

function leftpressed:boolean; assembler; asm
mov ax,3; int 33h; and bx,1; mov ax,bx end;

function rightpressed:boolean; assembler; asm
mov ax,3; int 33h; and bx,2; mov ax,bx end;

procedure mousesensetivity[x,y:word]; assembler; asm
mov ax,1ah; mov bx,x; mov cx,y; xor dx,dx; int 33h end;

{ video related routines --------------------------------------------------- }

procedure getfont; assembler; asm
mov ax,1130h; mov bh,1; int 10h; mov fseg,es; mov fofs,bp; end;

procedure writetxt[x,y:word; txt:string; where:word; col:byte];
var i,j,k:byte;
begin
for i:=1 to length[txt] do for j:=0 to 7 do for k:=0 to 7 do
if [[mem[fseg:fofs+ord[txt[i]]*8+j] shl k] and 128] 0 then
mem[where:[y+j]*320+[i*8]+x+k]:=col;
end;

procedure Cls[where:word; col:byte];
begin
fillchar[mem[where:0],64000,col];
end;

procedure flip[src,dst:word]; assembler; asm
push ds; mov ds,[src]; xor si,si; mov es,[dst]
xor di,di; mov cx,320*200/2; rep movsw; pop ds; end;

procedure putpixel[x,y:word; c:byte ]; assembler; asm
mov es,[Vaddr]; mov ax,[y]; shl ax,6; mov di,ax; shl ax,2
add di,ax; add di,[x]; mov al,[c]; mov [es:di],al; end;

{ shit starts --------------------------------------------------------- }

procedure moveplayer;
var i:word;
begin
px:=getmousex shr 1; py:=getmousey;
if px316 then px:=316;
py:=160;
if leftpressed then begin
i:=0; {goes here, resets with ea keypress}
if [i0 then begin {y starts at 160, from where players gun is, [x]}
dec[y,4]; {4 seems to be the magic number}
if y=0 then begin {off screen?, then killem}
x:=0; y:=0; dec[penergy,4];
end;end;
if penergy=0] and [dx =0] and [dy =3] and [dx =0] and [dy =6] and [dx =0] and [dy

Chủ Đề