Board Logo
« Memory Game for the MainWin »

Welcome Guest. Please Login or Register.
Jan 16th, 2018, 3:34pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Memory Game for the MainWin  (Read 628 times)
AndyAmaya
Board Moderator


member is offline

Avatar




PM

Gender: Male
Posts: 362
xx Memory Game for the MainWin
« Thread started on: Apr 29th, 2016, 2:28pm »

This is a game made to demonstrate the use of the MainWin SUB's placed in a previous _post.

It's just another way to introduce the concept of making the MainWin more 'graphical' to novice programmers.

Code:
'MainWin Memory Game - no sound
'Andres Amaya Jr
'2016.04.29

MainWin 80 32
Dim a(28,3), w$(14)
playGame = 1

While playGame = 1
    ReDim a(28,3)
    Call setUp
    guess = 0
    match = 0
    While match < 14
        valid1 = 0
        Do
            Locate 62, 10:Input "Tile 1: ";t1
            If t1 < 0 Then Call center "Game Terminated", 31 : End
            If (t1=0) Or (t1>28) Then
                Locate 69, 10: Print "     ";
                valid1 = 0
            Else
                If a(t1,3)=1 Then
                    Locate 69, 10: Print "     ";
                    valid1 = 0
                Else
                    w1$ = w$(a(t1,0))
                    Call slide a(t1,1), a(t1,2), w1$, 1,  200
                    valid1 = 1
                End If
            End If
        Loop Until valid1 = 1

        valid2 = 0
        Do
            Locate 62, 12:Input "Tile 2: ";t2
            If t2 < 0 Then Call center "Game Terminated", 31 : End
            If (t2=0) Or (t2>28) Then
                Locate 69, 12: Print "     ";
                valid2 = 0
            Else
                If a(t2,3)=1 Then
                    Locate 69, 12: Print "     ";
                    valid2 = 0
                Else
                    w2$ = w$(a(t2,0))
                    Call slide a(t2,1), a(t2,2), w2$, 1, 200
                    valid2 = 1
                End If
            End If
        Loop Until valid2 = 1

        guess = guess + 1
        Locate 70, 2:Print " ";guess;" ";
        If w1$ = w2$ Then
            match = match + 1
            a(t1,3) = 1: a(t2,3) = 1
            'PlayWave "ding3.wav"
            If match = 14 Then
                Locate 70,4:Print " ";match;" ";
                Call txtBox 60, 15, 15, 3, "*","*","*"
                Call txtBox 61, 16, 13, 1, "*","*","*"
                Locate 63, 17:Print "You Win!!!!";
                'PlayWave "win.wav"
                playGame = playAgain()
            End If
            If match < 14 Then
                Locate 70,4:Print " ";match;" ";
                Call pressEnter
            End If
        Else
            Call pressEnter
            'erase exposed words
            Locate a(t1,1), a(t1,2):Print "   ";
            Locate a(t2,1), a(t2,2):Print "   ";
        End If
        'erase guessed numbers
        Locate 70, 10:Print "   ";
        Locate 70, 12:Print "   ";
    Wend
Wend

Call center "End of 'MainWin Memory Game'", 31
End

Sub pressEnter
    Locate 62, 15:Print "Press [ENTER]";
    Locate 63, 16:Input "to continue";e$
    Locate 62, 15:Print Space$(13);
    Locate 63, 16:Print Space$(Len(e$)+11);
End Sub

Sub setUp
    Cls
    pi=Acs(-1)
    a270 = pi*1.5
    a630 = pi*3.5
    Call txtBox 60, 1, 15, 1, "O", "o", "0"
    Locate 62, 2:Print "Guesses: 0"

    Call txtBox 60, 3, 15, 1, "O", "o", "0"
    Locate 62, 4:Print "Matched: 0"

    Call txtBox 60,  9, 15, 1, "O", "o", "0"
    Call txtBox 60, 11, 15, 1, "O", "o", "0"

    Call txtBox 23, 12, 11, 5,"O", "o", "0"
    Locate 26, 14:Print"MainWin"
    Locate 26, 15:Print"Memory"
    Locate 27, 16:Print"Game"
    count=1
    'draw big circle
    For i = a270 To a630 Step pi/8.95
        x = Cos(i)*26+27
        y = Sin(i)*13+14
        Call txtBox x, y, 5, 1, "O", "o", "0"
        a(count,1)=Int(x+2) : a(count,2)=Int(y+1)
        Locate x+3,y+3: Print count;
        count = count + 1
    Next
    'draw smaller circle
    For i = a270 To a630 Step pi/4.95
        x = Cos(i)*15+27
        y = Sin(i)*8+14
        Call txtBox x, y, 5, 1, "O", "o", "0"
        a(count,1)=Int(x+2) : a(count,2)=Int(y+1)
        Locate x+3,y+3: Print count;
        count = count + 1
    Next
    'choose from 1 of 2 word lists
    flip = rand(1,2)
    Select Case flip
        Case 1 : Restore [words1]
        Case 2 : Restore [words2]
    End Select
    'fill w$() array with word list and the a() array with index to words
    For i = 1 To 14
        Read tmp$
        w$(i) = tmp$
        a(i,0) = i    'fill a( 1,0) to a(14,0)
        a(i+14,0) = i 'fill a(15,0) to a(28,0)
    Next
    'scramble the word indices
    For i = 1 To 211
        r1 = rand(1,28)
        r2 = rand(1,28)
        temp = a(r1,0)
        a(r1,0) = a(r2,0)
        a(r2,0) = temp
    Next
[words1]
Data "Art","Bee","Car","Day","Ear","Fox","Gun","Hat","Ink","Jet","Kit","Lot","Mat","Nap"
[words2]
Data "Pop","Cat","Ran","Sun","Top","Ice","Vat","Wet","Dog","Yes","Zoo","Bat","Sit","Tip"
End Sub

Sub txtBox xPos, yPos, wide, high, corner$, top$, side$
'============================================================================
'= Draws a box using text characters specified by corner$, top$, and side$  =
'= Upper-left corner of box is positioned at xPos, yPos                     =
'= wide is number of characters to place inside of box                      =
'= high is number of lines of text to place inside of box                   =
'=                                                                          =
'= Printed box is 2 chars GREATER than wide & 2 lines GREATER than high     =
'=                                                                          =
'= Example:                                                                 =
'= A box 30 chars wide with 1 line of text will                             =
'= be 32 chars wide by 3 lines high                                         =
'=                                                                          =
'= xLoc, yLoc                                                               =
'=      \                                                                   =
'=       \          1         2         3                                   =
'=        \12345678901234567890123456789012 <--- Total box width = 32 chars =
'=       1 +------------------------------+                                 =
'=       2 |**Inside = 30 characters max**| <--- Total box height = 3 lines =                       |
'=       3 +------------------------------+                                 =
'=                                                                          =
'=            Font = Courier New - Extended ASCII characters                =
'= These chars can be typed in by holding down the ALT key while typing     =
'= in the 4 digit character code. Release the ALT key and the extended      =
'= character will appear at the current cursor position.                    =
'=    - Alt + 0164      - Alt + 0166      - Alt + 0167                   =
'=    - Alt + 0169      - Alt + 0171       Alt + 0176                   =
'=     Alt + 0186      - Alt + 0183      - Alt + 0187                   =
'============================================================================
    For i = 1 To wide
        hz$ = hz$ + top$
    Next
    Locate xPos, yPos
    Print corner$+hz$+corner$;
    For i = 1 To high
        Locate xPos, yPos+i
        Print side$;
        Locate xPos+wide+1, yPos+i
        Print side$;
    Next
    Locate xPos, yPos + high + 1
    Print corner$+hz$+corner$;
End Sub

Sub slide xLoc, yLoc, msg$, leftRight, delay
'============================================================================
'=  Slides text onto the screen to the left or right starting at the        =
'=  specified xLoc and yLoc. Direction is determined by the argument        =
'=  leftRight, where a zero value equals left, non-zero equals right.     =
'=  delay is measured in milliseconds (1/1000th of a second).               =
'============================================================================
'   minimum delay is 15 milliseconds
    If delay < 15 Then delay = 15
    For i = 1 To Len(msg$)
'       slide to the left
        If leftRight = 0 Then
'           check column for illegal value (<1)
            c = xLoc - i + 1
            If c < 1 Then Exit For
'           print 1 char at a time, from left to right
            Locate c, yLoc
            Print Left$(msg$, i);
        Else
'          slide from right to left, 1 char at a time
           Locate xLoc, yLoc
           Print Right$(msg$, i);
        End If
        Timer delay, [timerOff]
        Wait
        [timerOff]
        Timer 0
    Next
End Sub

Sub center msg$, yLoc
    xLoc = Int((80-Len(msg$))/2)
    Locate  xLoc, yLoc
    Print msg$;
End Sub

Sub pause mils
    Timer mils,[timerOff]
    Scan
    Wait
    [timerOff]
    Timer 0
End Sub

Function rand(lo,hi)
    rand = Int(Rnd(1)*(hi-lo+1))+lo
End Function

Function playAgain()
    Call txtBox 54, 26, 21, 1, "O", "o", "0"
    Locate 56, 27:Input "Play Again (Y/N) ";res$
    res$ = Left$(Upper$(res$),1)
    If res$ = "Y" Then playAgain=1 Else playAgain=0
End Function 
« Last Edit: Apr 29th, 2016, 2:34pm by AndyAmaya » User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Memory Game for the MainWin
« Reply #1 on: Apr 30th, 2016, 2:25pm »

Hi Andy,

I was curious about your game, so I copy/pasted the code into JB editor and just ran it (a couple of times I tried this).

Here is what shows up on my screen:
Output Quote:
OoooooO OoooooO OoooooO OoooooooooooooooO
0 0 0 0 0 0 0 Guesses: 0 0
OoooooO OoooooO OoooooO OoooooO OoooooooooooooooO
0 0 18 1 2 OoooooO 0 Matched: 0 0
OoooooO 0 0 OoooooooooooooooO
17 OoooooO OoooooO
OoooooO OoooooO 0 0 OoooooO 3 OoooooO
0 0 0 0 OoooooO 0 0 0 0
OoooooO OoooooO 19 OoooooO OoooooO OoooooooooooooooO
16 28 20 4 0 Tile 1: 0
OoooooO OoooooO OoooooO OoooooO OoooooooooooooooO
0 0 0 0 OoooooooooooO 0 0 0 0 0 0
OoooooO OoooooO 0 0 OoooooO OoooooO OoooooooooooooooO
15 27 0 MainWin 0 21 5
OoooooO 0 Memory 0
0 0 OoooooO 0 Game 0 OoooooO OoooooO
OoooooO 0 0 0 0 0 0 0 0
14 OoooooO OoooooooooooO OoooooO OoooooO
26 22 6
OoooooO OoooooO OoooooO OoooooO
0 0 0 0 OoooooO 0 0 0 0
OoooooO OoooooO 0 0 OoooooO OoooooO
13OoooooO 25 OoooooO 23 7
0 0 24 OoooooO
OoooooO 0 0
12 OoooooO OoooooO OoooooO OoooooO
0 0 0 0 0 0 8
OoooooO OoooooO OoooooO
11 10 9


No, no the above is all left aligned, not what I see in main win from JB editor.

I don't think this is what you intended. Does this code need a procedure from the previous thread referenced?

Or is this correct?

Append:

OK it must be some sort of Font thing.
When I used code tags and posted quote above, it looked like something in the preview screen, like a target with two rings of rectangle O's, not the scattered mess I see on my screen.

When I use quote tags, as shown above, all the mess is left aligned, also not what shows up on my JB screen from editor.

This forum output screen looks like what was intended! Code:
                 OoooooO  OoooooO OoooooO                  OoooooooooooooooO
                 0     0  0     0 0     0                  0 Guesses: 0    0
         OoooooO OoooooO  OoooooO OoooooO                  OoooooooooooooooO
         0     0    18       1       2    OoooooO          0 Matched: 0    0
         OoooooO                          0     0          OoooooooooooooooO
            17            OoooooO         OoooooO
   OoooooO       OoooooO  0     0 OoooooO    3  OoooooO
   0     0       0     0  OoooooO 0     0       0     0
   OoooooO       OoooooO     19   OoooooO       OoooooO    OoooooooooooooooO
      16            28               20            4       0 Tile 1:       0
OoooooO    OoooooO                      OoooooO    OoooooO OoooooooooooooooO
0     0    0     0    OoooooooooooO     0     0    0     0 0               0
OoooooO    OoooooO    0           0     OoooooO    OoooooO OoooooooooooooooO
   15         27      0  MainWin  0        21         5
OoooooO               0  Memory   0
0     0    OoooooO    0   Game    0     OoooooO    OoooooO
OoooooO    0     0    0           0     0     0    0     0
   14      OoooooO    OoooooooooooO     OoooooO    OoooooO
              26                           22         6
   OoooooO      OoooooO           OoooooO       OoooooO
   0     0      0     0  OoooooO  0     0       0     0
   OoooooO      OoooooO  0     0  OoooooO       OoooooO
      13OoooooO    25    OoooooO     23            7
        0     0             24            OoooooO
        OoooooO                           0     0
           12   OoooooO  OoooooO  OoooooO OoooooO
                0     0  0     0  0     0    8
                OoooooO  OoooooO  OoooooO
                   11       10       9

 

Aha! This must be what I am supposed to see from JB editor but don't.
« Last Edit: Apr 30th, 2016, 2:43pm by bplus » User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3635
xx Re: Memory Game for the MainWin
« Reply #2 on: Apr 30th, 2016, 2:45pm »

JB | Setup | Editor font

try to select monospaced font. Like
Courier
Courier New
Andale Mono
Lucida Console
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1255
xx Re: Memory Game for the MainWin
« Reply #3 on: Apr 30th, 2016, 2:50pm »

Oh, I like Courier New! smiley

Thanks Tsh!

This looks interesting... smiley
User IP Logged

B+
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls