Author Topic: testa o croce  (Read 2774 times)

0 Members and 1 Guest are viewing this topic.

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
testa o croce
« on: September 10, 2020, 07:26:08 pm »
another program
is a coin toss based game
You can choose heads or tails if user types one means that he chooses heads if he types 2 and chooses tails
the game will have 10 tokens which are equivalent to 10 credits
Whether the user's choice is right will increase the value depends on the amount of credit you have wagered

Code: QB64: [Select]
  1. LOCATE 1, 1: PRINT "É"; STRING$(78, 205); "»" 'string$ scrive 78 volte il valore in ascii del 205
  2. LOCATE 2, 1: PRINT "º"; TAB(80); "º" 'tab significa fai un spazio di 80 caratteri una tabbulazione
  3. LOCATE 3, 1: PRINT "È"; STRING$(78, 205); "¼" 'string$ scrive 78 volte il valore in ascii del 205
  4. LOCATE 2, 30: PRINT "=== TESTA O CROCE ==="
  5.  
  6.  
  7. PRINT "Premi qualsiasi tasto per continuare..."
  8. tasto$ = INPUT$(1)
  9.  
  10. Credito = 10
  11. 3 CLS
  12. IF Credito <= 0 THEN LOCATE 15, 30: PRINT "GAME OVER": END
  13. LOCATE 1, 1: PRINT "É"; STRING$(78, 205); "»" 'string$ scrive 78 volte il valore in ascii del 205
  14. LOCATE 2, 1: PRINT "º"; TAB(80); "º" 'tab significa fai un spazio di 80 caratteri una tabbulazione
  15. LOCATE 3, 1: PRINT "È"; STRING$(78, 205); "¼" 'string$ scrive 78 volte il valore in ascii del 205
  16. LOCATE 2, 30: PRINT "il tuo credito"; Credito; "gettoni"
  17. 1 PRINT "Quanto vuoi puntare?"
  18. INPUT ">", Puntata
  19. PRINT "Hai puntato "; Puntata
  20. IF Puntata <= 0 THEN PRINT "Devi puntare qualcosa.": GOTO 1
  21. IF Puntata > Credito THEN PRINT "Non possiedi tutto questo credito.": GOTO 1
  22. PRINT "1-Testa     2-Croce"
  23. scelta$ = INPUT$(1)
  24. IF scelta$ <> "1" AND scelta$ <> "2" THEN PRINT "Digita 1 oppure 2": GOTO 2
  25. scelta2 = VAL(scelta$)
  26.  
  27. caso = INT(RND * 2) + 1
  28.  
  29. Vincita = Puntata * 2 - Puntata
  30.  
  31. IF caso = scelta2 THEN PRINT "Complimenti, hai vinto!!!": tasto$ = INPUT$(1): Credito = Credito + Vincita: GOTO 3
  32.  
  33. IF caso <> scelta2 THEN PRINT "Peccato hai perso": tasto$ = INPUT$(1): Credito = Credito - Puntata: GOTO 3
  34.  
  35.  
  36.  

se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: testa o croce
« Reply #1 on: September 11, 2020, 12:28:00 am »
One side of my coin says 1, the other says 2. Predict what the next flip will be 1 or 2, right or wrong we keep flipping until the flip doesn't match the first flip. That will be the amount you've won or lost if you matched the first flip or not.

I did not RANDOMIZE TIMER (like Kiara did) so you can learn to "predict" 2 for awhile and then 1 for awhile to get a little ahead in the game ;-))

Code: QB64: [Select]
  1. _TITLE "1 for 1 and 2 for 2 PLUS" 'b+ 2020-09-11
  2.     INPUT "Enter 1 for 1, 2 for 2, or 0 to quit this silly game > ", choice
  3.     IF choice = 0 THEN
  4.         END
  5.     ELSEIF choice = 1 OR choice = 2 THEN ' alrighty! let's play!
  6.         rollEm = INT(RND * 2) + 1
  7.         PRINT rollEm; ",";
  8.         DO
  9.             again = INT(RND * 2) + 1
  10.             PRINT again; ",";
  11.             count = count + 1
  12.         LOOP UNTIL again <> rollEm
  13.         PRINT
  14.         IF choice = rollEm THEN
  15.             yourPoints = yourPoints + count
  16.         ELSE
  17.             yourPoints = yourPoints - count
  18.         END IF
  19.         PRINT "Your Points ="; yourPoints
  20.     ELSE
  21.         _CONTINUE 'heh, heh
  22.     END IF
  23.     count = 0
  24.  
« Last Edit: September 11, 2020, 12:29:42 am by bplus »