Re: [問題]fortran95 棒球遊戲
大家好
小弟在多年前剛學fortran時,剛好無聊寫了這類的東西
以前很喜歡玩mvp baseball,不過mvp從2005後就沒再出了
所以寫來安慰自己一下,叫做mvp2011 XDD...還特地把30隊名單都打成txt檔
因為是那時還是初學者,現在看來應該有很多地方可以修改
如果有寫不好的地方還請見諒...
已經忘記自己寫的內容,不過記得可以打延長賽,但不能換投手XDDD
因為適用猜亂數來決定是否安打,所以常常分數很高
有一次自己玩到激烈投手戰,在延長賽中辛苦獲勝
還因此非常高興,現在想起來有夠蠢...
或許你可以參考一下
附上f90檔:
PROGRAM MVP2k11
IMPLICIT INTEGER (I-N)
IMPLICIT REAL (A-H,O-Z)
INTEGER
LEVEL,LEVELOPP,TEAM,OPPONENT,PITCH,BAT,OUT,INN,INNTEAM,BATTER,BATTEROPP
INTEGER ONBASE,SCORE,SCOREOPP
INTEGER HIT(9),HITOPP(9),HR(9),HROPP(9),SO(9),SOOPP(9),WALK(9),WALKOPP(9)
REAL ERA,ERAOPP
REAL RANTEAM(2)
CHARACTER(LEN=30) STUFF,PITCHBALL
CHARACTER(LEN=30) PLAYER(10,32),NAME(32)
OPEN(UNIT=20,FILE="GAMEBOX.txt")
OPEN(UNIT=10,FILE="ROSTER.txt",STATUS='OLD')
DO I=1,32
READ(10,*)
NAME(I),PLAYER(1,I),PLAYER(2,I),PLAYER(3,I),PLAYER(4,I),PLAYER(5,I),PLAYER(6,I),PLAYER(7,I),PLAYER(8,I),PLAYER(9,I),PLAYER(10,I)
END DO
WRITE(*,*)"=======WELCOME TO THE MVP BASEBALL 2K11======="
WRITE(*,*)"SELECT LEVEL:"
WRITE(*,*)"1:MVP/2:STAR/3:ROOKIE"
READ(*,*) LEVEL
LEVELOPP=4-LEVEL
WRITE(*,*)"SELECT HOME TEAM OR PRESS ""0"" TO SELECT BY RANDOM:"
READ(*,*) TEAM
IF(TEAM==0)THEN
CALL RANDOM_SEED()
DO I=1,2
CALL RANDOM_NUMBER(Z)
RANTEAM(I)=INT(32*Z)+1
END DO
TEAM=RANTEAM(1)
OPPONENT=RANTEAM(2)
ELSE
WRITE(*,*)"SELECT OPPONENT(AWAY):"
READ(*,*) OPPONENT
END IF
WRITE(*,*)"=============================================="
WRITE(*,"(2X,A25)") NAME(OPPONENT)
WRITE(*,"(12X,A16)") "AWAY VS HOME"
WRITE(*,"(24X,A25)") NAME(TEAM)
WRITE(*,*)"=============================================="
DO INN=1,30
WRITE(*,*)"=============================================="
WRITE(*,*) INN,"th INNING TOP"
WRITE(*,*)"=============================================="
ONBASE=0
OUT=0
2 CALL RANDOM_SEED()
CALL RANDOM_NUMBER(R)
PITCH=INT(10*R)
DO WHILE(OUT<3)
WRITE(*,"(2X,3(A12))") PLAYER(MOD(BATTEROPP,9)+1,OPPONENT),"VS
",PLAYER(10,TEAM)
BATTEROPP=BATTEROPP+1
READ(*,*) BAT
CALL PITCHWHAT(BAT,PITCHBALL)
IF(PITCH==BAT)THEN
WRITE(*,"(11X,A10)")"HOMERUN!!!"
WRITE(*,"(25X,A18)") PITCHBALL
CALL HRSHOW(ONBASE,SCOREOPP)
HROPP(MOD(BATTEROPP,9)+1)=HROPP(MOD(BATTEROPP,9)+1)+1
WRITE(*,*) SCOREOPP," :",SCORE
ONBASE=0
GOTO 2
ELSE IF(PITCH-LEVELOPP+1<=BAT.AND.BAT<=PITCH+LEVELOPP)THEN
WRITE(*,"(11X,A4)") "HIT!"
WRITE(*,"(25X,A18)") PITCHBALL
HITOPP(MOD(BATTEROPP,9)+1)=HITOPP(MOD(BATTEROPP,9)+1)+1
ONBASE=ONBASE+1
IF(ONBASE>=4)THEN
CALL COUNTSCORE(ONBASE,SCOREOPP)
WRITE(*,*) SCOREOPP," :",SCORE
END IF
GOTO 2
ELSE IF(PITCH-LEVELOPP-2==BAT.OR.BAT>=9+LEVELOPP)THEN
WRITE(*,"(11X,A5)") "WALK!"
WALKOPP(MOD(BATTEROPP,9)+1)=WALKOPP(MOD(BATTEROPP,9)+1)+1
ONBASE=ONBASE+1
IF(ONBASE>=4)THEN
CALL COUNTSCORE(ONBASE,SCOREOPP)
WRITE(*,*) SCOREOPP," :",SCORE
END IF
GOTO 2
ELSE IF(PITCH-LEVELOPP==BAT)THEN
WRITE(*,"(11X,A12)") "STRIKEOUT!!!"
WRITE(*,*) OUT+1,"OUT"
WRITE(*,"(25X,A18)") PITCHBALL
SOOPP(MOD(BATTEROPP,9)+1)=SOOPP(MOD(BATTEROPP,9)+1)+1
OUT=OUT+1
GOTO 2
ELSE
WRITE(*,*) OUT+1,"OUT"
WRITE(*,"(25X,A18)") PITCHBALL
OUT=OUT+1
GOTO 2
END IF
END DO
WRITE(*,*) SCOREOPP," :",SCORE
IF(INN>=9.AND.SCORE>SCOREOPP)THEN
GOTO 3
END IF
INNTEAM=INNTEAM+1
WRITE(*,*)"=============================================="
WRITE(*,*) INN,"th INNING BOTTOM"
WRITE(*,*)"=============================================="
ONBASE=0
OUT=0
1 CALL RANDOM_SEED()
CALL RANDOM_NUMBER(R)
PITCH=INT(10*R)
DO WHILE(OUT<3)
IF(INN>=9.AND.SCORE>SCOREOPP)THEN
GOTO 3
END IF
WRITE(*,"(2X,3(A12))") PLAYER(MOD(BATTER,9)+1,TEAM),"VS
",PLAYER(10,OPPONENT)
BATTER=BATTER+1
READ(*,*) BAT
CALL KINDOFBALL(STUFF)
IF(PITCH==BAT)THEN
WRITE(*,"(11X,A10)")"HOMERUN!!!"
WRITE(*,"(25X,A18)") STUFF
CALL HRSHOW(ONBASE,SCORE)
HR(MOD(BATTER,9)+1)=HR(MOD(BATTER,9)+1)+1
WRITE(*,*) SCOREOPP," :",SCORE
ONBASE=0
GOTO 1
ELSE IF(PITCH-LEVEL+1<=BAT.AND.BAT<=PITCH+LEVEL)THEN
WRITE(*,"(11X,A4)") "HIT!"
WRITE(*,"(25X,A18)") STUFF
HIT(MOD(BATTER,9)+1)=HIT(MOD(BATTER,9)+1)+1
ONBASE=ONBASE+1
IF(ONBASE>=4)THEN
CALL COUNTSCORE(ONBASE,SCORE)
WRITE(*,*) SCOREOPP," :",SCORE
END IF
GOTO 1
ELSE IF(PITCH-LEVEL-3==BAT)THEN
WRITE(*,"(11X,A5)") "WALK!"
WRITE(*,"(25X,A18)") STUFF
WALK(MOD(BATTER,9)+1)=WALK(MOD(BATTER,9)+1)+1
ONBASE=ONBASE+1
IF(ONBASE>=4)THEN
CALL COUNTSCORE(ONBASE,SCORE)
WRITE(*,*) SCOREOPP," :",SCORE
END IF
GOTO 1
ELSE IF(PITCH-LEVEL==BAT.OR.BAT>=9+LEVEL)THEN
WRITE(*,"(11X,A12)") "STRIKEOUT!!!"
WRITE(*,*) OUT+1,"OUT"
WRITE(*,"(25X,A18)") STUFF
SO(MOD(BATTER,9)+1)=SO(MOD(BATTER,9)+1)+1
OUT=OUT+1
GOTO 1
ELSE
WRITE(*,*) OUT+1,"OUT"
WRITE(*,"(25X,A18)") STUFF
OUT=OUT+1
GOTO 1
END IF
END DO
WRITE(*,*) SCOREOPP," :",SCORE
IF(INN>=9.AND.SCORE/=SCOREOPP)THEN
GOTO 3
END IF
END DO
3 WRITE(*,*)"GAME SET!"
IF(SCORE>SCOREOPP)THEN
WRITE(*,"(2X,2(A25))") NAME(TEAM),"WIN! "
ELSE
WRITE(*,"(2X,2(A25))") NAME(OPPONENT),"WIN! "
END IF
ERA=9.*SCOREOPP/INNTEAM
ERAOPP=9.*SCORE/INN
WRITE(20,"(2(A23))") NAME(OPPONENT),NAME(TEAM)
WRITE(20,*) SCOREOPP," -",SCORE
WRITE(20,*)"======================================"
WRITE(20,"(2X,A20)") PLAYER(10,OPPONENT)
WRITE(20,*)"======================================"
WRITE(20,"(7(8X,A3))") "IP","H","ER","SO","BB","HR","ERA"
WRITE(20,"(7(3X,G9.4))")
INN,SUM(HIT)+SUM(HR),SCORE,SUM(SO),SUM(WALK),SUM(HR),ERAOPP
WRITE(20,*)"=========================================="
DO I=1,9
IF(MAXVAL(HROPP)>0.AND.MAXVAL(HROPP)==HROPP(I))THEN
WRITE(20,*) PLAYER(I,OPPONENT),"HR",HROPP(I)
END IF
END DO
DO I=1,9
IF(MAXVAL(HITOPP+HROPP)>0.AND.MAXVAL(HITOPP+HROPP)==HITOPP(I)+HROPP(I))THEN
WRITE(20,*) PLAYER(I,OPPONENT),"H",HITOPP(I)+HROPP(I)
END IF
END DO
WRITE(20,*)"======================================"
WRITE(20,"(2X,A20)") PLAYER(10,TEAM)
WRITE(20,*)"======================================"
WRITE(20,"(7(8X,A3))") "IP","H","ER","SO","BB","HR","ERA"
WRITE(20,"(7(3X,G9.4))")
INNTEAM,SUM(HITOPP)+SUM(HROPP),SCOREOPP,SUM(SOOPP),SUM(WALKOPP),SUM(HROPP),ERA
WRITE(20,*)"======================================"
DO I=1,9
IF(MAXVAL(HR)>0.AND.MAXVAL(HR)==HR(I))THEN
WRITE(20,*) PLAYER(I,TEAM),"HR",HR(I)
END IF
END DO
DO I=1,9
IF(MAXVAL(HIT+HR)>0.AND.MAXVAL(HIT+HR)==HIT(I)+HR(I))THEN
WRITE(20,*) PLAYER(I,TEAM),"H",HIT(I)+HR(I)
END IF
END DO
STOP
END
!====================================================================!
SUBROUTINE KINDOFBALL(STUFF)
IMPLICIT INTEGER (I-N)
IMPLICIT REAL (A-H,O-Z)
CHARACTER(LEN=30) STUFF
CALL RANDOM_SEED()
CALL RANDOM_NUMBER(Q)
I=INT(10*Q)+1
SELECT CASE(I)
CASE(1)
STUFF="FASTBALL 100mph!"
CASE(2)
STUFF="FASTBALL 97mph"
CASE(3)
STUFF="FASTBALL 95mph"
CASE(4)
STUFF="CUTTER 93mph"
CASE(5)
STUFF="SLIDER 88mph"
CASE(6)
STUFF="CURVE 75mph"
CASE(7)
STUFF="CHANGEUP 80mph"
CASE(8)
STUFF="SLIDER 85mph"
CASE(9)
STUFF="BUTTERFLY 64mph"
CASE(10)
STUFF="SPLITTER 90mph"
END SELECT
RETURN
END
!====================================================================!
SUBROUTINE PITCHWHAT(M,PITCHBALL)
IMPLICIT INTEGER (I-N)
IMPLICIT REAL (A-H,O-Z)
CHARACTER(LEN=30) PITCHBALL
I=M+1
SELECT CASE(I)
CASE(1)
PITCHBALL="FASTBALL 100mph!"
CASE(2)
PITCHBALL="FASTBALL 97mph"
CASE(3)
PITCHBALL="FASTBALL 95mph"
CASE(4)
PITCHBALL="CUTTER 93mph"
CASE(5)
PITCHBALL="SLIDER 88mph"
CASE(6)
PITCHBALL="SLIDER 85mph"
CASE(7)
PITCHBALL="CURVE 75mph"
CASE(8)
PITCHBALL="CHANGEUP 80mph"
CASE(9)
PITCHBALL="SPLITTER 90mph"
CASE(10)
PITCHBALL="BUTTERFLY 64mph"
END SELECT
RETURN
END
!====================================================================!
SUBROUTINE COUNTSCORE(ONBASE,SCORE)
IMPLICIT INTEGER (I-N)
IMPLICIT REAL (A-H,O-Z)
INTEGER SCORE,ONBASE
IF(ONBASE>=4)THEN
SCORE=SCORE+1
END IF
RETURN
END
!====================================================================!
SUBROUTINE HRSHOW(ONBASE,SCORE)
IMPLICIT INTEGER (I-N)
IMPLICIT REAL (A-H,O-Z)
INTEGER SCORE,ONBASE
IF(ONBASE<=3)THEN
SCORE=SCORE+ONBASE+1
ELSE
SCORE=SCORE+4
END IF
RETURN
END
!====================================================================!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.207.118
※ 文章網址: https://www.ptt.cc/bbs/Fortran/M.1464159048.A.148.html
推
05/27 12:18, , 1F
05/27 12:18, 1F
推
06/01 11:31, , 2F
06/01 11:31, 2F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章