Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [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

Snake, die erste...

Uploader:Mitgliedmax06
Datum/Zeit:29.09.2008 13:51:44

' snake1

Screen 19


Dim taste As String

Type schlange
    Pos_x As Integer
    Pos_y As Integer
    direction As Integer = 0
End Type

Type spielfeld
    groesse_x As Integer = LOWORD(WIDTH)
    groesse_y As Integer = HIWORD(WIDTH)
End Type

Type Item
    pos_x As Integer
    pos_y As Integer
End Type

reDim snake(5) As schlange
Dim fenster As spielfeld
Dim x As Integer
Dim futter As Item

Randomize Timer
futter.pos_x=INT(RND * fenster.groesse_x) + 1
futter.pos_y=INT(RND * fenster.groesse_y) + 1

snake(0).Pos_x=fenster.groesse_x/2
snake(0).Pos_y=fenster.groesse_y/2

Do
    taste=InKey

    Cls
    With snake(0)
        Locate 1,1 : Print "Taste: ", taste
        Select Case taste
            Case Chr(255)+"H"
                .direction=4
            Case Chr(255)+"K"
                .direction=3
            Case Chr(255)+"P"
                .direction=2
            Case Chr(255)+"M"
                .direction=1
        End Select

        Select Case .direction
            Case 1      'rechts
                If .Pos_x<fenster.groesse_x Then
                    .Pos_x=.Pos_x+1
                    for x as integer = ubound(snake) - 1 to 0 step - 1: snake(x + 1) = snake(x): Next
                EndIf
            Case 2      'unten
                If .Pos_y<fenster.groesse_y Then
                    .Pos_y=.Pos_y+1
                    for x as integer = ubound(snake) - 1 to 0 step - 1: snake(x + 1) = snake(x): Next
                EndIf
            Case 3      'links
                If .Pos_x>1 Then
                    .Pos_x=.Pos_x-1
                    for x as integer = ubound(snake) - 1 to 0 step - 1: snake(x + 1) = snake(x): Next
                EndIf
            Case 4      'oben
                If .Pos_y>1 Then
                    .Pos_y=.Pos_y-1
                    for x as integer = ubound(snake) - 1 to 0 step - 1: snake(x + 1) = snake(x): Next
                EndIf
        End Select

        If .Pos_x=futter.pos_x And .Pos_y=futter.pos_y Then
            ReDim Preserve snake(UBound(snake)+2) As schlange
            futter.pos_x=INT(RND * fenster.groesse_x) + 1
            futter.pos_y=INT(RND * fenster.groesse_y) + 1
        EndIf
    End With



    For x As Integer = 0 To UBound(snake)
        Locate snake(x).Pos_y, snake(x).Pos_x
        Print "*"
    Next
        Locate futter.pos_y, futter.pos_x: Print "#"
    Sleep 50

Loop Until taste=Chr(27)

end