Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - MidnightOwl

Pages: [1]
1
Programs / Re: lancio di due dadi
« on: November 21, 2020, 07:46:24 pm »
The ideal in programming is to avoid reinventing the wheel ie. reusable code.  The function returns dice total and shows just how complicated a function can be.  It can also be adapted to many uses with little alteration (reused) . Which was why I brought  it up in the  first place. Isn't that why there are code libraries?

2
Programs / Re: lancio di due dadi
« on: November 21, 2020, 09:33:37 am »
There is an excellent dice rolling routine in 'mboard.bas' in the samples directory in your qb64 directory. It even simulates rolling dice.

3
Programs / Re: Guess the Animal
« on: November 09, 2020, 07:06:37 am »
Here is a version that saves a data file so that the program doesn't forget what it learned
Code: QB64: [Select]
  1. DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  2.  
  3. PRINT TAB(32); "ANIMAL"
  4. PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  5. PRINT "PLAY 'GUESS THE ANIMAL'"
  6. PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  7. DIM SHARED A$(200), K, N, T$
  8. ON ERROR GOTO NOFILE
  9. OPEN "ANIMAL.DAT" FOR INPUT AS #3
  10. FOR I = 0 TO 200
  11.     INPUT #3, A$(I)
  12. NOFILE:
  13. FOR I = 0 TO 3
  14.     READ A$(I)
  15.  
  16. N = VAL(A$(0))
  17.  
  18. MAIN
  19.  
  20. '         MAIN CONTROL SECTION
  21. SUB MAIN ()
  22.     DO
  23.         DO
  24.             INPUT "ARE YOU THINKING OF AN ANIMAL (Y/N)"; A$: A$ = UCASE$(A$)
  25.         LOOP UNTIL A$ = "LIST" OR LEFT$(A$, 1) = "Y" OR LEFT$(A$, 1) = "N"
  26.         IF A$ = "LIST" THEN SHOWLIST: MAIN
  27.         IF LEFT$(A$, 1) = "N" THEN KEEPDATA: SYSTEM
  28.         K = 1
  29.         DO
  30.             SHOWQUESTION
  31.             IF LEN(A$(K)) = 0 THEN KEEPDATA: SYSTEM
  32.         LOOP WHILE LEFT$(A$(K), 2) = "\Q"
  33.         PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  34.         INPUT A$
  35.         A$ = LEFT$(A$, 1)
  36.         IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": MAIN
  37.         INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  38.         PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  39.         PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  40.         INPUT X$
  41.         DO
  42.             PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  43.             INPUT A$
  44.         A$ = LEFT$(A$, 1): LOOP UNTIL A$ = "Y" OR A$ = "N"
  45.         IF A$ = "Y" THEN B$ = "N"
  46.         IF A$ = "N" THEN B$ = "Y"
  47.         Z1 = VAL(A$(0))
  48.         A$(0) = STR$(Z1 + 2)
  49.         A$(Z1) = A$(K)
  50.         A$(Z1 + 1) = "\A" + V$
  51.         A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  52.     LOOP
  53.  
  54. '  SUBROUTINE TO PRINT QUESTIONS
  55. SUB SHOWQUESTION ()
  56.     Q$ = A$(K)
  57.     DO
  58.         FOR Z = 3 TO LEN(Q$)
  59.             IF MID$(Q$, Z, 1) = "\" THEN EXIT FOR ELSE PRINT MID$(Q$, Z, 1);
  60.         NEXT Z
  61.         INPUT C$: C$ = UCASE$(C$)
  62.         C$ = LEFT$(C$, 1)
  63.     LOOP UNTIL C$ = "Y" OR C$ = "N"
  64.     T$ = "\" + C$
  65.     FOR X = 3 TO LEN(Q$) - 1
  66.         IF MID$(Q$, X, 2) = T$ THEN EXIT FOR
  67.     NEXT X
  68.     FOR Y = X + 1 TO LEN(Q$)
  69.         IF MID$(Q$, Y, 1) = "\" THEN EXIT FOR
  70.     NEXT Y
  71.     K = VAL(MID$(Q$, X + 2, Y - X - 2))
  72.  
  73. SUB SHOWLIST ()
  74.     PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  75.     X = 0
  76.     FOR I = 1 TO 200
  77.         IF LEFT$(A$(I), 2) = "\A" THEN
  78.             PRINT TAB(15 * X);
  79.             FOR Z = 3 TO LEN(A$(I))
  80.                 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  81.             NEXT Z
  82.             X = X + 1: IF X = 4 THEN X = 0: PRINT
  83.         END IF
  84.     NEXT I
  85.     PRINT
  86.     PRINT
  87.  
  88. '        SUBROUTINE TO SAVE DATA FILE
  89. SUB KEEPDATA ()
  90.     OPEN "ANIMAL.DAT" FOR OUTPUT AS #2
  91.     FOR I = 0 TO 200
  92.         WRITE #2, A$(I)
  93.     NEXT I
  94.     CLOSE #2

4
Programs / Re: Guess the Animal
« on: November 09, 2020, 03:24:06 am »
here is the program converted to QB64 code. I have done things like this so much that it was a piece of cake.
Code: QB64: [Select]
  1. [DATA "4","\QDOES IT SWIM\Y2\N3\","\AFISH","\ABIRD"
  2.  
  3. PRINT TAB(32); "ANIMAL"
  4. PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  5. PRINT "PLAY 'GUESS THE ANIMAL'"
  6. PRINT "THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT."
  7. DIM SHARED A$(200), K, N, T$
  8. FOR I = 0 TO 3
  9.    90 READ A$(I)
  10. N = VAL(A$(0))
  11.  
  12. MAIN
  13.  
  14. '         MAIN CONTROL SECTION
  15. SUB MAIN ()
  16.     DO
  17.         DO
  18.             INPUT "ARE YOU THINKING OF AN ANIMAL (Y/N)"; A$: A$ = UCASE$(A$)
  19.         LOOP UNTIL A$ = "LIST" OR LEFT$(A$, 1) = "Y" OR LEFT$(A$, 1) = "N"
  20.         IF A$ = "LIST" THEN SHOWLIST: MAIN
  21.         IF LEFT$(A$, 1) = "N" THEN SYSTEM
  22.         K = 1
  23.         DO
  24.             SHOWQUESTION
  25.             IF LEN(A$(K)) = 0 THEN SYSTEM
  26.         LOOP WHILE LEFT$(A$(K), 2) = "\Q"
  27.         PRINT "IS IT A "; RIGHT$(A$(K), LEN(A$(K)) - 2);
  28.         INPUT A$
  29.         A$ = LEFT$(A$, 1)
  30.         IF LEFT$(A$, 1) = "Y" THEN PRINT "WHY NOT TRY ANOTHER ANIMAL?": MAIN
  31.         INPUT "THE ANIMAL YOU WERE THINKING OF WAS A "; V$
  32.         PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A"
  33.         PRINT V$; " FROM A "; RIGHT$(A$(K), LEN(A$(K)) - 2)
  34.         INPUT X$
  35.         DO
  36.             PRINT "FOR A "; V$; " THE ANSWER WOULD BE ";
  37.             INPUT A$
  38.         A$ = LEFT$(A$, 1): LOOP UNTIL A$ = "Y" OR A$ = "N"
  39.         IF A$ = "Y" THEN B$ = "N"
  40.         IF A$ = "N" THEN B$ = "Y"
  41.         Z1 = VAL(A$(0))
  42.         A$(0) = STR$(Z1 + 2)
  43.         A$(Z1) = A$(K)
  44.         A$(Z1 + 1) = "\A" + V$
  45.         A$(K) = "\Q" + X$ + "\" + A$ + STR$(Z1 + 1) + "\" + B$ + STR$(Z1) + "\"
  46.     LOOP
  47.  
  48. '  SUBROUTINE TO PRINT QUESTIONS
  49. SUB SHOWQUESTION ()
  50.     Q$ = A$(K)
  51.     DO
  52.         FOR Z = 3 TO LEN(Q$)
  53.             IF MID$(Q$, Z, 1) = "\" THEN EXIT FOR ELSE PRINT MID$(Q$, Z, 1);
  54.         NEXT Z
  55.         INPUT C$: C$ = UCASE$(C$)
  56.         C$ = LEFT$(C$, 1)
  57.     LOOP UNTIL C$ = "Y" OR C$ = "N"
  58.     T$ = "\" + C$
  59.     FOR X = 3 TO LEN(Q$) - 1
  60.         IF MID$(Q$, X, 2) = T$ THEN EXIT FOR
  61.     NEXT X
  62.     FOR Y = X + 1 TO LEN(Q$)
  63.         IF MID$(Q$, Y, 1) = "\" THEN EXIT FOR
  64.     NEXT Y
  65.     K = VAL(MID$(Q$, X + 2, Y - X - 2))
  66.  
  67. SUB SHOWLIST ()
  68.     PRINT: PRINT "ANIMALS I ALREADY KNOW ARE:"
  69.     X = 0
  70.     FOR I = 1 TO 200
  71.        620 IF LEFT$(A$(I), 2) = "\A" THEN
  72.            624 PRINT TAB(15 * X);
  73.            630 FOR Z = 3 TO LEN(A$(I))
  74.                640 IF MID$(A$(I), Z, 1) <> "\" THEN PRINT MID$(A$(I), Z, 1);
  75.            642 NEXT Z
  76.            645 X = X + 1: IF X = 4 THEN X = 0: PRINT
  77.         END IF
  78.     NEXT I
  79.     PRINT
  80.     PRINT
  81.  
  82.  
  83.  
  84. /code]

5
Programs / Re: The Phantom Temple Game
« on: September 23, 2020, 01:56:40 am »
To add my 2 cents. Everything should be in arrays, room descriptions, object  descriptions, object locations,etc. Then when the data is read from a file the code gets very small. For a complete discussion of this read 'Creating Basic Adventure Programs by Frank Decosta.

Pages: [1]