Print
Parent Category: Development
Category: yab
Hits: 532

System: BeOS, Haiku, Zeta

To understand this tutorial you need to know and understand the first and second beginners tutorial.



Index

1. Prelog 6. The height score
2. The playing cards 7. The menu functions
3. The main structure 8. The complete source code
4. The playground 9. Epilogue
5. The game card functions 10. Download

 





1. We are create a game

In this Tutorial we will provide ourselves how to create a simple game. Here it goes not necessarily only around the game; we want to explain the complex structure behind a program like this. Naturally we will have an executable game at the end of this tutorial but we don’t add all aspects of ideas those are interesting of a game like this. Take it like a playground for your learning progress.

The Game is a conversion of the classic "Memory" game. Here it is valid to find all matching game cards, which lie covered before the player. The player search for pairs of game cards, if he found valid pairs they are get uncovered past this moment to the rest of the game. Only two cards may be uncovered at the same time. If the cards are not valid, they are covered again.

Before you are begin to write a game, you need to think over it exact. Simply to have the game before your eyes is not sufficient. Much dependence becomes only visible when trying out. Think about it is possible to create the game with the used programming language or about your knowledge of the programming language to do it. It often occurs that people discouraged and give up at the beginning.

Also this game, which we provided here for the Tutorial, get here exact range of the expirations developed only in the course of programming. This is a completely normal procedure, because you never know completely exactly what you must consider for a complex project like this. But we know that we can create a game like this with the language yab.

It is always helpful to paint the expirations as graphic, so you can control your development steps and status.


If you look exactly, there is no option for calling the Hightscore from the Hightscore representation. This is for example one of the dependence, which were mentioned above. In addition this graphic does not contain information about further dependence like the numbers of play courses they are included into the Hightscore information.

But we don't want to discourage or deter you with these possibly arising problems, we only want to show you that to create a game is more complex as you think it.

back to Index

 




2. The Game cards

Before we begin to developing the game, we want to create the game cards. It is always easier to create the game cards first by a game like this, because we can not necessarily always hold our self the real size of these before eyes. It naturally also always depends thereby on the motives we want to use. If there is for example landscapes, which one would like to show on the game cards, these should be larger, so that these become effective also correctly.

To select the correct graphics for such a game is not simple, because we need for these Tutorial eight different motives. All this motives should be topic-referred. We cannot take simple any graphic we want, for example from the internet, because they can be copyrighted by anyone. Often these graphics are protected with water-marks, which cannot be seen without the right software.

In order to go such difficulties out of the way, we create our own graphics from our private photo albums. For the game cards we need two motives for each card. They are one for the front side and one for the back side. The front side should be for all the same motive, so the player does not find the correct motives too simple. We decided to take graphics of animals in a size of 100 pixels in the width and 100 pixels in the height:

    

 

 

 

 

We create a folder named gfx in the game folder for the graphics. Into this folder we put all play card graphics and number them from 0 to 8. Picture0 is the front side and Picture1 to Picture8 the back sides.

back to Index




3. The main scructure

We begin with the main structure of the game. The following source code includes some dark red informations in order to make it easier to include some source informations into t he program code during the tutorial. Comes, for example a request to include a case command, insert him past the entry //cases. This makes it easier for me to explain it your.

#!/boot/home/config/bin/yab

//get infos
D_Width = peek("desktopwidth")
D_Height = peek("desktopheight")

//yab info
if (peek("isbound")) then
   Programfolder$ = peek$("directory")
else
   Programfolder$=system$("pwd")
   Programfolder$ = left$(Programfolder$, len(Programfolder$)-1)
fi

//variable
Graphicfolder$=Programfolder$+"/gfx/"
clicks=0
gamecount=0
status=0

//program window

WINDOW OPEN D_Width/2-250,D_Height/2-250 to D_Width/2+250,D_Height/2+250, "Mainwindow", "Memory Game"
   WINDOW SET "Mainwindow", "Flags", "Not-Resizable,Not-Zoomable"
      MENU "File", "Quit", "Q", "Mainwindow"
      MENU "Game", "New Game", "N", "Mainwindow"
      MENU "Game", "Hightscore", "H", "Mainwindow"

//call function

//main loop
dim part$(1)
inloop = true
while(inloop)
   msg$ = message$
   if (split(msg$, part$(), ":|") > 2) then
      PartOne$=part$(1)
      PartTwo$ = part$(2)
      PartThree$ = part$(3)
   fi
   if (msg$ <> "") print msg$
   switch msg$

   //cases

   default:
   end switch
   if(window count<1) inloop = false
   sleep 0.1
wend

//sub routines


As you can see, contain this source nothing new, because the same we learned to know in the two beginners tutorials.

back to Index

 
4. The Playground

Since this is to become a simple game we use a simple method to display the game cards. The dimpliest method to display the game cards is to use the Button command.

Enter following Code at //sub routines:

sub Program_Window()
   View$="GameTable"
   VIEW 0,15 TO 500, 495, "GameTable", "Mainwindow"
   VIEW 10,10 TO 120,120, "Button1", "GameTable"
   BUTTON IMAGE 5,5, "B_1", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button1"
   VIEW 130,10 TO 240,120, "Button2", "GameTable"
   BUTTON IMAGE 5,5, "B_2", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button2"
   VIEW 250,10 TO 360,120, "Button3", "GameTable"
   BUTTON IMAGE 5,5, "B_3", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button3"
   VIEW 370,10 TO 480,120, "Button4", "GameTable"
   BUTTON IMAGE 5,5, "B_4", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button4"
   VIEW 10,130 TO 120,240, "Button5", "GameTable"
   BUTTON IMAGE 5,5, "B_5", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button5"
   VIEW 130,130 TO 240,240, "Button6", "GameTable"
   BUTTON IMAGE 5,5, "B_6", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button6"
   VIEW 250,130 TO 360,240, "Button7", "GameTable"
   BUTTON IMAGE 5,5, "B_7", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button7"
   VIEW 370,130 TO 480,240, "Button8", "GameTable"
   BUTTON IMAGE 5,5, "B_8", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button8"
   VIEW 10,250 TO 120,360, "Button9", "GameTable"
   BUTTON IMAGE 5,5, "B_9", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button9"
   VIEW 130,250 TO 240,360, "Button10", "GameTable"
   BUTTON IMAGE 5,5, "B_10", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button10"
   VIEW 250,250 TO 360,360, "Button11", "GameTable"
   BUTTON IMAGE 5,5, "B_11", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button11"
   VIEW 370,250 TO 480,360, "Button12", "GameTable"
   BUTTON IMAGE 5,5, "B_12", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button12"
   VIEW 10,370 TO 120,480, "Button13", "GameTable"
   BUTTON IMAGE 5,5, "B_13", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button13"
   VIEW 130,370 TO 240,480, "Button14", "GameTable"
   BUTTON IMAGE 5,5, "B_14", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button14"
   VIEW 250,370 TO 360,480, "Button15", "GameTable"
   BUTTON IMAGE 5,5, "B_15", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button15"
   VIEW 370,370 TO 480,480, "Button16", "GameTable"
   BUTTON IMAGE 5,5, "B_16", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button16"
end sub


To display the playground we call at //call function the subroutine for it. Enter at this position the name of the subroutine Program_Window().

back to Index



5. The game card functions

Now next we come to the really interesting part of the game process. Here we need to compare the two game cards and determine needed informations for it. We need several informations, the name of the Views and the buttons, the position of the views and the number of the respective graphic.

Enter following code at //cases:

case "B_1|"
   BuView$="Button1"
   Button$="B_1"
   horizontal1=10
   vertical1=10
   horizontal2=120
   vertical2=120
   PictureNr=1
   PicSelection()
break

This is the first of sixteen Buttons, so we need to do the same for the other fifteen buttons. Get the needed informations from the playground (horizontal and vertical position, name of the view and Buttons, number of the picture).

We come now to the subroutine. Add following code at //sub routines:

 

sub PicSelection()
   VIEW REMOVE BuView$
   VIEW horizontal1,vertical1 TO horizontal2,vertical2, BuView$, "GameTable"
   err = DRAW IMAGE 5,5 TO 105,105, Graphicfolder$+"picture"+str$(PictureNr)+".png", BuView$
   clicks=clicks+1
   if(clicks=1)then
      Card1$="picture"+str$(PictureNr)+".png"
      Card_Button1$=Button$
      Card_horizontal1=horizontal1
      Card_vertical1=vertical1
      Card_horizontal2=horizontal2
      Card_vertical2=vertical2
      CardView1$=BuView$
   elseif(clicks=2)then
      Card2$="picture"+str$(PictureNr)+".png"
      Card_Button2$=Button$
      Card_horizontal3=horizontal1
      Card_vertical3=vertical1
      Card_horizontal4=horizontal2
      Card_vertical4=vertical2
      CardView2$=BuView$
   fi
   if(clicks=2)then
      if(Card1$=Card2$)then
         status=status+1
         gamecourse=gamecourse+1
         if(status=8)then
            window open D_Width/2-120,D_Height/2-70 to D_Width/2+120,D_Height/2+70, "Status", "Won"
            WINDOW SET "Status", "Look", "Modal"
            WINDOW SET "Status", "Flags", "Not-Resizable,Not-Zoomable"
            DRAW SET "system-bold", "Status"
            DRAW TEXT 10,15, "You have Won!!!", "Status"
            DRAW SET "system-plain", "Status"
            DRAW TEXT 10,45, "Rounds: "+str$(gamecourse), "Status"
            TEXTCONTROL 10,50 TO 230,40, "Player_Name", "Enter Name:", "", "Status"
            BUTTON 60,100 TO 180,110, "Save", "Save", "Status"
         fi
      else
         gamecourse=gamecourse+1
         wait 0.5
         VIEW REMOVE CardView1$
         VIEW REMOVE CardView2$
         VIEW Card_horizontal1,Card_vertical1 TO Card_horizontal2,Card_vertical2, CardView1$, "GameTable"
         BUTTON IMAGE 5,5, Card_Button1$, Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, CardView1$
         VIEW Card_horizontal3,Card_vertical3 TO Card_horizontal4,Card_vertical4, CardView2$, "GameTable"
         BUTTON IMAGE 5,5, Card_Button2$, Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, CardView2$
      fi
      clicks=0
   fi
end sub


We work on the information we defined at the buttons. We use at all button the same variable names so we can use these together also for all. Using this saves many lines of code, so the source will be more clearly. Try always to work like this.


We use the IF Querie to get all needed informations to compare the two selected game cards. The following If Querie is to decide the next step. If are the game cards identically they will be viewable for the rest of the game. If they are not identically the graphics will be covered again.

Back to Index

6. The Hightscore

We come back to that briefly addressed IF Querie at The game card functions. Here starts the querie then the number variable status has the value 8:

if(status=8)then
   window open D_Width/2-120,D_Height/2-70 to D_Width/2+120,D_Height/2+70, "Status", "Won"
   WINDOW SET "Status", "Look", "Modal"
   WINDOW SET "Status", "Flags", "Not-Resizable,Not-Zoomable"
   DRAW SET "system-bold", "Status"
   DRAW TEXT 10,15, "You have won!!!", "Status"
   DRAW SET "system-plain", "Status"
   DRAW TEXT 10,45, "Rounds: "+str$(gamecourse), "Status"
   TEXTCONTROL 10,50 TO 230,40, "Player_Name", "Enter Name:", "", "Status"
   BUTTON 60,100 TO 180,110, "Save", "Save", "Status"
fi


If this is the case, a new window in the middle of the screen is opened. Here again the two variables (D_Width and D_Height) are used for the window position. On this view we draw a text and add a Textcontrol and a Button. Here the player is requested to enter his name into the Textcontrol in order to save it using the Save button into the height score. You know this from the beginners tutorial.

To make the button useable, add following code at //cases:

case "Save|"
   Player_Name$ = TEXTCONTROL GET$ "Player_Name"
   write=open(Programfolder$+"/Hightscore.data", "a")
      print #anlegen str$(gamecource)+";"+Player_Name$
   close(write)
   Output$=System$("sort -g "+Programfolder$+"/Hightscore.data > "+Programfolder$+"/Hightscore.temp")
   Output$=System$("rm "+Programfolder$+"/Hightscore.data")
   Output$=system$("cp "+Programfolder$+"/Hightscore.temp "+Programfolder$+"/Hightscore.data")
   Output$=System$("rm "+Programfolder$+"/Hightscore.temp")
   WINDOW CLOSE "Status"
   VIEW REMOVE "GameTable"
   Hightscore()
break

If you stores the data by this way, all saved informations of the players will be back added. But we want to store all saved data in alphabetical order. One of the simplest methods to make this is to use the Shell command sort.

sub Hightscore()
   View$="Hightscore"
   MENU SET "Game", "Hightscore", "Disable", "Mainwindow"
   VIEW 0,15 TO 500, 495, "Hightscore", "Mainwindow"
   DRAW SET "system-bold", "Hightscore"
   DRAW TEXT 20,50, "Hightscore", "Hightscore"
   DRAW SET "system-plain", "Hightscore"
   Spielstaende$=Programfolder$+"/Hightscore.data"
   x=0
   auslesen=open(Spielstaende$, "r")
   while (not EOF(auslesen))
      line input #auslesen b$
      dim elements$(1)
      numElements = split(b$, elements$(), ";")
      for i = 1 to numElements
         x=x+1
         dim d$(x)
         d$(x) = elements$(i)
      next i
   wend
   close(auslesen)
   height=100
   aa=1
   for a = 1 to x/2
      DRAW TEXT 20,height, d$(aa), "Hightscore"
      aa=aa+2
      height=height+20
   next a
   height=100
   bb=2
   for b = 1 to x/2
      DRAW TEXT 120,height, d$(bb), "Hightscore"
      bb=bb+2
   height=height+20
   next b
end sub

The first step is done for representing the Hightscore. Subsequently we need to display the content of the Array elements$() on the View "Hightscore" to represent. The most important informations we need for this are the position of the text on the view. Here you need to try out the right position before you find the best look for the text:


Back to Index

 

7. Menu options

Now we want to make the menu options executable. Add following code at the area //cases:

case "Mainwindow:Game:Hightscore|"
   VIEW REMOVE "GameTable"
   Hightscore()
break

case "Mainwindow:Game:New Game|"
   MENU SET "Game", "Hightscore", "Enable", "Mainwindow"
   VIEW REMOVE View$
   clicks=0
   gamecource=0
   status=0
   Program_Window()
break

We have two Cases. Where are an option to call the Heightscore and another one to start a new game.


Then the player select the option for a new game we need to put back some number variables and activating the inactive menu options:

and the status.

Back to Index


8. The complete Sourcecode

#!/boot/home/config/bin/yab

D_Width = peek("desktopwidth")
D_Height = peek("desktopheight")

if (peek("isbound")) then
   Programfolder$ = peek$("directory")
else
   Programfolder$=system$("pwd")
   Programfolder$ = left$(Programfolder$, len(Programfolder$)-1)
fi

Graphicfolder$=Programfolder$+"/gfx/"

clicks=0
Gamecourse=0
status=0

WINDOW OPEN D_Width/2-250,D_Height/2-250 to D_Width/2+250,D_Height/2+250, "Mainwindow", "Memory Game"
   WINDOW SET "Mainwindow", "Flags", "Not-Resizable,Not-Zoomable"
      MENU "File", "Quit", "Q", "Mainwindow"
      MENU "Game", "New Game", "N", "Mainwindow"
      MENU "Game", "Hightscore", "H", "Mainwindow"

Program_Window()

dim part$(1)
inloop = true
while(inloop)
   msg$ = message$
   if (split(msg$, part$(), ":|") > 2) then
      PartOne$=part$(1)
      PartTwo$ = part$(2)
      PartThree$ = part$(3)
   fi
   if (msg$ <> "") print msg$
   switch msg$

case "Mainwindow:File:Quit|"
   WINDOW CLOSE "Mainwindow"
break

case "Mainwindow:_QuitRequested|"
   WINDOW CLOSE "Mainwindow"
break

case "B_1|"
   BuView$="Button1"
   Button$="B_1"
   horizontal1=10
   vertical1=10
   horizontal2=120
   vertical2=120
   PictureNr=1
   PictureSelected()
break
case "B_2|"
   BuView$="Button2"
   Button$="B_2"
   horizontal1=130
   vertical1=10
   horizontal2=240
   vertical2=120
   PictureNr=2
   PictureSelected()
break
case "B_3|"
   BuView$="Button3"
   Button$="B_3"
   horizontal1=250
   vertical1=10
   horizontal2=360
   vertical2=120
   PictureNr=3
   PictureSelected()
break
case "B_4|"
   BuView$="Button4"
   Button$="B_4"
   horizontal1=370
   vertical1=10
   horizontal2=480
   vertical2=120
   PictureNr=4
   PictureSelected()
break
case "B_5|"
   BuView$="Button5"
   Button$="B_5"
   horizontal1=10
   vertical1=130
   horizontal2=120
   vertical2=240
   PictureNr=5
   PictureSelected()
break
case "B_6|"
   BuView$="Button6"
   Button$="B_6"
   horizontal1=130
   vertical1=130
   horizontal2=240
   vertical2=240
   PictureNr=6
   PictureSelected()
break
case "B_7|"
   BuView$="Button7"
   Button$="B_7"
   horizontal1=250
   vertical1=130
   horizontal2=360
   vertical2=240
   PictureNr=7
   PictureSelected()
break
case "B_8|"
   BuView$="Button8"
   Button$="B_8"
   horizontal1=370
   vertical1=130
   horizontal2=480
   vertical2=240
   PictureNr=8
   PictureSelected()
break
case "B_9|"
   BuView$="Button9"
   Button$="B_9"
   horizontal1=10
   vertical1=250
   horizontal2=120
   vertical2=360
   PictureNr=8
   PictureSelected()
break
case "B_10|"
   BuView$="Button10"
   Button$="B_10"
   horizontal1=130
   vertical1=250
   horizontal2=240
   vertical2=360
   PictureNr=7
   PictureSelected()
break
case "B_11|"
   BuView$="Button11"
   Button$="B_11"
   horizontal1=250
   vertical1=250
   horizontal2=360
   vertical2=360
   PictureNr=6
   PictureSelected()
break
case "B_12|"
   BuView$="Button12"
   Button$="B_12"
   horizontal1=370
   vertical1=250
   horizontal2=480
   vertical2=360
   PictureNr=5
   PictureSelected()
break
case "B_13|"
   BuView$="Button13"
   Button$="B_13"
   horizontal1=10
   vertical1=370
   horizontal2=120
   vertical2=480
   PictureNr=4
   PictureSelected()
break
case "B_14|"
   BuView$="Button14"
   Button$="B_14"
   horizontal1=130
   vertical1=370
   horizontal2=240
   vertical2=480
   PictureNr=3
   PictureSelected()
break
case "B_15|"
   BuView$="Button15"
   Button$="B_15"
   horizontal1=250
   vertical1=370
   horizontal2=360
   vertical2=480
   PictureNr=2
   PictureSelected()
break
case "B_16|"
   BuView$="Button16"
   Button$="B_16"
   horizontal1=370
   vertical1=370
   horizontal2=480
   vertical2=480
   PictureNr=1
   PictureSelected()
break

case "Save|"
   Player_Name$ = TEXTCONTROL GET$ "Player_Name"
   anlegen=open(Programfolder$+"/Hightscore.data", "a")
      print #anlegen str$(Gamecourse)+";"+Player_Name$
   close(anlegen)
   Output$=System$("sort -g "+Programfolder$+"/Hightscore.data > "+Programfolder$+"/Hightscore.temp")
   Output$=System$("rm "+Programfolder$+"/Hightscore.data")
   Output$=system$("cp "+Programfolder$+"/Hightscore.temp "+Programfolder$+"/Hightscore.data")
   Output$=System$("rm "+Programfolder$+"/Hightscore.temp")
   WINDOW CLOSE "Status"
   VIEW REMOVE "GameTable"
   Hightscore()
break

case "Mainwindow:Game:Hightscore|"
   VIEW REMOVE "GameTable"
   Hightscore()
break

case "Mainwindow:Game:New Game|"
   MENU SET "Game", "Hightscore", "Enable", "Mainwindow"
   VIEW REMOVE View$
   clicks=0
   Gamecourse=0
   status=0
   Program_Window()
break

   default:
   end switch
   if(window count<1) inloop = false
   sleep 0.1
wend

sub Program_Window()
   View$="GameTable"
   VIEW 0,15 TO 500, 495, "GameTable", "Mainwindow"
   VIEW 10,10 TO 120,120, "Button1", "GameTable"
   BUTTON IMAGE 5,5, "B_1", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button1"
   VIEW 130,10 TO 240,120, "Button2", "GameTable"
   BUTTON IMAGE 5,5, "B_2", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button2"
   VIEW 250,10 TO 360,120, "Button3", "GameTable"
   BUTTON IMAGE 5,5, "B_3", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button3"
   VIEW 370,10 TO 480,120, "Button4", "GameTable"
   BUTTON IMAGE 5,5, "B_4", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button4"
   VIEW 10,130 TO 120,240, "Button5", "GameTable"
   BUTTON IMAGE 5,5, "B_5", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button5"
   VIEW 130,130 TO 240,240, "Button6", "GameTable"
   BUTTON IMAGE 5,5, "B_6", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button6"
   VIEW 250,130 TO 360,240, "Button7", "GameTable"
   BUTTON IMAGE 5,5, "B_7", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button7"
   VIEW 370,130 TO 480,240, "Button8", "GameTable"
   BUTTON IMAGE 5,5, "B_8", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button8"
   VIEW 10,250 TO 120,360, "Button9", "GameTable"
   BUTTON IMAGE 5,5, "B_9", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button9"
   VIEW 130,250 TO 240,360, "Button10", "GameTable"
   BUTTON IMAGE 5,5, "B_10", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button10"
   VIEW 250,250 TO 360,360, "Button11", "GameTable"
   BUTTON IMAGE 5,5, "B_11", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button11"
   VIEW 370,250 TO 480,360, "Button12", "GameTable"
   BUTTON IMAGE 5,5, "B_12", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button12"
   VIEW 10,370 TO 120,480, "Button13", "GameTable"
   BUTTON IMAGE 5,5, "B_13", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button13"
   VIEW 130,370 TO 240,480, "Button14", "GameTable"
   BUTTON IMAGE 5,5, "B_14", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button14"
   VIEW 250,370 TO 360,480, "Button15", "GameTable"
   BUTTON IMAGE 5,5, "B_15", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button15"
   VIEW 370,370 TO 480,480, "Button16", "GameTable"
   BUTTON IMAGE 5,5, "B_16", Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, "Button16"
end sub

sub PictureSelected()
   VIEW REMOVE BuView$
   VIEW horizontal1,vertical1 TO horizontal2,vertical2, BuView$, "GameTable"
   err = DRAW IMAGE 5,5 TO 105,105, Graphicfolder$+"picture"+str$(PictureNr)+".png", BuView$
   clicks=clicks+1
   if(clicks=1)then
      Card1$="picture"+str$(PictureNr)+".png"
      Card_Button1$=Button$
      Card_horizontal1=horizontal1
      Card_vertical1=vertical1
      Card_horizontal2=horizontal2
      Card_vertical2=vertical2
      CardView1$=BuView$
   elseif(clicks=2)then
      Card2$="picture"+str$(PictureNr)+".png"
      Card_Button2$=Button$
      Card_horizontal3=horizontal1
      Card_vertical3=vertical1
      Card_horizontal4=horizontal2
      Card_vertical4=vertical2
      CardView2$=BuView$
   fi
   if(clicks=2)then
      if(Card1$=Card2$)then
         status=status+1
         gamecourse=gamecourse+1
         if(status=8)then
            window open D_Width/2-120,D_Height/2-70 to D_Width/2+120,D_Height/2+70, "Status", "Won"
            WINDOW SET "Status", "Look", "Modal"
            WINDOW SET "Status", "Flags", "Not-Resizable,Not-Zoomable"
            DRAW SET "system-bold", "Status"
            DRAW TEXT 10,15, "You have Won!!!", "Status"
            DRAW SET "system-plain", "Status"
            DRAW TEXT 10,45, "Rounds: "+str$(Gamecourse), "Status"
            TEXTCONTROL 10,50 TO 230,40, "Player_Name", "Enter Name:", "", "Status"
            BUTTON 60,100 TO 180,110, "Save", "Save", "Status"
         fi
      else
         Gamecourse=Gamecourse+1
         wait 0.5
         VIEW REMOVE CardView1$
         VIEW REMOVE CardView2$
         VIEW Card_horizontal1,Card_vertical1 TO Card_horizontal2,Card_vertical2, CardView1$, "GameTable"
         BUTTON IMAGE 5,5, Card_Button1$, Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, CardView1$
         VIEW Card_horizontal3,Card_vertical3 TO Card_horizontal4,Card_vertical4, CardView2$, "GameTable"
         BUTTON IMAGE 5,5, Card_Button2$, Graphicfolder$+"picture0.png", Graphicfolder$+"picture0.png", Disabled$, CardView2$
      fi
      clicks=0
   fi
end sub

sub Hightscore()
   View$="Hightscore"
   MENU SET "Game", "Hightscore", "Disable", "Mainwindow"
   VIEW 0,15 TO 500, 495, "Hightscore", "Mainwindow"
   DRAW SET "system-bold", "Hightscore"
   DRAW TEXT 20,50, "Hightscore", "Hightscore"
   DRAW SET "system-plain", "Hightscore"
   Spielstaende$=Programfolder$+"/Hightscore.data"
   x=0
   auslesen=open(Spielstaende$, "r")
   while (not EOF(auslesen))
      line input #auslesen b$
      dim elements$(1)
      numElements = split(b$, elements$(), ";")
      for i = 1 to numElements
         x=x+1
         dim d$(x)
         d$(x) = elements$(i)
      next i
   wend
   close(auslesen)
   height=100
   aa=1
   for a = 1 to x/2
      DRAW TEXT 20,height, d$(aa), "Hightscore"
      aa=aa+2
      height=height+20
   next a
   height=100
   bb=2
   for b = 1 to x/2
      DRAW TEXT 120,height, d$(bb), "Hightscore"
      bb=bb+2
   height=height+20
   next b
end sub

Back to Index


9. Epilog

Now we have an completely functioning MEMORY game. But we have a big failure into this game. It is not a failure that makes the game not playable but something you can make better.

The game card displayed covered but they are every time on the same place. Here the game needs a random function to place the covered graphics every time the game starts on another position.

How to do this is not part of this tutorial. I don’t plan an extension of this tutorial at the moment.

Back to Index



10. Download

Here you can download the game in compiled version..

Back to Index


 

Translation by Christian Albrecht (Lelldorin) April 2009
Tutorial by Christian Albrecht (Lelldorin) December 2007
Made available by BeSly, the BeOS, Haiku and Zeta knowledge base.