Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
You're a bandit!
#2
program plays itself
where character is striving for a target
and character avoids enemy
and yet enemy wins

used idea of my program XONIX

https://qb64phoenix.com/forum/showthread.php?tid=519

beginning of program added name bandit.bas
and copying it is easy to save using a ready-made name

Code: (Select All)
'by mnrvovrfc 23-Mar-2023 ' bandit.bas
Option _Explicit: Randomize Timer

Dim As Integer top, lef, bot, rig, lvl, chc, i, j, wid
Dim As Integer px, py, bx, by, cx, cy, ox, oy, score
Dim As _Byte quit, die, goon, permission, finis
Dim a$, t$, treasure$, namlvl$(1 To 5)
treasure$ = "@$" + Chr$(244) + Chr$(176) + Chr$(4)
namlvl$(1) = "honey bun"
namlvl$(2) = "lotta money"
namlvl$(3) = "candy cane"
namlvl$(4) = "graham cracker"
namlvl$(5) = "diamond"
top = 1: lef = 1
bot = 22: rig = 80
lvl = 1

_Title "You're a BANDIT!"
Do
    Color 15, 0: Cls
    wid = rig - lef + 1
    a$ = String$(wid, 35)
    Locate top, lef: Print a$;
    Locate bot, lef: Print a$;
    For j = top + 1 To bot - 1
        Locate j, lef: Print "#";
        Locate j, rig: Print "#";
    Next

    px = Rand(lef + 1, 39)
    py = Rand(top + 1, 11)
    bx = Rand(40, rig - 1)
    by = Rand(12, bot - 1)
    cx = Rand(40, rig - 1)
    cy = Rand(top + 1, 11)

    t$ = Mid$(treasure$, lvl, 1)
    Locate py, px: Print "R";
    Locate by, bx: Print t$;
    Locate cy, cx: Print Chr$(206);
    Do
        _Limit 100
        j = 0
        For i = 49 To 117
            Select Case i
                Case 49, 50, 51, 52, 54, 55, 56, 57, 106, 107, 108, 111, 117
                    If _KeyDown(i) Then j = j + 1
            End Select
        Next
    Loop Until j = 0
    Locate 23, 1: Print "Go get that "; namlvl$(lvl); "!"

    chc = 2
    quit = 0
    die = 0
    Do
        _Limit 14
        ox = 3: oy = 3
        permission = 0
        If _KeyDown(27) Then quit = 1

' Danilin Xonix
        Locate oy, ox: Print " ";
        If py < by Then ox = px: oy = py: py = py + 1
        Locate py, px: Print "R";

        Locate oy, ox: Print " ";
        If py > by Then ox = px: oy = py: py = py - 1
        Locate py, px: Print "R";

        Locate oy, ox: Print " ";
        If px < bx Then ox = px: oy = py: px = px + 1
        Locate py, px: Print "R";

        Locate oy, ox: Print " ";
        If px > bx Then ox = px: oy = py: px = px - 1
        Locate py, px: Print "R";


        Locate oy, ox: Print " ";
        If py = cy Then ox = px: oy = py: py = py + 1
        Locate py, px: Print "R";

        Locate oy, ox: Print " ";
        If px = cx Then ox = px: oy = py: px = px - 1
        Locate py, px: Print "R";
' Danilin Xonix

        Do
            If ox <> -1 And oy <> -1 Then
                If Screen(py, px) = 35 Then

                    Locate by, bx: Print t$;
                    Locate py, px: Print Chr$(15);
                    die = 2
                    Exit Do
                End If
                permission = 1
                Locate oy, ox: Print " ";
                Locate by, bx: Print t$;
                Locate py, px: Print "R";
                If px = cx And py = cy Then die = 1
                If px = bx And py = by Then
                    score = score + 1
                    Locate 24, 1: Print "Score ="; score; "| Level ="; lvl;
                    chc = chc - 1
                    If chc < 1 Then finis = 1
                    bx = Rand(lef, 39)
                    by = Rand(top, 11)
                    If px < 40 Then bx = Rand(40, rig - 1) Else bx = Rand(lef + 1, 39)
                    If py < 12 Then by = Rand(12, bot - 1) Else by = Rand(top + 1, 11)
                End If
            End If
        Loop Until 1
        If die Or finis Then Exit Do
        If permission Then
            'goon = (chc = 1)
            'IF goon = 0 THEN goon = (INT(RND * chc + 1) = 1)
            goon = (Rnd * chc + 1.25 < 2)
            If goon Then
                ox = cx: oy = cy
                If px < cx Then cx = cx - 1 Else If px > cx Then cx = cx + 1
                If py < cy Then cy = cy - 1 Else If py > cy Then cy = cy + 1
                Locate oy, ox: Print " ";
                Locate by, bx: Print t$;
                Locate cy, cx: Print Chr$(206);
                If px = cx And py = cy Then die = 1
            End If
        End If
    Loop Until quit Or die Or finis

    Locate 23, 1: Print Space$(79);
    If die Then
        Play "T200L8"
        Locate 23, 1
        If die = 1 Then
            Print "The bandit has been caught!";
            For j = 8 To 80 Step 5
                Play "N" + _Trim$(Str$(j))
            Next
        ElseIf die = 2 Then
            Print "Cheater! Stop trying to run out of bounds LOL.";
            For j = 5 To 11000 Step 384
                i = Int(Sin(_D2R(j)) * Abs(30 - 40 * (j > 2000)) + 6)
                If i < 6 Then i = 6
                If i > 80 Then i = 80
                Play "N" + _Trim$(Str$(i))
            Next
        End If
    ElseIf finis Then
        lvl = lvl + 1
        If lvl > 5 Then
            Locate 23, 1: Print "Guess what? You have beaten the game!";
            Play "T200L8"
            For j = 10 To 80 Step 10
                i = ((j ^ 2.5) Mod 70) + 6
                Play "N" + _Trim$(Str$(i))
                Play "N" + _Trim$(Str$(j))
            Next
            quit = 1
        Else
            top = top + 1
            bot = bot - 1
            Select Case lvl
                Case 2
                    lef = lef + 5
                    rig = rig - 5
                Case 3
                    lef = lef + 9
                    rig = rig - 9
                Case 4
                    lef = lef + 6
                    rig = rig - 6
                Case 5
                    lef = lef + 3
                    rig = rig - 3
            End Select
            finis = 0
        End If
    End If
Loop Until die Or quit
System

Function Rand& (fromval&, toval&)
    Dim f&, t&, sg%
    If fromval& = toval& Then
        Rand& = fromval&
        Exit Function
    End If
    f& = fromval&
    t& = toval&
    If (f& < 0) And (t& < 0) Then
        sg% = -1
        f& = f& * -1
        t& = t& * -1
    Else
        sg% = 1
    End If
    If f& > t& Then Swap f&, t&
    Rand& = Int(Rnd * (t& - f& + 1) + f&) * sg%
End Function
Write name of program in 1st line to copy & paste & save filename.bas
Insert program pictures: press print-screen-shot button
Open paint & Paste & Save as PNG
Add picture file to program topic

Russia looks world from future. Big data is peace data.
I never recommend anything & always write only about myself
Reply


Messages In This Thread
You're a bandit! - by mnrvovrfc - 03-23-2023, 04:29 AM
RE: You're a bandit! - by DANILIN - 03-23-2023, 07:02 AM
RE: You're a bandit! - by SpriggsySpriggs - 03-23-2023, 04:45 PM
RE: You're a bandit! - by mnrvovrfc - 03-23-2023, 04:52 PM
RE: You're a bandit! - by DANILIN - 03-24-2023, 03:58 AM
RE: You're a bandit! - by TempodiBasic - 03-26-2023, 10:14 PM
RE: You're a bandit! - by johannhowitzer - 03-27-2023, 12:46 AM



Users browsing this thread: 2 Guest(s)