Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Brick 2

Uploader:Mitgliedcroco97
Datum/Zeit:10.12.2007 11:22:12

' Brick 2
' From Eternal Pain
' Modifications by Croco
' 2007
' See www.freebasic-portal.de

#include "fbgfx.bi"

Const Ckeydelay=0.15

''-- Data Lines --''

Main:
Data 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16 , 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,14,14,14,07,07,04,04,04,07,07,09,09 , 09,07,07,05,05,05,07,07,02,07,07,02,07,07,07,16
Data 16,07,07,07,14,07,07,14,07,04,07,07,04,07,07,09 , 07,07,05,07,07,07,05,07,02,07,07,02,07,07,07,16
Data 16,07,07,07,14,07,07,14,07,04,07,07,04,07,07,09 , 07,07,05,07,07,07,07,07,02,07,02,07,07,07,07,16
Data 16,07,07,07,14,07,07,14,07,04,07,07,04,07,07,09 , 07,07,05,07,07,07,07,07,02,02,07,07,07,07,07,16
Data 16,07,07,07,14,14,14,07,07,04,04,04,07,07,07,09 , 07,07,05,07,07,07,07,07,02,02,07,07,07,07,07,16
Data 16,07,07,07,14,07,07,14,07,04,07,07,04,07,07,09 , 07,07,05,07,07,07,07,07,02,07,02,07,07,07,07,16
Data 16,07,07,07,14,07,07,14,07,04,07,07,04,07,07,09 , 07,07,05,07,07,07,05,07,02,07,07,02,07,07,07,16
Data 16,07,07,07,14,14,14,07,07,04,07,07,04,07,09,09 , 09,07,07,05,05,05,07,07,02,07,07,02,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,16,16,16,16,16,16,16,16 , 16,16,16,16,16,16,16,16,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,16,16,16,16,16,16,16,16 , 16,16,16,16,16,16,16,16,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07 , 07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,16
Data 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16 , 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16

'Forms:

Form1:
    Data 0,0,0,0
    Data 0,1,1,0
    Data 0,1,1,0
    Data 0,0,0,0
Form2:
    Data 0,1,1,0
    Data 0,0,1,0
    Data 0,0,1,0
    Data 0,0,0,0
Form3:
    Data 0,0,0,0
    Data 0,0,1,0
    Data 0,0,1,0
    Data 0,1,1,0
Form4:
    Data 0,0,0,0
    Data 0,1,0,0
    Data 0,1,1,0
    Data 0,0,0,0
Form5:
    Data 0,0,0,0
    Data 0,0,1,0
    Data 0,1,1,1
    Data 0,0,0,0
Form6:
    Data 0,0,1,0
    Data 0,0,1,0
    Data 0,0,1,0
    Data 0,0,1,0

''-- Global Dimensions --''
    Screen 12,,2
    SetMouse 0,0,0

    Randomize Timer


    Dim Shared as UByte A_Form(3,3) 'Aktuelle Form
    Dim Shared as UByte P_Form(3,3) 'Preview Form

    Dim Shared as UByte A_Col       'Aktuelle Farbe
    Dim Shared as UByte P_Col       'Preview Color

    Dim Shared as UByte Edit_Scr    'Edit Screen
    Dim Shared as UByte View_Scr    'View Screen
    Edit_Scr = 1 : View_Scr = 0

    Dim Shared as UInteger Score    'Score
    Dim Shared as UInteger OldScore
    Dim Shared as UByte Level       'Level
    Dim Shared as UByte OldLevel
    OldScore = 0 : Score = 0 : Level = 1 : OldLevel = 0
    Dim Shared as UInteger Lines
    Lines = 0
    Const Start_x=4
    Const Start_y=-5

    Dim Shared as Byte Pos_x
    Dim Shared as Byte Pos_y
    Pos_x = Start_x : Pos_y = Start_y

    Dim Shared as UByte Game_Scr(15,23)

    Dim Shared as Double Key_Timer
    Dim Shared as Double Fall_Timer

    Enum
        M_Down = 0
        M_Left
        M_Right
    End Enum

    Dim Shared as ubyte GameOver
    GameOver = 0
    Palette 1,&h15,&h65,&h60
''-----------------------''

    Declare Sub Get_Form
    Declare Sub Set_Brick (byval px as ushort,byval py as ushort,byval sco as ubyte)
    Declare Sub Game_Background
    Declare Sub Game_Screen
    Declare Sub Rotate_Form (byval form as ubyte)
    Declare Sub Set_Form
    Declare Sub Move_Form (byval direction as UByte)
    Declare Sub Preview_Form
    Declare Sub control_raster

    Declare Sub Main_Screen
    Declare Sub Game_Play
    Declare Sub Help_Screen

    Declare Sub Game_Over_Screen

''--Get_Form--
    Sub Get_Form
    '------------------
    'schreibe vorschau zu aktuell
        For y=0 to 3
        For x=0 to 3
            A_Form(x,y) = P_Form(x,y)
        Next x
        Next y
            A_Col = P_Col

    '------------------
    'wähle zufällige neue Form
        Rnd_Form = Int(rnd*6)

            Select Case Rnd_Form

        Case 0
            Restore Form1
        Case 1
            Restore Form2
        Case 2
            Restore Form3
        Case 3
            Restore Form4
        Case 4
            Restore Form5
        Case 5
            Restore Form6

            End Select
    '------------------
    'wähle/setze zufällige neue Farbe
        Rnd_Col = Int(rnd*5)

            Select Case Rnd_Col

        Case 0
            P_Col = 9
        Case 1
            P_Col = 2
        Case 2
            P_Col = 4
        Case 3
            P_Col = 5
        Case 4
            P_Col = 14

            End Select
    '------------------
    'schreibe neue Vorschau Form
        For y=0 to 3
        For x=0 to 3
            Read P_Form(x,y)
        Next x
        Next y
    '------------------
    'Rotiere Vorschau zufällig
        Rnd_rot = Int(rnd*4)

        For l=0 to Rnd_rot
            Rotate_Form (1)
        Next l

End Sub


''--Set_Brick--
    Sub Set_Brick (byval px as ushort,byval py as ushort,byval sco as ubyte)

        Line (1+px,1+py)-(18+px,18+py),sco,bf
        Line (0+px,0+py)-(19+px,19+py),15,b
        Line (19+px,0+py)-(19+px,19+py),8
        Line (0+px,19+py)-(19+px,19+py),8

End Sub


''--Rotate_Form--
    Sub Rotate_Form (byval form as ubyte)

        Dim Save_Form(3,3) as UByte
        Dim New_Form(3,3) as UByte

        For y=0 to 3
        For x=0 to 3
            If form = 0 Then Save_Form(x,y) = A_Form(x,y)
            If form = 1 Then Save_Form(x,y) = P_Form(x,y)
        Next x
        Next y

        New_Form(0,0)=Save_Form(3,0)
        New_Form(1,0)=Save_Form(3,1)
        New_Form(2,0)=Save_Form(3,2)
        New_Form(3,0)=Save_Form(3,3)

        New_Form(0,1)=Save_Form(2,0)
        New_Form(1,1)=Save_Form(2,1)
        New_Form(2,1)=Save_Form(2,2)
        New_Form(3,1)=Save_Form(2,3)

        New_Form(0,2)=Save_Form(1,0)
        New_Form(1,2)=Save_Form(1,1)
        New_Form(2,2)=Save_Form(1,2)
        New_Form(3,2)=Save_Form(1,3)

        New_Form(0,3)=Save_Form(0,0)
        New_Form(1,3)=Save_Form(0,1)
        New_Form(2,3)=Save_Form(0,2)
        New_Form(3,3)=Save_Form(0,3)

        RC=0

        If Form=0 Then
            For y=0 to 3
            For x=0 to 3
                If Pos_x+x>-1 and Pos_x+x<16 and Pos_y+y>-1 and Pos_y+y<24 Then
                If Game_Scr(Pos_x+x,Pos_y+y)<>0 and New_Form(x,y)=1 Then RC=1
                End If
            Next x
            Next y
        End If

        If RC=0 Then
        For y=0 to 3
        For x=0 to 3
            if form = 0 then A_Form(x,y) = New_Form(x,y)
            if form = 1 then P_Form(x,y) = New_Form(x,y)
        Next x
        Next y
        End If

        If Pos_x<0 Then
            If Pos_x<-2 Then Pos_x=-2

        If Pos_x=-2 Then
            CO=0
            For y=0 to 3
                If A_Form(1,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=-1
        End If

        If Pos_x=-1 Then
            CO=0
            For y=0 to 3
                If A_Form(0,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=0
        End If



    '------------------
        If Pos_x>12 Then
        If Pos_x>14 Then Pos_x=14

        If Pos_x=14 Then
            CO=0
            For y=0 to 3
                If A_Form(2,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=13
        End If

        If Pos_x=13 Then
            CO=0
            For y=0 to 3
                If A_Form(3,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=12
        End If

        End If
    '------------------
        End If
End Sub


''--Game_Background-- Game Background Screen Build Up
    Sub Game_Background
        For y=0 to 23
        For x=0 to 7
            Set_Brick (x*20,y*20,1)
            Set_Brick (480+(x*20),y*20,1)
        Next x
        Next y

        Line (520,20)-(599,99),0,bf

        Line (520,120)-(599,159),0,bf
        Line (520,200)-(599,239),0,bf
        Line (520,280)-(599,319),0,bf

        color 15:locate 09,67:?"Score:"
        locate 10,67:?using"########";Score

        locate 14,67:?"Level:"
        locate 15,67:?using"########";Level

        locate 19,67:?"Lines:"
        locate 20,67:?using"########";Lines

        Game_Screen
End Sub

''--Game_Screen--
    Sub Game_Screen
        For y=0 to 23
        For x=0 to 15

            If Game_Scr(x,y)<>0 then
                Set_Brick (160+(x*20),y*20,Game_Scr(x,y))
            Else
                Line (160+(x*20),y*20)-(179+(x*20),19+(y*20)),0,bf
            End If

        Next x
        Next y
End Sub


''--Set_Form
    Sub Set_Form
        For y=0 to 3
        For x=0 to 3
            If Pos_x+x>-1 and Pos_y+y>-1 and Pos_x+x<16 and Pos_y+y<24 and A_Form(x,y)<>0 Then Set_Brick(160+((Pos_x+x)*20),(Pos_y+y)*20,A_Col)
        Next x
        Next y
End Sub

''--
    Sub Preview_Form
        For y=0 to 3
        For x=0 to 3
            If P_Form(x,y)<>0 Then Set_Brick(520+(x*20),20+(y*20),P_Col)
        Next x
        Next y
End Sub


''-------------------------------------------------------------------

    Function Move_Form0 (byval direction as UByte) as integer
    '------------------

      dim CO as integer

        If Direction=1 Then
            CO=0
            For y=0 to 3
            For x=0 to 3
                If Pos_x+x>-1 and Pos_y+y>-1 and Pos_x+x<16 and Pos_y+y<24 and _
                A_Form(x,y)=1 and Game_Scr(Pos_x+x-1,Pos_y+y)<>0 Then CO=1
            Next x
            Next y

            If CO=0 Then Pos_x=Pos_x-1
        End If


        If Direction=2 Then
            CO=0
            For y=0 to 3
            For x=0 to 3
                If Pos_x+x>-1 and Pos_y+y>-1 and Pos_x+x<16 and Pos_y+y<24 and _
                A_Form(x,y)=1 and Game_Scr(Pos_x+x+1,Pos_y+y)<>0 Then CO=1
            Next x
            Next y

            If CO=0 Then Pos_x=Pos_x+1
        End If

        If Pos_x<0 Then
            If Pos_x<-2 Then Pos_x=-2

        If Pos_x=-2 Then
            CO=0
            For y=0 to 3
                If A_Form(1,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=-1
        End If

        If Pos_x=-1 Then
            CO=0
            For y=0 to 3
                If A_Form(0,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=0
        End If

        End If

    '------------------
        If Pos_x>12 Then
        If Pos_x>14 Then Pos_x=14

        If Pos_x=14 Then
            CO=0
            For y=0 to 3
                If A_Form(2,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=13
        End If

        If Pos_x=13 Then
            CO=0
            For y=0 to 3
                If A_Form(3,y)<>0 Then CO=1
            Next y

            If CO=1 Then Pos_x=12
        End If

        End If
    '------------------

        If direction = 0 Then
            CO=0
            For y=0 to 3
            For x=0 to 3
                If Pos_x+x>-1 and Pos_y+y>-1 and Pos_x+x<16 and A_Form(x,y)=1 Then
                    If Pos_y+y<24 and Game_Scr(Pos_x+x,Pos_y+y+1)<>0 Then CO=1
                    If Pos_y+y=23 Then CO=1
                End If
            Next x
            Next y

            If CO=0 Then Pos_y=Pos_y+1

        End If

     Move_Form0=CO

End Function


''-------------------------------------------------------------------.


Sub Move_Form (byval direction as UByte)
    '------------------

      CO=Move_Form0(direction)

      If CO=1 and direction=0 Then
          If Pos_y<1 Then GameOver=1
          For y=0 to 3
          For x=0 to 3
              If Pos_x+x>-1 and Pos_y+y>-1 and Pos_x+x<16 and Pos_y+y<24 Then
              If A_Form(x,y)<>0 Then Game_Scr (pos_x+x,pos_y+y)=A_Col
              End If
          Next x
          Next y
          Get_Form
          Pos_x=start_x
          Pos_y=start_y
          Score=Score+10
          control_raster
      End If

End Sub





    sub control_raster
        dim l_t as double
        y=23:bonsco=0

        while y>-1

        cr = 0

        for x=0 to 15
            if game_scr(x,y)<>0 then cr=cr+1
        next x

        if cr=16 then

        '-------------
        Screenset View_Scr,View_Scr

        for ll=0 to 4
            for xb=0 to 15
                set_brick(160+(xb*20),y*20,15)
            next xb

            l_t=Timer:while timer-l_t<.09:wend

            for xb=0 to 15
                set_brick(160+(xb*20),y*20,0)
            next xb

            l_t=Timer:while timer-l_t<.09:wend
        next ll
        '-------------


        for yy=y to 1 step -1
        for xx=0 to 15

            game_scr(xx,yy) = game_scr(xx,yy-1)

        next xx
        next yy

        y = 24

        'score = score + ((level*100)*(bonsco+1))
        score = score + 100
        Game_Screen
        bonsco=bonsco+1
        Lines=Lines+1
        end if

        y = y-1

        wend

end sub



SUB Game_Play
    Dim x_Timer as double
    Dim Key$
    dim as integer i

    Get_Form
    Get_Form
    Game_Background
    Game_Screen
    Preview_Form

    GameOver = 0
    Level    = 1
    OldLevel = 0
    Score    = 0
    OldScore = 0
    Lines    = 0

    Pos_x=Start_x : Pos_y=Start_y

    For y=0 to 23
    For x=0 to 15
    Game_Scr(x,y)=0
    Next x
    Next y

    Fall_Timer=Timer:Key_Timer=Timer
    while key$<>chr$(27) and gameover=0
        Key$=Inkey$
        If OldLevel<>Level Then
            OldLevel=Level
            Select Case Level
        Case 1
            Palette 1,&h15,&h65,&h60
        Case 2
            Palette 1,&h15,&h45,&h80
        Case 3
            Palette 1,&h00,&h30,&hAA
        Case 4
            Palette 1,&h30,&h10,&hFF
        Case 5
            Palette 1,&h50,&h00,&hBB
        Case 6
            Palette 1,&h75,&h00,&h88
        Case 7
            Palette 1,&h90,&h30,&h50
        Case 8
            Palette 1,&hB0,&h50,&h30
        Case 9
            Palette 1,&hC0,&h60,&h10
        Case 10
            Palette 1,&hf0,&h75,&h00
            End Select
        End If


        If MultiKey(&h4B) and Timer-Key_Timer>Ckeydelay Then Move_Form(1):Key_Timer=Timer
        If MultiKey(&h4D) and Timer-Key_Timer>Ckeydelay Then Move_Form(2):Key_Timer=Timer
        If Timer-Fall_Timer>(.4-((Level-1)*.042)) Then Move_Form(0):Fall_Timer=Timer

        If MultiKey(&h48) and Timer-Key_Timer>Ckeydelay Then Rotate_Form(0):Key_Timer=Timer
        If MultiKey(&h50) and Timer-Key_Timer>0.2 Then
          For k1=0 to 30:k2=Move_Form0(0):next k1
          Key_Timer=Timer:Fall_Timer=Timer
        end if

        'If Score-OldScore>(1000*(Level*Level))-1 and Level<11 Then OldScore=(1000*(Level*Level)):Level=Level+1
        If Score-OldScore>999 and Level<11 Then Level=Level+1:OldScore=Score
        If MultiKey(SC_PAGEUP) then
          Level=Level+1
          'Empty keybuffer
          for i=0 to 999999:Key$=inkey$:next i
          'input key$
        end if

        Screenset Edit_Scr
        Game_Background : Game_Screen : Preview_Form : Set_Form
        Screenset ,Edit_Scr
        Swap Edit_Scr,View_Scr

        If asc(LCase(Key$))=112 Then
            Break=1:ScreenSet View_Scr,View_Scr
            x_timer=timer
            While Break=1


                    cl=cl+1
                    If cl=16 then cl=1

                        Locate 15,37
                        Color cl
                        ?"P";
                        Color cl+1
                        ?"A";
                        Color cl+2
                        ?"U";
                        Color cl+3
                        ?"S";
                        Color cl+4
                        ?"E";
                        Color cl+5
                        ?"D";
                    Key$=Inkey$
                    If asc(LCase(Key$))=112 Then Break=0

                    While Timer-x_timer<.1 and Break=1
                        Key$=Inkey$
                        If asc(LCase(Key$))=112 Then Break=0
                    Wend

                    x_timer=timer
            Wend
        End If


    wend

end sub







'--------------Main Screen
    Sub Main_Screen

    Dim Key$

    While Key$<>Chr$(27)

    If GameOver=1 Then GameOver=0:Game_Over_Screen:key$=" ":while key$<>"":key$=Inkey$:wend

    ScreenSet Edit_Scr

    restore Main

    for y=0 to 23
    for x=0 to 31
        read c
        if c<>16 then set_brick(x*20,y*20,c) else line(x*20,y*20)-(19+(x*20),19+(y*20)),0,bf
    next x
    next y
        color 15
        locate 20,25:?" Press -Space- to Start New Game"
        locate 21,25:?"       Press -H- for Help      "
    ScreenSet ,Edit_Scr
    Swap Edit_Scr,View_Scr

    Key$=Inkey$
    If LCase(Key$)=chr$(32) Then Game_Play:key$=" ":while key$<>"":key$=Inkey$:wend
    If LCase(Key$)=chr$(104) Then Help_Screen:key$=" ":while key$<>"":key$=Inkey$:wend
    Wend

End Sub


'--------------Help Screen
    Sub Help_Screen

        Dim Key$

        While Key$<>Chr$(27)

        ScreenSet Edit_Scr

        restore Main
        for y=0 to 23
        for x=0 to 31
            read c
            if c<>16 then set_brick(x*20,y*20,c) else line(x*20,y*20)-(19+(x*20),19+(y*20)),0,bf
        next x
        next y

        Line (40,240)-(599,439),0,bf

        Color 15
            Locate 17,10:?"Help: Use arrow keys to control the bricks"
        Color 7
            Locate 19,10:?"UP    ->  Rotate brick"
            Locate 20,10:?"LEFT  ->  Move left"
            Locate 21,10:?"RIGHT ->  Move right"
            Locate 22,10:?"DOWN  ->  Speed Up falling down"
            Locate 23,10:?"PgUp  ->  Increase Level by 1"
        Color 15
            Locate 25,10:?"Press ESCape to return Main Screen"

        ScreenSet ,Edit_Scr
        Swap Edit_Scr,View_Scr

        Key$=Inkey$

        Wend
End Sub

'---------------Game Over Screen
    Sub Game_Over_Screen
    Dim Free as integer
    Dim FL as UInteger
    Dim hscName(9) as String*12
    Dim hscScore(9) as UInteger
    Dim hscLevel(9) as UByte
    Dim hscLines(9) as UInteger
    Dim Key$,NewName$

    ScreenCopy View_Scr,Edit_Scr
    ScreenSet Edit_Scr

    Free = freefile

    Open "brick.hsc" for binary access read as #Free
    FL=Lof(Free)
    Close #Free

        If FL=0 Then

        Free = freefile
        Open "brick.hsc" for binary access write as #Free

        For l=0 to 9
            hscName(l)="NoName"
            hscScore(l)=10000-(l*1000)
            hscLevel(l)=10-l
            hscLines(l)=100-(l*10)
            Put #Free,,hscName(l)
            Put #Free,,hscScore(l)
            Put #Free,,hscLevel(l)
            Put #Free,,hscLines(l)
        Next l

        Close #Free
        End If

    Free = freefile
    Open "brick.hsc" for binary access read as #Free

    For l=0 to 9
        Get #Free,,hscName(l)
        Get #Free,,hscScore(l)
        Get #Free,,hscLevel(l)
        Get #Free,,hscLines(l)
    Next l

    Close #Free

        Line (160,0)-(479,479),0,bf

        Color 7
        Locate 2,23:?"Name"
        Locate 2,35:?"Score"
        Locate 2,45:?"Level"
        Locate 2,54:?"Lines"
        Color 15
    For l=0 to 9
        Locate 5+(l*2),23
        ?hscName(l)
        Locate 5+(l*2),36
        ?USING"########";hscScore(l)
        Locate 5+(l*2),46
        ?USING"##";hscLevel(l)
        Locate 5+(l*2),53
        ?USING"#####";hscLines(l)
    Next l

    ScreenSet ,Edit_Scr
    ScreenCopy Edit_Scr,View_Scr
    Swap Edit_Scr,View_Scr

    hscControl=0
    While hscControl<10
        If Score>hscScore(hscControl)-1 Then hscL=hscControl:Exit While
        hscControl=hscControl+1
    Wend
        If hscControl<>hscL Then Sleep:Exit Sub

        While key$<>chr$(13)
        key$=inkey$
        ScreenSet Edit_Scr
        Color 7
        Locate 26,22:?"Enter Your Name: "
        Color 15
        Locate 26,41:?"             "
        Locate 26,41:?NewName$+"_"
        ScreenSet ,Edit_Scr
        Swap Edit_Scr,View_Scr

            If asc(key$)>27 and asc(key$)<211 and Len(NewName$)<13 Then NewName$=NewName$+chr$(asc(key$))
            If MultiKey(&h0E) Then NewName$=Mid$(NewName$,1,Len(NewName$)-1)
        Wend

        ScreenSet Edit_Scr

        If hscL<9 Then
            For l=9 to hscL-1 step-1
                hscName(l)  = hscName(l-1)
                hscScore(l) = hscScore(l-1)
                hscLevel(l) = hscLevel(l-1)
                hscLines(l) = hscLines(l-1)
            Next l
        End If

        hscName(hscL)  = NewName$
        hscScore(hscL) = Score
        hscLevel(hscL) = Level
        hscLines(hscL) = Lines

        Line (160,0)-(479,479),0,bf

        Color 7
        Locate 2,23:?"Name"
        Locate 2,35:?"Score"
        Locate 2,45:?"Level"
        Locate 2,54:?"Lines"
        Color 15
    For l=0 to 9
        Locate 5+(l*2),23
        ?hscName(l)
        Locate 5+(l*2),36
        ?USING"########";hscScore(l)
        Locate 5+(l*2),46
        ?USING"##";hscLevel(l)
        Locate 5+(l*2),53
        ?USING"#####";hscLines(l)
    Next l

    ScreenSet ,Edit_Scr
    ScreenCopy Edit_Scr,View_Scr
    Swap Edit_Scr,View_Scr
        Free = freefile
        Open "brick.hsc" for binary access write as #Free

        For l=0 to 9
            Put #Free,,hscName(l)
            Put #Free,,hscScore(l)
            Put #Free,,hscLevel(l)
            Put #Free,,hscLines(l)
        Next l

        Close #Free

    key$=" ":while getkey<>0 and key$<>"":key$=Inkey$:wend
    sleep
    key$=" ":while getkey<>0 and key$<>"":key$=Inkey$:wend


End Sub



Main_Screen