A downloadable game

10 Line BASIC 

=============

Category : PUR-80 

TITLE    : MEMORY

PLATFORM : Oric Atmos

LANGUAGE : BASIC 1.1b

AUTHOR   : Rax

VIDEO    :


A few years ago, I watched a popular science documentary that showed how chimpanzees’ memory can be far superior to humans’. It really stuck with me, and I decided to see how my own memory would measure up.

I created a small program to test my visual memory — and, unsurprisingly, it turned out to be much weaker than what I’d seen in the documentary 😄

The game itself isn’t anything fancy, but it does a good job of demonstrating the concept from the video below.

The game is played using the arrow keys and the spacebar.

Code:

0---------1---------2---------3---------4---------5---------6---------7-----78
0PAPER0:INK7:CLS:POKE#26A,2:DEFFNR(X)=INT(RND(1)*X):Q=5:W=2:N=5:C$="         "
1INPUT"LEVEL(1-99)";N:GOSUB8:PLOT2,0,"Hit key":GETA$:GOSUB7:X=0:Y=0:I=0:E=0
2PLOT2,0,C$:REPEAT:GETK$:K=ASC(K$):PLOTQ+X*3,W+Y*2," ":PLOT3+Q+X*3,W+Y*2," "
3X=X+(K=8ANDX>0)-(K=9ANDX<9):Y=Y+(K=11ANDY>0)-(K=10ANDY<9)
4IFK=32ANDV(X,Y)>0THENIFV(X,Y)=I+1THENI=I+1ELSEE=1:?@Q+X*3,W+Y*2;V(X,Y)
5PLOT3+Q+X*3,W+Y*2,"<":PLOTQ+X*3,W+Y*2,">"
6UNTILEORI>=N:IFI=NTHENPAPER2:PING:GETA$:RUNELSEPAPER1:EXPLODE:GETA$:RUN
7FORY=0TO9:FORX=0TO9:IFV(X,Y)THEN?@Q+X*3,W+Y*2;" ##"ELSE:NEXTX,Y:RETURN
8CLS:FORI=1TON:X=FNR(10):Y=FNR(10):IFV(X,Y)=0THENV(X,Y)=IELSEI=I-1:NEXT
9FORY=0TO9:FORX=0TO9:IFV(X,Y)THEN?@Q+X*3,W+Y*2;V(X,Y)ELSE:NEXTX,Y:RETURN

CODE EXPLANATION:

0PAPER0:INK7:CLS:POKE#26A,2:DEFFNR(X)=INT(RND(1)*X):Q=5:W=2:N=5:C$=" "

    PAPER 0                                                    - set background color (black)

    INK 7                                                      - set text color (white)

    CLS                                                        - clear screen

    POKE #26A,2                                                - disable cursor blink

    DEFFNR(X)=INT(RND(1)*X)                                    - random function (0 to X-1)

    Q=5                                                        - horizontal offset of the grid

    W=2                                                        - vertical offset of the grid

    N=5                                                        - default level (number of hidden numbers)

    C$="         "                                             - string used for clearing text (spaces)


1INPUT"LEVEL(1-99)";N:GOSUB8:PLOT2,0,"Hit key":GETA$:GOSUB7:X=0:Y=0:I=0:E=0

    INPUT "LEVEL(1-99)";N                                      - user selects difficulty (how many numbers)

    GOSUB 8                                                    - generate board with random numbers

    PLOT 2,0,"Hit key"                                         - print message

    GET A$                                                     - wait for key press

    GOSUB 7                                                    - hide numbers (show ## instead)

    X=0                                                        - player cursor X position

    Y=0                                                        - player cursor Y position

    I=0                                                        - current number to find (progress)

    E=0                                                        - error flag (wrong choice)


2PLOT2,0,C$:REPEAT:GETK$:K=ASC(K$):PLOTQ+X3,W+Y2," ":PLOT3+Q+X3,W+Y2," "

    PLOT 2,0,C$                                                - clear top text line

    REPEAT                                                     - start game loop

        GET K$                                                 - read key

        K=ASC(K$)                                              - convert key to ASCII

        PLOT Q+X*3,W+Y*2," "                                   - erase cursor (left part)

        PLOT 3+Q+X*3,W+Y*2," "                                 - erase cursor (right part)


3X=X+(K=8ANDX>0)-(K=9ANDX<9):Y=Y+(K=11ANDY>0)-(K=10ANDY<9)

        X = X + (K=8 AND X>0) - (K=9 AND X<9)                 - move left/right (arrow keys)

        Y = Y + (K=11 AND Y>0) - (K=10 AND Y<9)               - move up/down

        'K=8  → left

        'K=9  → right

        'K=11 → up

        'K=10 → down


4IFK=32ANDV(X,Y)>0THENIFV(X,Y)=I+1THENI=I+1ELSEE=1:?@Q+X3,W+Y2;V(X,Y)

        IF K=32 AND V(X,Y)>0 THEN                              - if SPACE pressed on a cell with number

            IF V(X,Y)=I+1 THEN                                 - correct next number?

                I=I+1                                          - increase progress

            ELSE

                E=1                                            - mark error (wrong number)

            ?@Q+X*3,W+Y*2;V(X,Y)                               - reveal the number at that position


5PLOT3+Q+X3,W+Y2,"<":PLOTQ+X3,W+Y2,">"

        PLOT 3+Q+X*3,W+Y*2,"<"                                 - draw cursor right symbol

        PLOT Q+X*3,W+Y*2,">"                                   - draw cursor left symbol


6UNTILEORI>=N:IFI=NTHENPAPER2:PING:GETA$:RUNELSEPAPER1:EXPLODE:GETA$:RUN

    UNTIL E OR I>=N                                            - exit loop if error OR finished all numbers

    IF I=N THEN                                                - if player found all numbers in order

        PAPER 2                                                - change background (green)

        PING                                                   - success sound

        GET A$                                                 - wait key

        RUN                                                    - restart game

    ELSE

        PAPER 1                                                - change background (red)

        EXPLODE                                                - error sound

        GET A$                                                 - wait key

        RUN                                                    - restart game


7FORY=0TO9:FORX=0TO9:IFV(X,Y)THEN?@Q+X3,W+Y2;" ##"ELSE:NEXTX,Y:RETURN

    FOR Y=0 TO 9                                               - loop rows

        FOR X=0 TO 9                                           - loop columns

            IF V(X,Y) THEN                                     - if there is a number

                ?@Q+X*3,W+Y*2;" ##"                            - hide it with ##

        NEXT X,Y

    RETURN                                                     - return to main


8CLS:FORI=1TON:X=FNR(10):Y=FNR(10):IFV(X,Y)=0THENV(X,Y)=IELSEI=I-1:NEXT

    CLS                                                        - clear screen

    FOR I=1 TO N                                               - place numbers from 1 to N

        X=FNR(10)                                              - random X (0-9)

        Y=FNR(10)                                              - random Y (0-9)

        IF V(X,Y)=0 THEN                                       - if cell is empty

            V(X,Y)=I                                           - place number

        ELSE

            I=I-1                                              - retry same number

    NEXT                                                       - next number


9FORY=0TO9:FORX=0TO9:IFV(X,Y)THEN?@Q+X3,W+Y2;V(X,Y)ELSE:NEXTX,Y:RETURN

    FOR Y=0 TO 9                                               - loop rows

        FOR X=0 TO 9                                           - loop columns

            IF V(X,Y) THEN                                     - if there is a number

                ?@Q+X*3,W+Y*2;V(X,Y)                           - show it

        NEXT X,Y

    RETURN                                                     - return

Download

Download
memory.bas 7.8 kB
Download
MEMORY.tap 574 bytes

Install instructions

INSTALLATION INSTRUCTIONS:

1. Download the zip file from here: http://www.petergordon.org.uk/oricutron/files/Oricutron_win32_v12.zip

2. Copy the file MEMORY.TAP to the Oric\tapes folder

3. Start the emulator oricutron.exe

4. Type CLOAD"MEMORY" and press enter

5. LIST to show the program

6. Type RUN to play the game

Comments

Log in with itch.io to leave a comment.

very good