เกมนี้เป็นเกมแรก ที่ผมทำสำเร็จครับ ความจริงเกมมีอยู่หลายชนิด แต่เกมที่ผมอยากทำเป็นก็เป็นเกมพวก action หรือ shooting ทำไม่สำเร็จมาหลายครั้งแล้ว ตอนแรกนึกภาพไม่ออกว่าจะ บังคับยานขยับได้ยังไง เพราะ ต้องให้ยานฝ่ายตรงข้ามเคลื่อนไหวไปพร้อมๆ กันด้วย ใครคิดว่าเกมนี้มันส์มากก็เข้าใจผิด ล่ะครับ +_+ แต่หลักการทำงานของเกมนี้ ใน procedrue สองอันแรก เป็นภาษา assembly ระวังนิดนึงครับ ผม ไปลอกมาจาก swag team ผมเขียนไม่เป็นหรอกครับ ภาษา assembly ทำอะไรได้มากกว่า pascal แต่ก็เขียนยากและ ต้องใช้ความระมัดระวังในการแก้ไข code เพราะอาจทำให้เครื่องมีปัญหาได้ Code นี้ผม compile โดย turbo pascal ครับ สำหรับผู้ที่ใช้ VP 2.1 ( virtual pascal )ให้ใช้ code อันที่อยู่ด้านล่าง เนื่องจาก compiler ทั้งสองมีคำสั่งบางอันไม่ตรงกัน และในการเล่นเกมนี้ควรจะเล่นใน mode fullscreen ครับ ถ้าคุณใช้ compiler อื่นๆ นอกเหนือจากนี้ ให้ใช้ code สำหรับ turbo pascal โดยลบ โพรซีเจอร์ hidecursor และ showcursor ออก แต่หาก ยัง compile ไม่ผ่านอีก ก็ให้ทำการลบ โพรซีเจอร์เกี่ยวกับเวลาออกให้หมดครับ ถ้าคุณไม่มั่นใจว่า code นี้จะอันตรายต่อคอมฯ ของคุณหรือไม่ ให้ลบ โพรซีเจอร์ที่เขียนด้วย assembly ออกไปก็ได้ครับ คำสั่งนี้เป็นเพียงคำสั่งให้ซ่อนและแสดง cursor เท่านั้น ตอนที่คุณมีเวลาว่างๆ ก็ลองเอาไปแก้เล่นสิครับ ต่อไปเมืองไทย อาจจะมีเกมโปรแกรมเมอร์มืออาชีพ เกิดขึ้นมาอีกคนก็ได้นะ /(+_+) |
Code สำหรับ Turbo pascal [download] [ คำอธิบาย คำสั่ง ] |
Uses Crt, Dos; Var { var for game} C : Char; yanX , yanY , ameX , ameY , gunY , gunX : byte; ameDir : ShortInt; mscore : Word; yboo, gboo, gstart : Boolean; { var for time} h1,m1,s1,hund1 , h2,m2,s2,hund2 : Word; mboo : Boolean; Const yann =char(5 ); amee =char(2 ); gunn =char(94); blakk=char(0 ); { assembly code form swag support team } Procedure HideCursor; Assembler; Asm MOV ax,$0100 MOV cx,$2607 INT $10 end; Procedure ShowCursor; Assembler; Asm MOV ax,$0100 MOV cx,$0506 INT $10 end; {++++++++++ TIME +++++++++++} Procedure TimeGameStart; begin if mboo=true then begin Gettime(h1,m1,s1,hund1); mboo:=false; end; end; Procedure DoWhenAtLimit; begin Repeat mboo:=true; Gotoxy (12,21); Write(' Press `Q` to Exit or Press `C` to Continue'); c:=Readkey; if (c='Q') or (c='q') then Halt; Until (c='C') or (c='c'); Gotoxy (12,21); Write( ' ' ); end; Procedure Time_Con_Or_Exit( MyTimeLimit:byte ); begin if (ameX=39) or (ameX=40) then begin Gettime(h2,m2,s2,hund2); if m2>m1 then if m2-m1>=MyTimeLimit then begin doWhenAtLimit; end; if h1<>h2 then if m2>=1 then begin doWhenAtLimit; end; end; end; {++++++++++ Score +++++++++++} Procedure writeScore; begin mscore:=mscore+100; Gotoxy (55,22); Write( ' ' ); Gotoxy (55,22); Write( 'score : ' ,mscore); end; {+++++++ Game-Simbol ++++++++} Procedure Yan; begin Write( yann); end; Procedure Ame; begin Write( amee); end; Procedure Gun; begin Write( gunn); end; Procedure Blank; begin Write( blakk); end; Procedure iline; var myi : byte; begin for myi :=1 to 24 do BEGIN Gotoxy (80,myi); Write( 'x' ); Gotoxy (1 ,myi); Write( 'x' ); END; end; {+++++++++ Game-Run ++++++++++} Procedure YanStart; var i : byte; begin For i:=1 To 3 Do begin Gotoxy ( 40, 16); TextColor(10+i); yan; Delay (350); end; Gotoxy ( 40, 16); TextColor(7); yan; end; { write yan color and Gotoxy=40,16} Procedure ameRan; begin Randomize; ameX:=Random( 76)+3; ameY:=Random( 8)+5; ameDir:=Random( 2); if (ameDir=0) then ameDir:=-1 else if (ameDir=1) then ameDir:=1; end; Procedure runAme; begin if gboo=false then Delay (50); if ameX=yanX then begin Gotoxy ( ameX, ameY); blank; ameran; end; if ameX=79 then ameDir:=-1 else if ameX=2 then ameDir:=1; ameX:= ameX+ameDir; Gotoxy ( ameX, ameY); ame; Gotoxy ( ameX-ameDir, ameY); blank; Delay (50); end; { run Ame } Procedure RunGun; begin IF gboo=true THEN BEGIN if gstart=true then begin { define GunX=YanX and define GunY=YanY-2 At First} gunX:=yanX; gunY:=yanY-2; gstart:=false; end; Dec (gunY); Gotoxy (gunX, gunY ); gun; Gotoxy (gunX, gunY+1); blank; Delay (50); if (gunY<=ameY) then begin Gotoxy ( gunX, gunY); blank; gboo:=false; end; if (gunY=ameY) and (gunX=ameX) then begin Gotoxy ( ameX,ameY); TextColor (11); Write ( '*' ); { write Boom} TextColor ( 7); Delay (75); writeScore; end; END; end; Procedure RunYan; begin IF yboo=true THEN BEGIN if (c=#75) And (yanX>=4 ) then BEGIN { when press arrow left AND yanX more than 2} yanX := yanX-2; Gotoxy ( yanX, yanY); yan; Gotoxy ( yanX+2, yanY); blank; Delay ( 25); END else if (c=#77) And (yanX<=77) then BEGIN { when press arrow right AND yanX less than 79} yanX := yanX+2; Gotoxy ( yanX, yanY); yan; Gotoxy ( yanX-2, yanY); blank; Delay ( 25); END; yboo:=false; END; end; { RunYan} begin Clrscr; HideCursor; yanstart; ameran; iline; yanX := 40; yanY := 16; gstart:=false; gboo:=false; yboo:=false; mboo:=true; {start} while c<>#27 do Begin c:=readkey; IF c=#0 THEN BEGIN c:=readkey; if (c=#75) xor (c=#77) then begin yboo :=true; end else if c=#72 then begin gboo :=true; gstart :=true; end; REPEAT rungun; runame; runyan; timeGameStart; time_Con_Or_Exit(3); UNTIL KeyPressed; END; End; ShowCursor;{end} end. |
Code สำหรับ Compiler VP 2.1 [downoad] |