A downloadable game

10 Line BASIC 

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

Category : PUR-80 

TITLE    : Lights Out

PLATFORM : Oric Atmos

LANGUAGE : BASIC 1.1b

AUTHOR   : Rax

VIDEO    :

“Lights Out” (8-bit version) – Game Description

In an old 8-bit system, a mysterious malfunction has left all the lights in a chaotic state. Your task is to restore order by turning off every single light and bringing the system back to normal.

How to play:

The game field is a grid of lights (classic 5×5), each of which can be either on or off. When you press a light, it changes its state as well as the state of its neighbors (up, down, left, and right). The goal is to turn off all the lights on the board.

Each move affects multiple positions at once, so careful planning is required.

You control the game using the arrow keys to move around the grid, and the spacebar to toggle a light (and its neighbors).

Interesting fact:

In the classic 5×5 grid, not all starting configurations are solvable. The total number of possible states is 2²⁵ = 33,554,432, but only 2²³ = 8,388,608 of them have a solution.

Important:

In this version of the game, all starting configurations you encounter are carefully selected and always solvable — there are no invalid or impossible levels.

A small trick:

If you get stuck, there is a strategy that always works. Try to turn off the lights row by row from top to bottom, leaving only the last (5th) row possibly lit. Then, depending on which lights are on in row 5, apply the following pattern by pressing buttons on row 1:

If lights are on: 1, 2, 3 → press position 2

If lights are on: 1, 2, 4, 5 → press position 3

If lights are on: 1, 3, 4 → press position 5

If lights are on: 1, 5 → press positions 1 and 2

If lights are on: 2, 3, 5 → press position 1

If lights are on: 2, 4 → press positions 2 and 5

If lights are on: 3, 4, 5 → press position 4

Then continue clearing the rows downward again, and you will reach a solution.


Code:

0---------1---------2---------3---------4---------5---------6---------7-----78
0DEFFNR(X)=INT(RND(1)*X):CLS:LORES1:INK3:DIMM(7,7):POKE#26A,2:PLOT0,2,0:M=0'''
1S$="6#IEP:^_]O_?V/YG\;":GOSUB7:PING:REPEAT:K$=KEY$:K=0:IFK$<>""THENK=ASC(K$)'
2Q=X:W=Y:S=M(X,Y):GOSUB9:X=X+(K=8ANDX>1)-(K=9ANDX<5)''''''''''''''''''''''''''
3Y=Y+(K=11ANDY>1)-(K=10ANDY<5):Q=X:W=Y:S=2:GOSUB9:IFK$=" "THENGOSUB5:GOSUB8'''
4UNTILZ=0:CLS:LORES0:?"Moves:"M" Again Y/N? ":GETK$:IFK$="N"THENENDELSERUN''''
5M(X,Y)=1-M(X,Y):M(X-1,Y)=1-M(X-1,Y):M(X+1,Y)=1-M(X+1,Y):M(X,Y-1)=1-M(X,Y-1)''
6M(X,Y+1)=1-M(X,Y+1):Z=0:IFK$=" "THENM=M+1ELSE:RETURN'''''''''''''''''''''''''
7FORW=1TO99:X=FNR(5)+1:Y=FNR(5)+1:GOSUB5:NEXT:X=3:Y=3:PLOT12,2,"Lights Out:"''
8FORW=1TO5:FORQ=1TO5:S=(M(Q,W)):Z=Z+S:GOSUB9:NEXTQ,W:?@23,2;Z" ":RETURN'''''''
9FORI=0TO1:PLOT6+Q*4,2+W*3+I,MID$(S$,1+S*6+I*3,3):NEXT:RETURN'''''''''''''''''

CODE EXPLANATION:

0DEFFNR(X)=INT(RND(1)*X):CLS:LORES1:INK3:DIMM(7,7):POKE#26A,2:PLOT0,2,0:M=0

    DEFFNR(X)=INT(RND(1)*X)                                     - define function FNR that returns random integer from 0 to X-1

    CLS                                                         - clear the screen

    LORES1                                                      - set alternative chars mode

    INK3                                                        - set drawing color to 3

    DIM M(7,7)                                                  - create 2D array used for the lights grid

    POKE#26A,2                                                  - adjust keyboard/cursor behavior

    PLOT0,2,0                                                   - remove the alternate character mode on this line set by the LORES1 command

    M=0                                                         - reset move counter


1S$="6#IEP:^]O?V/YG;":GOSUB7:PING:REPEAT:K$=KEY$:K=0:IFK$<>""THENK=ASC(K$)

    S$="6#IEP:^_]O_?V/YG\;"                                     - sprite/graphics data used to draw grid cells

    GOSUB7                                                      - call routine to initialize the puzzle board

    PING                                                        - play small sound effect

    REPEAT                                                      - start main game loop

        K$=KEY$                                                 - read keyboard input

        K=0                                                     - reset key code

        IF K$<>"" THEN                                          - if a key is pressed

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


2Q=X:W=Y:S=M(X,Y):GOSUB9:X=X+(K=8ANDX>1)-(K=9ANDX<5)

        Q=X                                                     - store previous cursor X position

        W=Y                                                     - store previous cursor Y position

        S=M(X,Y)                                                - get current cell state (light on/off)

        GOSUB9                                                  - draw the cell

        X=X+(K=8 AND X>1)-(K=9 AND X<5)                         - move cursor pos left/right depending on key


3Y=Y+(K=11ANDY>1)-(K=10ANDY<5):Q=X:W=Y:S=2:GOSUB9:IFK$=" "THENGOSUB5:GOSUB8

        Y=Y+(K=11 AND Y>1)-(K=10 AND Y<5)                       - move cursor up/down depending on key

        Q=X                                                     - update cursor X

        W=Y                                                     - update cursor Y

        S=2                                                     - sprite index used to highlight cursor

        GOSUB9                                                  - draw cursor on grid

        IF K$=" " THEN                                          - if SPACE key pressed

            GOSUB5                                              - toggle selected light and neighbors

            GOSUB8                                              - redraw grid and recalculate lights count


4UNTILZ=0:CLS:LORES0:?"Moves:"M" Again Y/N? ":GETK$:IFK$="N"THENENDELSERUN

    UNTIL Z=0                                                   - loop continues until all lights are off

    CLS                                                         - clear screen

    LORES0                                                      - return to normal text mode

    PRINT "Moves:"M" Again Y/N? "                               - show number of moves and ask for replay

    GET K$                                                      - read user input

    IF K$="N" THEN                                              - if player chooses no

        END                                                     - end program

    ELSE

        RUN                                                     - restart the game


5M(X,Y)=1-M(X,Y):M(X-1,Y)=1-M(X-1,Y):M(X+1,Y)=1-M(X+1,Y):M(X,Y-1)=1-M(X,Y-1)

    'toggle selected light routine

    M(X,Y)=1-M(X,Y)                                             - toggle current light

    M(X-1,Y)=1-M(X-1,Y)                                         - toggle left neighbor

    M(X+1,Y)=1-M(X+1,Y)                                         - toggle right neighbor

    M(X,Y-1)=1-M(X,Y-1)                                         - toggle upper neighbor


6M(X,Y+1)=1-M(X,Y+1):Z=0:IFK$=" "THENM=M+1ELSE:RETURN

    M(X,Y+1)=1-M(X,Y+1)                                         - toggle bottom neighbor

    Z=0                                                         - reset lights counter

    IF K$=" " THEN                                              - if action triggered by player

        M=M+1                                                   - increase moves counter

    ELSE

        :                                                       - nothing

    RETURN                                                  - return without counting move


7FORW=1TO99:X=FNR(5)+1:Y=FNR(5)+1:GOSUB5:NEXT:X=3:Y=3:PLOT12,2,"Lights Out:"

    'randomize board routine

    FOR W=1 TO 99                                               - randomize board by performing 99 random toggles

        X=FNR(5)+1                                              - random X position

        Y=FNR(5)+1                                              - random Y position

        GOSUB5                                                  - toggle that cell and neighbors

    NEXT

    X=3                                                         - set starting cursor X

    Y=3                                                         - set starting cursor Y

    PLOT12,2,"Lights Out:"                                      - print game title


8FORW=1TO5:FORQ=1TO5:S=(M(Q,W)):Z=Z+S:GOSUB9:NEXTQ,W:?@23,2;Z" ":RETURN

    'print board routine

    FOR W=1 TO 5                                                - vertical grid loop

        FOR Q=1 TO 5                                            - horizontal grid loop

            S=(M(Q,W))                                          - get cell state (light on/off)

            Z=Z+S                                               - accumulate number of lights still on

            GOSUB9                                              - draw cell

        NEXT Q

    NEXT W

    PRINT @23,2;Z" "                                            - display remaining lights counter

    RETURN                                                      - return to main loop


9FORI=0TO1:PLOT6+Q4,2+W3+I,MID$(S$,1+S6+I3,3):NEXT:RETURN

    

    'print sprite routine

    FOR I=0 TO 1                                                - draw two rows of the cell sprite

        PLOT 6+Q*4,2+W*3+I, MID$(S$,1+S*6+I*3,3)                - print 3-character sprite part depending on cell state

    NEXT

    RETURN                                                      - return to caller

Updated 26 days ago
Published 28 days ago
StatusReleased
AuthorBASIC 10Liner
GenreStrategy
Tags10liner, 8-Bit, basic, oric-atmos
ContentNo generative AI was used

Download

Download
LIGHTSOUT10.tap 693 bytes
Download
lightsout10.txt 9.8 kB

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 LIGHTSOUT10.TAP to the Oric\tapes folder

3. Start the emulator oricutron.exe

4. Type CLOAD"LIGHTSOUT10" 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