找回密码
 注册
Simdroid-非首页
查看: 48|回复: 1

[命令和APDL] A GAME "NAVAL BATTLE" WRITTEN IN APDL

[复制链接]
发表于 2010-10-28 11:31:05 | 显示全部楼层 |阅读模式 来自 湖北武汉
本帖最后由 clame 于 2010-10-28 12:10 编辑

//NOPR                      !Suppress printout
/PMACRO
/COM, ==========================================================
/COM,
/COM,   NAVAL BATTLE
/COM,
/COM, ==========================================================
TRUE =    1                !Logical true
FALS =    0                !Logical false
HORZ =    0                !Horizontal
VERT =    1                !Vertical
NHOR =   10                !Number of horizontal grids
NVER =   10                !Number of vertical grids
NSHP =    6                !Number of ships
NSNK =    0                !Number of ships sunk
NDES =    0                !Number of destroyers sunk
NSUB =    0                !Number of submarines sunk
NMVE =    0                !Number of moves
*DIM,SSHP,ARRAY,NSHP       !Ship sizes
SSHP(1) = 5,4,3,3,2,2
*DIM,RSHP,ARRAY,NSHP       !Real constant for each ship
RSHP(1) = 0,0,0,0,0,0
*DIM,OSHP,ARRAY,NSHP       !Orientation of each ship
OSHP(1) = 0,0,0,0,0,0
*DIM,XSHP,ARRAY,NSHP       !Horizontal starting grid
XSHP(1) = 0,0,0,0,0,0
*DIM,YSHP,ARRAY,NSHP       !Vertical starting grid
YSHP(1) = 0,0,0,0,0,0
*DIM,HSHP,ARRAY,NSHP       !Number of hits on each ship
HSHP(1) = 0,0,0,0,0,0
*DIM,GRID,ARRAY,NHOR,NVER  !Grid array
/PREP7
/TRIAD,OFF
IMMED,OFF
N,1
N,NHOR+1,NHOR
FILL,1,NHOR+1
NGEN,NVER+1,NHOR+1,1,NHOR+1,1,0,1  !NGEN, ITIME, INC, NODE1, NODE2, NINC, DX, DY, DZ, SPACE
ET,1,42
E,1,2,NHOR+3,NHOR+2
EGEN,NHOR,1,1,1,1
EGEN,NVER,NHOR+1,1,NHOR,1
KSHP = 1
*DO,I,1,999,1
RSHP(KSHP) = NINT(RAND(2,NSHP+1))
UNIQ = TRUE
*DO,J,1,KSHP-1,1
*IF,RSHP(K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SHP(KSHP),J) = 1
*ENDDO
NSEL,S,LOC,X,XSHP(KSHP)-1,XSHP(KSHP)
NSEL,R,LOC,Y,YSHP(KSHP)-1,YSHP(KSHP)+SSHP(KSHP)-1
ESLN,S,1
REAL,RSHP(KSHP)
EMODIF,ALL,REAL
ALLSEL
*ENDIF
KSHP = KSHP+1
*IF,KSHP,EQ,NSHP+1,EXIT
*ENDDO
/PNUM,TYPE,1
/NUM,1
/PLOPTS,INFO,OFF
/PLOPTS,LOGO,OFF
/WIND,1,-1,1,-1,1
/PLOPTS,WINS,OFF
EPLOT
/TSPEC,15,0.8
/TLABEL,1.05,0.94,NAVAL BATTLE
/TLABEL,1.05,0.88,by Dave Lindeman
/TLABEL,1.05,0.76,1 BATTLESHIP - 5 HITS
/TLABEL,1.05,0.70,1 CRUISER    - 4 HITS
/TLABEL,1.05,0.64,2 DESTROYERS - 3 HITS
/TLABEL,1.05,0.58,2 SUBMARINES - 2 HITS
/PSPEC,15,1,0
/POLYG,4,1.20,0.20,1.50,0.20,1.50,0.40,1.20,0.40
FCOL = NINT(RAND(1,11))
/PSPEC,FCOL,1,0
/POLYG,3,1.28,0.25,1.42,0.30,1.28,0.35
/LSPEC,13,0,2
/LINE,1.20,-0.45,1.20,0.42
/PSPEC,12,1,0
/PCIRC,1.35,-0.15,0.25
/PSPEC,15,1,0
/PCIRC,1.35,-0.15,0.20
/PSPEC,12,1,0
/PCIRC,1.35,-0.15,0.15
/PSPEC,15,1,0
/PCIRC,1.35,-0.15,0.10
/PSPEC,12,1,0
/PCIRC,1.35,-0.15,0.05
/NOER
/USER
/PNUM,REAL,1
/NUM,1
*MSG,UI
To play, simply select one or more elements at a time. %/&
Moves will not be registered until the Select elements %/&
dialog box has been closed by pressing the OK button
*GET,EMAX,ELEM,,NUM,MAX
*DIM,EPCK,ARRAY,EMAX
*DO,I,1,EMAX,1
EPCK(I) = 0
*ENDDO
DONE = FALS
*DO,I,1,999,1
ESEL,S,PICK
*GET,NELE,ELEM,,COUNT
ENUM = 0
*DO,J,1,NELE,1
ENUM = ELNEXT(ENUM)
*IF,EPCK(ENUM),EQ,1,CYCLE
EPCK(ENUM) = 1
NMVE = NMVE+1
*GET,RNUM,ELEM,ENUM,ATTR,REAL
*DO,K,1,NSHP,1
*IF,RNUM,EQ,RSHP(K),THEN
HSHP(K) = HSHP(K)+1
*IF,HSHP(K),EQ,SSHP(K),THEN
NSNK = NSNK+1
*IF    ,SSHP(K),EQ,2,THEN
NSUB = NSUB+1
/TSPEC, 0,0.8
*IF,NSUB,EQ,1,THEN
/TLABEL,1.05,0.58,2
/TSPEC,15,0.8
/TLABEL,1.05,0.58,1
*ELSE
/TLABEL,1.05,0.58,1 SUBMARINES - 2 HITS
*ENDIF
*ELSEIF,SSHP(K),EQ,3,THEN
NDES = NDES+1
/TSPEC, 0,0.8
*IF,NDES,EQ,1,THEN
/TLABEL,1.05,0.64,2
/TSPEC,15,0.8
/TLABEL,1.05,0.64,1
*ELSE
/TLABEL,1.05,0.64,1 DESTROYERS - 3 HITS
*ENDIF
*ELSEIF,SSHP(K),EQ,4,THEN
/TSPEC, 0,0.8
/TLABEL,1.05,0.70,1 CRUISER    - 4 HITS
*ELSEIF,SSHP(K),EQ,5,THEN
/TSPEC, 0,0.8
/TLABEL,1.05,0.76,1 BATTLESHIP - 5 HITS
*ENDIF
*IF,NSNK,EQ,NSHP,THEN
DONE = TRUE
*EXIT
*ENDIF
*ENDIF
*ENDIF
*ENDDO
*ENDDO
/num,0
EPLOT
/num,1
*IF,DONE,EQ,TRUE,EXIT
ALLSEL
*ENDDO
/PSPEC,15,1,0
/POLYG,4,1.22,0.22,1.48,0.22,1.48,0.38,1.22,0.38
IMMED,ON
ESEL,S,REAL,,1
*GET,NELE,ELEM,,COUNT
*GET,EMAX,ELEM,,NUM,MAX
ENUM = 0
*DO,I,1,NELE,1
ENUM = ELNEXT(ENUM)
EPCK(ENUM) = 2
*ENDDO
ECNT = 0
*DO,I,1,999,1
ENUM = NINT(RAND(0,EMAX))
ENUM = ELNEXT(ENUM)
*IF,ENUM,EQ,0,THEN
ENUM = 1
*ENDIF
*IF,EPCK(ENUM),EQ,2,THEN
EPCK(ENUM) = 0
ECNT = ECNT+1
EDELE,ENUM
*GET,EMAX,ELEM,,NUM,MAX
*ENDIF
*IF,ECNT,EQ,NELE,EXIT
*ENDDO
FINI
*MSG,UI,NMVE
You sunk my fleet in %I moves!
/WAIT,5
*MSG,UI
To play another game, enter /CLEAR, then /INPUT,BATTLE
/EOF
IT'S DESIGNED BY Dave Lindeman, AND SEE MORE DETAILS IN THE ACCESSORY, OK, HAVE FUN GUYS.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2010-10-28 14:24:56 | 显示全部楼层 来自 瑞典
Simdroid开发平台
转载请注明
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-9-20 01:22 , Processed in 0.032553 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表