Advertisement
Shaun_B

Number Guesser by Donkeysoft

Jan 9th, 2019
4,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    1 REM Number Guesser ZX Spectrum Version by Donkeysoft
  2.    2 DIM r AS INTEGER: DIM i AS INTEGER: DIM z AS INTEGER: LET a$="": LET c$="": LET n$=CHR$(13): BORDER 0: PAPER 0: INK 7: CLS: PRINT "Welcome to Number Guesser by"; n$; INVERSE 1; "Donkeysoft MMXIX"; INVERSE 0; "- not a real"; n$; "entry for the CGC 2018"; n$; n$; n$; INK 4; "Please begin by entering a"; n$; "positive integer >= 10, I will"; n$; "then generate a random number"; n$; "for you which you must guess.": PAUSE 0: CLS
  3.    3 LET b$="": PRINT "Enter your number"; n$; "c:\>_";
  4.    4 LET a$=INKEY$: IF a$=n$ AND LEN b$>1 THEN LET z=VAL b$: GO TO 9: END IF
  5.    5 IF a$="" THEN GO TO 4: END IF
  6.    6 IF (CODE a$=8 OR CODE a$=12) AND LEN b$>0 THEN LET a$="": GO SUB 2000: GO TO 8: END IF
  7.    7 IF CODE a$<48 OR CODE a$>57 THEN GO TO 4: END IF
  8.    8 LET b$=b$+a$: PRINT AT 1,4; b$; "_  ":  LET a$=INKEY$: GO SUB 1000: GO TO 4
  9.    9 CLS: LET r=INT (RND*z)+SGN PI: LET i=NOT PI
  10.   10 LET b$="": BORDER RND*7: BEEP .1, RND*48: PRINT AT NOT PI, NOT PI; INK 3; "Please enter your guess"; n$; "c:\>"; INK 7;"_            "
  11.   11 LET a$=INKEY$: IF a$=n$ AND LEN b$>0 THEN GO TO 16: END IF
  12.   12 IF a$="" THEN GO TO 11: END IF
  13.   13 IF (CODE a$=8 OR CODE a$=12) AND LEN b$>0 THEN LET a$="": GO SUB 2000: GO TO 14: END IF
  14.   14 IF CODE a$<48 OR CODE a$>57 THEN GO TO 11: END IF
  15.   15 LET b$=b$+a$: PRINT AT 1,4; b$; "_  ": LET a$=INKEY$: GO SUB 1000: GO TO 11
  16.   16 LET i=i+1: IF VAL b$=r THEN PRINT AT 1,4; b$; " "; AT 4,0; "YOU GOT IT IN "; i; " TRIES!": GO TO 20: END IF
  17.   17 IF VAL b$<r THEN PRINT AT 4,0;"Try higher    ": END IF
  18.   18 IF VAL b$>r THEN PRINT AT 4,0;"Try lower     ": END IF
  19.   19 IF i<11 THEN GO TO 10: END IF
  20.   20 IF VAL b$=r THEN PRINT n$;"Well done": FOR i=0 TO 32: BORDER RND*7: BEEP .05, RND*48: NEXT i: END IF
  21.   21 PRINT "Would you like to try again?"; n$;"(Y/N)"
  22.   22 LET a$=INKEY$: IF a$="" THEN GO TO 22: END IF
  23.   23 IF a$="Y" OR a$="y" THEN GO TO 26: END IF
  24.   24 IF a$="N" OR a$="n" THEN CLS: RANDOMIZE USR 0: END IF
  25.   25 GO TO 22
  26.   26 GO SUB 1000: PRINT "Would you like the same number"; n$; "range?"; n$; "(Y/N)";
  27.   27 LET a$=INKEY$: IF a$="" THEN GO TO 27: END IF
  28.   28 IF a$="Y" OR a$="y" THEN GO SUB 1000: GO TO 9: END IF
  29.   29 IF a$="N" OR a$="n" THEN CLS: GO SUB 1000: GO TO 3: END IF
  30.   30 GO TO 27
  31. 1000 IF INKEY$<>"" THEN GO TO 1000:END IF: RETURN
  32. 2000 LET c$="": IF LEN b$>1 THEN LET c$=b$(0 TO LEN b$-2): END IF: LET b$=c$: RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement