الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

الدرس رقم 22 لتعلم البرمجة بدون كود نستعرض فيه مثال للعبة غير رسومية تعتمد على الاحداث

مشاركة: واتساب X فيسبوك تيليجرام
#1

بسم الله الرحمن الرحيم

اليوم لدينا درس جديد نرى فيه مثال على لعبة غير رسومية Console-Mode

لقد تم بناء هذه اللعبة استنادا على نمط البرمجة الخادم الممتاز DoubleS

وذلك قبل بناء تكنولوجيا البرمجة بدون كود RPWI

وقد تم بناء تلك اللعبة البسيطة لاختبار وحدة الكود Code Unit من ناحية دعمها للبيئة التى تعتمد على الاحداث Event-Driven

اللعبة تسمى Earth-Wolf ويمكن ان يستخدمها لاعب واحد او لاعبين

والهدف من اللعبة هو ان يمر الاعب على جميع المساحة (الارض) المتاحة له ومن ثم يحوز على اعلى Score

بينما هو يحاول المرور على الارض كاملة اذا بالنيران تطلق عليه من خلال اربعة مدافع متحركة على جوانب الشاشة.

post-137500-1204866726_thumb.gif

post-137500-1204866730_thumb.gif

post-137500-1204866735_thumb.gif

post-137500-1204866740_thumb.gif

post-137500-1204866746_thumb.gif

post-137500-1204866750_thumb.gif

post-137500-1204866755_thumb.gif

ونظرا لان هذا المثال هو استعراض لمفهوم من مفاهيم نمط البرمجة الجديد - الخادم الممتاز

وكان ذلك قبل بناء بيئة البرمجة بدون كود RPWI Environment فانه تم عمل هذا المثال

من خلال كتابة الكود

وهو كما يلى

*-------------------------------------------------------------------------*
*
*  DoubleS Project (DoubleS Paradigm,DoubleS Framework & DoubleS Library)
*
*  Copyright(C) 2006-2007, Mahmoud Fayed 
*
*-------------------------------------------------------------------------*

#include "SSXHB.CH"		 && DoubleS Library Header File

SET PROCEDURE TO SSLIB.PRG  && DoubleS Library Source Code 

FUNCTION MAIN()

START DOUBLES			   && One Time At the start of Application
New Server EarthWolf Type Slave Server Eigen Value 000
Details:
		DataUnit:		   && Data Unit Not Used Here
				ATOM KILLER
						SHELL MOVE
								SUBSHELL PLACE
									 VAR  V_STEP
									 VAR  V_TIME
									 VAR  V_DIR
									 VAR  V_BOOMS
									 VAR  V_BTIME
									 VAR  V_NBTIME
				ATOM HUMAN
						SHELL MOVE
								SUBSHELL PLACE
									 VAR  SYS_KEYBOARD
									 VAR  V_X
									 VAR  V_Y
									 VAR  V_HDIR
									 VAR  V_HTIME
									 VAR  V_GOP1 
									 VAR  V_GOP2
									 VAR  V_X2
									 VAR  V_Y2
									 VAR  V_HDIR2
									 VAR  V_HTIME2
		CodeUnit:
				MAIN RESISTANCE CIRCUITS\C1\B3\MYMAIN
				Circuit C1
				MainSwitch	 On
						Branch B1
																					 Switch	 On
								Resistance KeyBuffer
								Resistance NewBoom
								Resistance MoveBoom
								Resistance MoveKiller
								Resistance CheckExit
						Branch Human1
																					Switch	 On
								Resistance MoveHuman1
								Resistance KeyHuman1
						Branch Human2
																					Switch	 On
								Resistance MoveHuman2
								Resistance KeyHuman2
						Branch B2
																					Switch	 On
								Resistance GameOver
						Branch B3
								Switch Off
								Resistance mymain
								Resistance DrawKiller
								Resistance DrawHuman
								Resistance DrawHuman2
								Resistance DrawBOOMS
		VetoUnit:		   && Veto Unit Not Used Here
End Of Server

Resistance Start()	  Address Code Unit : Circuits\c1\b1\start
Resistance KeyBuffer()  Address Code Unit : Circuits\c1\b1\KeyBuffer
Resistance NewBoom()	Address Code Unit : Circuits\c1\b1\NewBoom
Resistance MoveBoom()   Address Code Unit : Circuits\c1\b1\MoveBoom
Resistance MoveHuman1() Address Code Unit : Circuits\c1\human1\MoveHuman1
Resistance MoveHuman2() Address Code Unit : Circuits\c1\human2\MoveHuman2
Resistance MoveKiller() Address Code Unit : Circuits\c1\b1\MoveKiller
Resistance KeyHuman1()  Address Code Unit : Circuits\c1\human1\KeyHuman1
Resistance KeyHuman2()  Address Code Unit : Circuits\c1\human2\KeyHuman2
Resistance CheckExit()  Address Code Unit : Circuits\c1\b1\CheckExit

Resistance GameOver()   Address Code Unit : Circuits\c1\b2\GameOver
Resistance mymain()	 Address Code Unit : Circuits\c1\b3\mymain
Resistance drawkiller() Address Code Unit : Circuits\c1\b3\drawkiller
Resistance drawhuman()  Address Code Unit : Circuits\c1\b3\drawhuman
Resistance drawh2()	 Address Code Unit : Circuits\c1\b3\drawhuman2
Resistance drawBOOMS()  Address Code Unit : Circuits\c1\b3\drawBOOMS


Server FireOn

RETURN

Resistance NewBoom Code
IF SECONDS() - V_NBTIME >= 1
V_NBTIME = SECONDS()
Y = int(V_STEP * 2.5)
X = int(V_STEP * 8)
Y2 = int((9-V_STEP) * 2.5)
X2 = int((9-V_STEP) * 8)
AADD(V_BOOMS,{Y2,6,4})
AADD(V_BOOMS,{3,X2,3})
AADD(V_BOOMS,{21,X,2})
AADD(V_BOOMS,{Y,73,1})
ENDIF
End of Resistance

Resistance MoveBoom Code
IF SECONDS() - V_BTIME >= 0.1
V_BTIME = SECONDS()
	  call resistance circuits\c1\b3\drawBOOMS(.t.)
	  if len(v_booms) > 0
		for x = 1 to len(V_booms)
			   IF V_BOOMS[X][3] = 1 && LEFT
				  V_BOOMS[X][2] = V_BOOMS[X][2] - 1
			   ENDIF
			   IF V_BOOMS[X][3] = 2 && UP
				  V_BOOMS[X][1] = V_BOOMS[X][1] - 1
			   ENDIF
			   IF V_BOOMS[X][3] = 3 && DOWN
				  V_BOOMS[X][1] = V_BOOMS[X][1] + 1
			   ENDIF
			   IF V_BOOMS[X][3] = 4 && RIGHT
				  V_BOOMS[X][2] = V_BOOMS[X][2] + 1
			   ENDIF
		next
		for x = 1 to len(V_booms)
			IF V_BOOMS[X][2] < 6
			   ADEL(V_BOOMS,X)
			   ASIZE(V_BOOMS,LEN(V_BOOMS)-1)
			   LOOP
			ENDIF
			IF V_BOOMS[X][2] > 73
			   ADEL(V_BOOMS,X)
			   ASIZE(V_BOOMS,LEN(V_BOOMS)-1)
			   LOOP
			ENDIF
			IF V_BOOMS[X][1] < 3
			   ADEL(V_BOOMS,X)
			   ASIZE(V_BOOMS,LEN(V_BOOMS)-1)
			   LOOP
			ENDIF
			IF V_BOOMS[X][1] > 21
			   ADEL(V_BOOMS,X)
			   ASIZE(V_BOOMS,LEN(V_BOOMS)-1)
			   LOOP
			ENDIF
		NEXT
		call resistance circuits\c1\b3\drawBOOMS()
	  endif
call resistance Circuits\c1\b2\GameOver
ENDIF
End of Resistance

Resistance MoveHuman1 Code
IF SECONDS() - V_HTIME >= 0.04
V_HTIME = SECONDS()
		if v_HDIR >= 1 .AND. V_HDIR <= 4
				call resistance circuits\c1\b3\drawhuman(.t.)
		ENDIF
		IF V_HDIR = 1 && left
				v_x = v_x - 1
				IF V_X < 6
						V_X = 6
				ENDIF
		ENDIF
		IF V_HDIR = 2 && up
				v_y = v_y - 1
				IF V_Y < 3
						V_Y = 3
				ENDIF
		ENDIF
		IF V_HDIR = 3 && down
				v_y = v_y + 1
				IF V_Y > 21
						V_Y = 21
				ENDIF
		ENDIF
		IF V_HDIR = 4 && right
				v_x = v_x + 1
				IF V_X > 73
						V_X = 73
				ENDIF
		ENDIF
		if v_HDIR >= 1 .AND. V_HDIR <= 4
				call resistance circuits\c1\b3\drawhuman
		ENDIF
call resistance Circuits\c1\b2\GameOver
ENDIF
End of Resistance

Resistance MoveHuman2 Code
IF SECONDS() - V_HTIME2 >= 0.04
		V_HTIME2 = SECONDS()
		if v_HDIR2 >= 1 .AND. V_HDIR2 <= 4
				call resistance circuits\c1\b3\drawhuman2(.t.)
		ENDIF
		IF V_HDIR2 = 1 && left
				v_x2 = v_x2 - 1
				IF V_X2 < 6
						V_X2 = 6
				ENDIF
		ENDIF
		IF V_HDIR2 = 2 && up
				v_y2 = v_y2 - 1
				IF V_Y2 < 3
						V_Y2 = 3
				ENDIF
		ENDIF
		IF V_HDIR2 = 3 && down
				v_y2 = v_y2 + 1
				IF V_Y2 > 21
						V_Y2 = 21
				ENDIF
		ENDIF
		IF V_HDIR2 = 4 && right
				v_x2 = v_x2 + 1
				IF V_X2 > 73
						V_X2 = 73
				ENDIF
		ENDIF
		if v_HDIR2 >= 1 .AND. V_HDIR2 <= 4
				call resistance circuits\c1\b3\drawhuman2
		ENDIF
call resistance Circuits\c1\b2\GameOver
ENDIF
End of Resistance

Resistance MoveKiller Code
IF SECONDS() - V_TIME >= 0.2
		V_TIME = SECONDS()
		IF V_DIR = 1
				V_STEP = V_STEP + 1
		ELSE
				V_STEP = V_STEP - 1
		ENDIF
		IF V_STEP = 0
				V_STEP = 1
				V_DIR = 1
		ENDIF
		IF V_STEP = 9
				V_STEP = 8
				V_DIR = 0
		ENDIF
		set color to bg+/rb
		@0,0 CLEAR TO 24,5
		@0,0 CLEAR TO 2,79
		@22,0 CLEAR TO 24,79
		@0,74 CLEAR TO 24,79
		call resistance Circuits\c1\b3\drawkiller(V_STEP,1)
		call resistance Circuits\c1\b3\drawkiller(V_STEP,2)
		call resistance Circuits\c1\b3\drawkiller(V_STEP,3)
		call resistance Circuits\c1\b3\drawkiller(V_STEP,4)
ENDIF
End of Resistance

Resistance KeyHuman1 Code
x = SYS_KEYBOARD
		if x = 4
				V_HDIR = 4
		endif
		if x = 19
				V_HDIR = 1
		endif
		if x = 5
				V_HDIR = 2
		endif
		if x = 24
				V_HDIR = 3
		endif
End of Resistance

Resistance KeyHuman2 Code
x = SYS_KEYBOARD
		if x = ASC('D') .OR. x = ASC('d')
				V_HDIR2 = 4
		endif
		if x = ASC('A') .or. x = ASC('a')
				V_HDIR2 = 1
		endif
		if x = ASC('W')  .or. x = ASC('w') 
				V_HDIR2 = 2
		endif
		if x = ASC('X')  .or. x = ASC('x') 
				V_HDIR2 = 3
		endif
End of Resistance

Resistance KeyBuffer Code
SYS_KEYBOARD = inkey()
end of resistance

Resistance CheckExit Code
x = SYS_KEYBOARD
if x = 27
		set color to w/n
		clear
		set cursor on
		quit
endif
End Of Resistance

Resistance GameOver Code
IF .NOT. LEN(V_BOOMS) = 0
		FOR X = 1 TO LEN(V_BOOMS)
				IF V_BOOMS[X][1] = V_Y .AND. V_BOOMS[X][2] = V_X 
						SAVE SCREEN TO OLDSCR
						SET COLOR TO W/R
						CLEAR
						@12,30 SAY "Game Over Player 1 "
						sleeptime 1
						RESTORE SCREEN FROM OLDSCR
						WITH CIRCUIT C1
								WITH BRANCH HUMAN1
										SET SWITCH OFF
								END WITH BRANCH
						END WITH CIRCUIT
						V_X = 0
						V_Y = 0
						V_GOP1 = .T.
						P1 = 0
						P2 = 0
						FOR Y = 1 TO LEN(MYEARTH)
								FOR T = 1 TO LEN(MYEARTH[Y])
										IF MYEARTH[Y][T] = 1
												  P1 = P1 + 1
										ENDIF
										IF MYEARTH[Y][T] = 2
												  P2 = P2 + 1
										ENDIF
								NEXT
						NEXT
				Endif
				IF V_BOOMS[X][1] = V_Y2 .AND. V_BOOMS[X][2] = V_X2
						SAVE SCREEN TO OLDSCR
						SET COLOR TO W/R
						CLEAR
						@12,30 SAY "Game Over Player 2 "
						sleeptime 1
						WITH CIRCUIT C1
								WITH BRANCH HUMAN2
										SET SWITCH OFF
								END WITH BRANCH
						END WITH CIRCUIT
						RESTORE SCREEN FROM OLDSCR
						V_X2 = 0
						V_Y2 = 0
						V_GOP2 = .T.
						P1 = 0
						P2 = 0
						FOR Y = 1 TO LEN(MYEARTH)
								FOR T = 1 TO LEN(MYEARTH[Y])
										IF MYEARTH[Y][T] = 1
												  P1 = P1 + 1
										ENDIF
										IF MYEARTH[Y][T] = 2
												  P2 = P2 + 1
										ENDIF
								NEXT
						NEXT
				Endif
		NEXT
ENDIF
if V_GOP1 = .T. .and. V_GOP2 = .T.
		P1 = 0
		P2 = 0
		FOR X = 1 TO LEN(MYEARTH)
				FOR T = 1 TO LEN(MYEARTH[X])
						IF MYEARTH[X][T] = 1
						  P1 = P1 + 1
						ENDIF
						IF MYEARTH[X][T] = 2
						  P2 = P2 + 1
						ENDIF
				NEXT
		NEXT
set color to w/w
clear
set color to bg+/gr,gr+/gr
@ 2,0 clear to 6,79
		@3,45 say "	 (SCORE)"
		@4,30 say " PLAYER [1] "
		@4,45 say STR(P1)
		@5,30 say " PLAYER [2] "
		@5,45 say STR(P2)
set color to bg+/B,gr+/b
@ 8,0 clear to 14,79
@10,40 say " Try Again "
@12,40 say " Exit "
set color to b/B,gr+/b
@10,30 prompt ""
@12,30 prompt ""
menu to cont
if cont = 1
		V_GOP1 = .f.
		V_GOP2 = .f.
		WITH CIRCUIT C1
			  WITH BRANCH HUMAN2
					SET SWITCH ON
			  END WITH BRANCH
		END WITH CIRCUIT
		WITH CIRCUIT C1
			  WITH BRANCH HUMAN1
					SET SWITCH ON
			  END WITH BRANCH
		END WITH CIRCUIT
		release all
		call resistance circuits\c1\b3\mymain
else
		SYS_KEYBOARD = 27
		call resistance Circuits\c1\b1\CheckExit
endif
ENDIF
End Of Resistance

Resistance mymain Code
set color to w/w
clear
set color to bg+/gr,gr+/gr
@ 2,0 clear to 6,79
		@3,17 SAY "  DoubleS (Super Server) Programming Paradigm "
		@4,17 SAY "	Copyright(C) 2006-2007, Mahmoud Fayed	 "
		@5,17 SAY "		Simple Game : EarthWolf v1.0		  "
set color to bg+/B,gr+/b
@8,0 clear to 16,79
@10,30 say " One Player  "
@12,30 say " Two Players W=Up D=Right A= Left X=Down"
@14,30 say " Exit "
set color to b/B,gr+/b
@10,20 prompt ""
@12,20 prompt ""
@14,20 prompt ""
menu to mainmenu
if mainmenu = 3
		set color to w/n
		clear
		set cursor on
		quit
endif
SET COLOR TO W/B
CLEAR
SET COLOR TO BG+/RB
call resistance Circuits\c1\b3\drawkiller(5,1)
call resistance Circuits\c1\b3\drawkiller(5,2)
call resistance Circuits\c1\b3\drawkiller(5,3)
call resistance Circuits\c1\b3\drawkiller(5,4)
SET CURSOR OFF
SELECT ADDRESS KILLER:MOVE:PLACE
LOAD ACTIVE SUBSHELL FROM MEMORY
V_TIME = SECONDS()
V_STEP = 5
V_DIR  = 1
V_BOOMS = {}
V_BTIME = SECONDS()
V_NBTIME = SECONDS()
SELECT ADDRESS HUMAN:MOVE:PLACE
LOAD ACTIVE SUBSHELL FROM MEMORY
V_X = 40
V_Y = 10
V_HDIR = 0
V_HTIME = SECONDS()
V_GOP1 = .F.
if .not. mainmenu = 1
V_GOP2 = .F.
V_X2 = 39
V_Y2 = 10
V_HDIR2 = 0
V_HTIME2 = SECONDS()
Call resistance circuits\c1\b3\drawhuman2
else
		WITH CIRCUIT C1
			 WITH BRANCH HUMAN2
				  SET SWITCH OFF
			 END WITH BRANCH
		END WITH CIRCUIT
		V_GOP2 = .t.
		V_X2 = 0
		V_Y2 = 0
endif
PUBLIC MYEARTH
MYEARTH = {}
SYS_KEYBOARD = 0
Call resistance circuits\c1\b3\drawhuman
* 3 6 21 73
FOR X = 3 TO 21
AADD(MYEARTH,{0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0,0,0,0,0,0,0,0,;
			  0,0,0})
NEXT
End of Resistance

Resistance drawkiller Code
parameters step,place
local myform,myform2,myform3,myform4
set color to bg+/rb

if place = 1 .or. place = 4
step2 = 2.5 * (9-step)
step = 2.5 * step
else
step2 = 8 * (9-step)
step = 8 * step
endif


myform = {"±±   ",;
		  "±±±±³-",;
		  "±±   "}

myform2= {"±±±±±",;
		  " ±³± ",;
		  "  |  "}

myform3= {"  |  ",;
		  " ±³± ",;
		  "±±±±±"}

myform4 ={"	±±",;
		  "-³±±±±",;
		  "	±±   "}


if place = 1 && left
   @step2,0 say   myform[1]
   @step2+1,0 say myform[2]
   @step2+2,0 say myform[3]
endif

if place = 2 && up
   @0,step2   say myform2[1]
   @1,step2 say myform2[2]
   @2,step2 say myform2[3]
endif

if place = 3 && down
   @22,step   say myform3[1]
   @23,step say myform3[2]
   @24,step say myform3[3]
endif

if place = 4 && right
   @step,74 say   myform4[1]
   @step+1,74 say myform4[2]
   @step+2,74 say myform4[3]
endif

End of Resistance

Resistance drawhuman Code
parameters phide
local myform,myform2,myform3,myfrom4
set color to bg+/b
if phide = .t.
		@v_y,v_x say "±"
		if .not. v_x = 0 .and. .not. v_y = 0
		MYEARTH[V_Y-2][V_X-5] = 1
		endif

else
myform = ""
myform2 = ""
myform3 = ""
myform4 = ""
if v_hdir = 1 && left
@v_y,v_x say myform4
endif
if v_hdir = 2 && up
@v_y,v_x say myform2
endif
if v_hdir = 3 && down
@v_y,v_x say myform3
endif
if v_hdir = 4 .or. v_hdir = 0 && right
@v_y,v_x say myform
endif
endif
End of Resistance

Resistance drawh2 Code
parameters phide
local myform,myform2,myform3,myfrom4
set color to gr+/b
if phide = .t.
		if .not. v_x2 = 0 .and. .not. v_y2 = 0
		@v_y2,v_x2 say "±"
		MYEARTH[V_Y2-2][V_X2-5] = 2
		endif
else
myform = ""
myform2 = ""
myform3 = ""
myform4 = ""
if v_hdir2 = 1 .or. v_hdir2 = 0 && left
@v_y2,v_x2 say myform4
endif
if v_hdir2 = 2 && up
@v_y2,v_x2 say myform2
endif
if v_hdir2 = 3 && down
@v_y2,v_x2 say myform3
endif
if v_hdir2 = 4 && right
@v_y2,v_x2 say myform
endif
endif
End of Resistance

Resistance drawbooms Code
parameters phide
local x
set color to n/b
if phide = .t.
	  if len(v_booms) > 0
		for x = 1 to len(V_booms)
				myy = v_booms[x][1] - 2
				myx = v_booms[x][2] - 5
				if myy >= 1 .and. myx >= 1
				if MYEARTH[myy][myx] = 0
					@v_booms[x][1],v_booms[x][2] say " "
				endif
				if MYEARTH[myy][myx] = 1
					set color to bg+/b	
					@v_booms[x][1],v_booms[x][2] say "±"
				endif
				if MYEARTH[myy][myx] = 2
					set color to gr+/b
					@v_booms[x][1],v_booms[x][2] say "±"
				endif
				endif
		next
	  endif
else
	  if len(v_booms) > 0
		for x = 1 to len(V_booms)
				@v_booms[x][1],v_booms[x][2] say "غ"
		next
	  endif
endif
End of Resistance

تم تعديل هذه المشاركة بواسطة محمود سمير في 7 مارس 2008 في 08:18

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…