Initial commit

This commit is contained in:
Gregory Campbell
2021-07-08 21:22:36 -04:00
commit 0dce6b1259
3 changed files with 376 additions and 0 deletions
Executable
+152
View File
@@ -0,0 +1,152 @@
C GAME OF HANGMAN BY DAVE AHL, DIGITAL
C BASED ON A BASIC PROGRAM WRITTEN BY KEN AUPPERLE
C HALF HALLOW HILLS H.S. DIX HILLS NY
C CONVERTED TO FORTRAN 77 BY M.WIRTH, APRIL 2012
C
PROGRAM HANGMAN
CHARACTER P(12,12)
CHARACTER D(20), N(26), A*20, GUESS, B*20, ANS
INTEGER U(50)
INTEGER Q, M, I, J, W, T1, R, L
REAL RND
CHARACTER*20 DICT(50)
DATA DICT/'gum','sin','for','cry','lug','bye','fly','ugly',
M 'each','from','work','talk','with','self',
M 'pizza','thing','feign','fiend','elbow','fault',
M 'dirty','budget','spirit','quaint','maiden',
M 'escort','pickax','example','tension','quinine',
M 'kidney','replica','sleeper','triangle',
M 'kangaroo','mahogany','sergeant','sequence',
M 'moustache','dangerous','scientist','different',
M 'quiescent','magistrate','erroneously',
M 'loudspeaker','phytotoxic','matrimonial',
M 'parasympathomimetic','thigmotropism'/
WRITE (*,*) "THE GAME OF HANGMAN"
10 DO 16 I = 1,12
DO 15 J = 1,12
P(I,J) = " "
15 CONTINUE
16 CONTINUE
DO 18 I = 1,20
D(I) = "-"
18 CONTINUE
DO 20 I = 1,26
N(I) = " "
20 CONTINUE
DO 25 I = 1,50
U(I) = 0
25 CONTINUE
DO 30 I = 1,12
P(I,1) = "X"
30 CONTINUE
DO 40 J = 1,7
P(1,J) = "X"
40 CONTINUE
P(2,7) = "X"
C=1
W=50
M=0
IF (C .LT. W) GO TO 100
WRITE (*,*) "You did all the words"; GO TO 999
100 RND=RAND()
Q=CEILING(RND*50)
IF (U(Q) .EQ. 1) THEN
GO TO 100
ELSE
U(Q) = 1; C=C+1; T1=0
END IF
A = DICT(Q)
L = LEN_TRIM(A)
WRITE (*,*) D(1:L)
170 WRITE (*,*) "Here are the letters you used: "
DO 180 I = 1,26
IF (N(I) .EQ. ' ') GO TO 200
WRITE (*,'(AA$)') N(I),","
180 CONTINUE
200 WRITE (*,*) " "
WRITE (*,*) "What is your guess? "; R=0
READ (*,*) GUESS
DO 210 I = 1,26
IF (N(I) .EQ. " ") GO TO 250
IF (N(I) .EQ. GUESS) THEN
WRITE (*,*) "You guessed that letter before";
GO TO 170
END IF
210 CONTINUE
WRITE (*,*) "Invalid character"; GO TO 170
250 N(I)=GUESS; T1=T1+1
DO 260 I = 1,L
IF (A(I:I) .EQ. GUESS) THEN
D(I) = GUESS; R=R+1
END IF
260 CONTINUE
270 IF (R .EQ. 0) THEN
GO TO 290
ELSE
GO TO 300
END IF
290 M=M+1; GO TO 400
300 DO 305 I = 1,L
IF (D(I) .EQ. "-") GO TO 320
305 CONTINUE
GO TO 390
320 WRITE (*,*) D(1:L)
330 WRITE (*,*) "What is your guess for the word? "
READ (*,*) B
340 IF (A .EQ. B) GO TO 360
WRITE (*,*) "Wrong. Try another letter"; GO TO 170
360 WRITE (*,*) "Right! It took you ",T1," guesses"
370 WRITE (*,*) "Do you want another word? (Y/N) "
READ (*,*) ANS
IF (ANS .EQ. "Y") GO TO 10
WRITE (*,*) "It's been fun! Bye for now."; GO TO 999
390 WRITE (*,*) "You found the word."; GO TO 370
400 WRITE (*,*) "Sorry, that letter isn't in the word."
410 GO TO (415,420,425,430,435,440,445,450,455,460), M
415 WRITE (*,*) "First we draw a head."; GO TO 470
420 WRITE (*,*) "Now we draw a body."; GO TO 470
425 WRITE (*,*) "Next we draw an arm."; GO TO 470
430 WRITE (*,*) "This time it's the other arm."; GO TO 470
435 WRITE (*,*) "Now, let's draw the right leg."; GO TO 470
440 WRITE (*,*) "This time we draw the left leg."; GO TO 470
445 WRITE (*,*) "Now we put up a hand."; GO TO 470
450 WRITE (*,*) "Next the other hand."; GO TO 470
455 WRITE (*,*) "Now we draw one foot."; GO TO 470
460 WRITE (*,*) "Here's the other foot -- You're hung!!."
470 GO TO (480,490,500,510,520,530,540,550,560,570), M
480 P(3,6) = "-"; P(3,7) = "-"; P(3,8) = "-"; P(4,5) = "(";
P(4,6) = ".";
481 P(4,8) = "."; P(4,9) = ")"; P(5,6) = "-"; P(5,7) = "-";
P(5,8) = "-"; GO TO 580
490 DO 495 I = 6,9
P(I,7) = "X"
495 CONTINUE
GO TO 580
500 DO 505 I = 4,7
P(I,I-1) = "\"
505 CONTINUE
GO TO 580
510 P(4,11) = "/"; P(5,10) = "/"; P(6,9) = "/"; P(7,8) = "/";
GO TO 580
520 P(10,6) = "/"; P(11,5) = "/"; GO TO 580
530 P(10,8) = "\"; P(11,9) = "\"; GO TO 580
540 P(3,11) = "\"; GO TO 580
550 P(3,3) = "/"; GO TO 580
560 P(12,10) = "\"; P(12,11) = "-"; GO TO 580
570 P(12,3) = "-"; P(12,4) = "/"
580 DO 585 I = 1,12
WRITE (*,*) (P(I,J),J=1,12)
585 CONTINUE
590 IF (M .EQ. 10) THEN
GO TO 600
ELSE
GO TO 170
END IF
600 WRITE (*,*) "Sorry, you loose. The word was ", A
610 WRITE (*,*) "You missed that one."; GO TO 370
999 WRITE (*,*) "Ending..."
END
Executable
+216
View File
@@ -0,0 +1,216 @@
! Game of hangman by dave ahl, digital
! based on a basic program written by Ken Aupperle
! Half Hallow Hills H.H. Dix Hills NY
! Converted to fortran 77 by M.Wirth, April 2012
! Converted again to fortran 95 by Gregory Campbell, February 2016
!
program hangman
implicit none
character :: p(12,12)
character :: d(20), n(26), a*20, guess, b*20, ans
integer :: u(50)
integer :: q, m, i, j, w, t1, r, l, c, win = 0, dead = 0, wrong = 0
character(len=20), dimension(50) :: dict = [character(len=20) ::'gum','sin','for','cry','lug','bye','fly',&
& 'ugly','each','from','work','talk','with','self',&
& 'pizza','thing','feign','fiend','elbow','fault',&
& 'dirty','budget','spirit','quaint','maiden',&
& 'escort','pickax','example','tension','quinine',&
& 'kidney','replica','sleeper','triangle',&
& 'kangaroo','mahogany','sergeant','sequence',&
& 'moustache','dangerous','scientist','different',&
& 'quiescent','magistrate','erroneously',&
& 'loudspeaker','phytotoxic','matrimonial',&
& 'parasympathomimetic','thigmotropism']
write (*,*) "the game of hangman"
do
do i = 1,12
do j = 1,12
p(i,j) = " "
end do
end do
do i = 1,20
d(i) = "-"
end do
do i = 1,26
n(i) = " "
end do
do i = 1,50
u(i) = 0
end do
do i = 1,12
p(i,1) = "x"
end do
do j = 1,7
p(1,j) = "x"
end do
p(2,7) = "x"
c=1
w=50
m=0
if (c >= w) then
write (*,*) "you did all the words"; exit
end if
u(q) = 1; c=c+1; t1=0
do while ((u(q) - 1) == 0)
q = random(q)
end do
a = dict(q)
l = len_trim(a)
write (*,*) d(1:l)
do while (win == 0)
wrong = 0
write (*,*) "here are the letters you used: "
do i = 1,26
if (n(i) == ' ') then
exit
end if
write (*,'(aa$)') n(i),","
end do
write (*,*) " "
write (*,*) "what is your guess? "; r=0
read (*,*) guess
do i = 1,26
if (n(i) == " ") then
exit
end if
if ((ichar(n(i)) - ichar(guess)) == 0) then
write (*,*) "you guessed that letter before";
exit
end if
end do
n(i)=guess; t1=t1+1
do i = 1,l
if (a(i:i) == guess) then
d(i) = guess; r=r+1
end if
end do
do while (r == 0)
m=m+1
write (*,*) "sorry, that letter isn't in the word."
select case (m)
case(:1)
write (*,*) "first we draw a head.";
p(3,6) = "-"; p(3,7) = "-"; p(3,8) = "-"; p(4,5) = "(";
p(4,6) = "."; p(4,8) = "."; p(4,9) = ")"; p(5,6) = "-";
p(5,7) = "-"; p(5,8) = "-";
case(2)
write (*,*) "now we draw a body.";
do i = 6,9
p(i,7) = "x" ;
end do
case(3)
write (*,*) "next we draw an arm.";
do i = 4,7
p(i,i-1) = "\";
end do
case(4)
write (*,*) "this time it's the other arm.";
p(4,11) = "/"; p(5,10) = "/"; p(6,9) = "/"; p(7,8) = "/";
case(5)
write (*,*) "now, let's draw the right leg.";
p(10,6) = "/"; p(11,5) = "/";
case(6)
write (*,*) "this time we draw the left leg.";
p(10,8) = "\"; p(11,9) = "\";
case(7)
write (*,*) "now we put up a hand.";
p(3,11) = "\";
case(8)
write (*,*) "next the other hand.";
p(3,3) = "/";
case(9)
write (*,*) "now we draw one foot.";
p(12,10) = "\"; p(12,11) = "-";
case(10:)
write (*,*) "here's the other foot -- you're hung!!.";
p(12,3) = "-"; p(12,4) = "/"
dead = 1
end select
do i = 1,12
write (*,*) (p(i,j),j=1,12)
end do
if ((m - 10) /= 0 .and. dead == 0) then
write (*,*) "here are the letters you used: "
do i = 1,26
if (n(i) == ' ') then
exit
end if
write (*,'(aa$)') n(i),","
end do
write (*,*) " "
write (*,*) "what is your guess? "; r=0
read (*,*) guess
do i = 1,26
if (n(i) == " ") then
exit
end if
if ((ichar(n(i)) - ichar(guess)) == 0) then
write (*,*) "you guessed that letter before";
exit
end if
end do
n(i)=guess; t1=t1+1
do i = 1,l
if (a(i:i) == guess) then
d(i) = guess; r=r+1
end if
end do
else
write (*,*) "sorry, you loose. the word was ", a
write (*,*) "you missed that one."; exit
end if
end do
if (dead == 1) exit
do i = 1,l
if ((ichar(d(i)) - ichar("-")) == 0) then
write (*,*) d(1:l)
write (*,*) "what is your guess for the word? "
read (*,*) b
if (a == b) then
write (*,*) "right! it took you ",t1," guesses"
win = 1
wrong = 0
exit
else
write (*,*) "wrong. try another letter"
wrong = 1
exit
end if
end if
end do
if (wrong == 0) then
write (*,*) "you found the word."
win = 1
wrong = 0
end if
end do
win = 0
dead = 0
write (*,*) "do you want another word? (y/n) "
read (*,*) ans
if ((ichar(ans) - ichar("y")) /= 0 .and. (ichar(ans) - ichar("Y")) /= 0) then
write (*,*) "it's been fun! bye for now."; exit
end if
end do
write (*,*) "ending..."
contains
integer function random(q)
implicit none
real :: rnd
integer :: q
rnd=rand()
q=ceiling(rnd*50)
random = q
end function random
end
+8
View File
@@ -0,0 +1,8 @@
main: hangman.f95
gfortran -o hangman hangman.f95
77: hang4.for
gfortran -o hangman hang4.for
clean:
rm hangman