Buttons access like an array

Post

Posted
Rating:
#1 (In Topic #227)
Trainee
 ==Newbie - programmed in visual basic for a while, Just installed Gambas3

I am writing a game where one of the elements is a 5 x 5 array. The elements in this array are placed by the player and are represented as buttons on the play field. I would like to refer to these button as field[x,y] where x and y number 1 to 5 (I will also be using x=0 for a stack of oncoming play items, so x=0 to 5 and y = 1 to 5 where x will represent distance left to right across the screen, and y= up and down:


|0,1|   |1,1||2,1||3,1||4,1||5,1|
|1,2|   |1,2||2,2||3,2||4,2||5,2|


Can I name my buttons field[0,1]  or something like that, and be able to display something on button 1,2 with : x=1
y=2
field[x,y].text = "[$]"  
Which would set the label on the button to [$]

Thanks for your help - sorry if this is not for getting help..
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Hi waspentalive,
I'm a VB.net developer and came from a background of VB6 (many many years ago…)
You are going to love Gambas and the learning curve is not too steep .

The function you need is the 'Group' property that you will see in all ( I think ?) GUI components.
If you click on the 'Group' property and expand the property information display on the left hand side of the screen you will see some very basic information.

In my example , I have set a group of buttons group name to ButtonArray.
In the GUI editor; when you click on any button in this group, Gambas automatically opens the code editor and instead of the Click function for the selected button you will get the group name click function.
so.. ButtonArray_Click().
This traps the click event of any of the buttons whose group name the same so you can code your requirements for them.

To do this , you use the Last function.
Last provides the control in the group that was last activated…by a click event in this case.

The attached example shows some of the properties that are accessible.
Use the checkbox to turn off the message with the clicked button data

I've also included a sub routine that deals directly with (any) object's properties
You can GET or SET any object property with this and it is quite powerful.

Thing to Note# -  The property name is case sensitive so if you write one that does not seem to work, check the name in the property for the control in the GUI editor and use the name exactly as displayed - took me a while to work that out. *sigh*

This example is to quickly prepare a form for validation after the user has entered data.
It will go through every control in a container ( normally a Frame or a Panel ) and then ensure that the identified controls are set to what I need.
The Trim(text) function is really handy as it ensures no extraneous spaces are included.
 

Code (gambas)

  1. Public Sub PrepareFormForValidation(InControl As Object)
  2.  
  3.   Dim ControlElement As Control
  4.  
  5.   For Each ControlElement In InControl.Children
  6.    ' The control may be a container so it may have children - do a recursive search
  7.     If ControlElement Is Frame Then PrepareFormForValidation(ControlElement)
  8.     If ControlElement Is Panel Then PrepareFormForValidation(ControlElement)
  9.  
  10.     If ControlElement Is Label Then Object.SetProperty(ControlElement, "ForeGround", Color.black)
  11.     If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
  12.     If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
  13.     If ControlElement Is RadioButton Then Object.SetProperty(ControlElement, "ForeGround", Color.black)
  14.     If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "ForeGround", Color.black)
  15.   Next
  16.   Message.Warning(Error.Text))
  17.  

Any questions, let me know.

Attachment

Button Array Example


Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Quinn, Thanks for your help - sorry it went way over my head - I don't get it at all :(  but that's ok because the original version of my game was written using just plain buttons (with each button checking the neighbors in a hard coded way) I will just do that again.

Anyone—
I went to start my project and now I have a question already - my OS is KDE (devuan to be exact) should I choose - a gtk flavor or QT?  I am not sure which KDE runs on, QT perhaps. There is also a general "graphical application" is that more general?
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Welcome to the forum: -

Anyone—
I went to start my project and now I have a question already - my OS is KDE (devuan to be exact) should I choose - a gtk flavor or QT? I am not sure which KDE runs on, QT perhaps.

If you are using KDE then Gambas will default to using QT4 or 5 as KDE is built using QT. If you look at menu item Project>Properties and click on Components you will see that Gambas has selected gb.gui which will switch between QT and GTK as necessary.

There is also a general "graphical application" is that more general?

The "graphical application" is the one you will probably use most of the time, well I do anyway!

I have also put together a bit of code for your 'Field' idea, see attached.

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
 Thanks all for the help so far  - I used the 'graphical application" this time too..

Next question - I have looked around at the variable declarations, I will need some global variables but I don't know where to declare them - I have tried above all my 'public sub' subroutines - I have tried in each subroutine and Gambas just says  "Unexpected Dim"

- hindsight note edit- I have tried both with DIM and without and both where you see it and inside the form.open…

This is my FMain.class file:
' Gambas class file

  Dim Static Public GameLevel As Integer
  Dim Static Public Iconstring[50] As String


Public Sub PushStack()
  
  ' add a new item to the top of the stack - dropping the bottom most away
  BtnStack1.text = BtnStack2.text
  BtnStack2.text = BtnStack3.text
  BtnStack3.text = BtnStack4.Text
  Btnstack4.text = BtnStack5.text
  BtnStack5.text = Iconstring[Rand(1, GameLevel * 7)]
  
End




Public Sub SetupGame()
  
  
  GameLevel = 1
  
  BtnField11.text = "…"
  BtnField12.text = "…"
  BtnField13.text = "…"
  BtnField14.text = "…"
  BtnField15.text = "…"
  BtnField21.text = "…"
  BtnField22.text = "…"
  BtnField23.text = "…"
  BtnField24.text = "…"
  BtnField25.text = "…"
  BtnField31.text = "…"
  BtnField32.text = "…"
  BtnField33.text = "…"
  BtnField34.text = "…"
  BtnField35.text = "…"
  
  
End
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
OH - I removed the DIM and now it seems to be working... strange.
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
stevedee is in the usergroup ‘Regular’

waspentalive said

…Next question - I have looked around at the variable declarations, I will need some global variables but I don't know where to declare them - I have tried above all my 'public sub' subroutines - I have tried in each subroutine and Gambas just says  "Unexpected Dim …

Generally, you declare a Global variable outside of any routine using "Public" not "Dim" for example:-

Code (gambas)

  1. Public myNumber As Integer

If you only need access from other routines in the same class you can use "Private". For example if you have written all your code that needs access to this variable in the FMain.class, then this will also work:-

Code (gambas)

  1. Private myNumber As Integer

…but this Private variable will not be accessible if you create a second class unless you access it like:-

Code (gambas)

  1. x = myClass2.myNumber

I think in VB6 you could create a static variable within a simple routine. This was handy where you wanted a local variable that was persistent. I'm not sure that this works in Gambas.
Online now: No Back to the top

Post

Posted
Rating:
#8
Trainee
 Here's another one -I may hate the answer but can one pass buttons as parameters for a subroutine?

Public button15_click()
   dobuttonclick(Button15, button10, button20)
end

Public dobuttonclick(center as button, top as button, bottom as button)

   if top.text  = bottom.text then
    center.text = "Matches"
  else
    center.text = "No Match"
  end if
end

So here there are lots of buttons, some are above others, some are below. at some point the user clicks a center button of a set of 3.  The button above and the button below are compared and the text is set properly of the button in the center (the one that was pressed).

I know I will hate the answer because I have already coded a bunch of buttons in my app and this would have simplified stuff a lot, I could have one block of code that all the buttons call just referring to different buttons as references.
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi waspentalive,

It might be easier to help you if you posted the code here so that we can see what you are trying to achieve.

Public button15_click()
dobuttonclick(Button15, button10, button20)
end

Yes this can be done but the other item with 'center.text' etc I'm not sure. Please post the code.
Online now: No Back to the top

Post

Posted
Rating:
#10
Trainee
– edit Now using gb tags as pointed out below

Tiles -

This is what I have so far… I need to implement the rest of my btnfield routines

There is also my main.form - I don't know how to show that to you yet.

It's a game - you have a stack of icons you can draw from. You place these in a 5x5 grid.  
When 2 adjacent elements on the grid contain the same icon - they both clear and you get points.
There are also other bonuses you can earn for more points.

You can also drop the next icon for free, but if you drop a 2nd time (or third…) it costs you 1/2 your current points.

As you progress the body of Icons in the stack grows (the number of kinds of icons) , making it harder to pair them up.

You will notice that the BtnFieldxx stanzas are all pretty much alike.

— edit —
Because the btnFieldxx stanzas are alike excepting which buttons they reference I was thinking it might be better to extract that code into a "DoButtonField" subroutine where the neighbor buttons are specified and which of them are edgebonus checks as well -

Code (gambas)

  1. public sub dobuttonfield ( center as button, north as button, northedge as boolean, south as button, southedge as boolean, east as button, east edge as boolean, west as button, westedge as boolean)
  2.  
  3.  
and probably some other parameters as well..  Then each button_click just calls dobuttonfield with the proper neighbors.


Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. ' Declarations for global variables
  5.  
  6.   Static Public GameLevel As Integer
  7.   Static Public GameScore As Integer
  8.   Static Public Iconstring[51] As String
  9.   Static Public DestroypPenalty As Boolean
  10.   Static Public lastfilled As Integer
  11.   Static Public ThisRound As Integer
  12.   Static Public EdgeBonus As Integer  
  13.  
  14.  
  15. Public Sub PushStack()
  16.  
  17.   ' add a new item to the top of the stack - dropping the bottom most away
  18.   Dialog.title = GameLevel  '<-- I just noticed this - what is it doing here?
  19.  
  20.   BtnStack1.text = BtnStack2.text
  21.   BtnStack2.text = BtnStack3.text
  22.   BtnStack3.text = BtnStack4.Text
  23.   Btnstack4.text = BtnStack5.text
  24.   BtnStack5.text = Iconstring[Rand(1, GameLevel * 7)]
  25.  
  26.   ThisRound = ThisRound - 1
  27.   If ThisRound = 0 Then
  28.     ThisRound = 49
  29.     GameLevel = GameLevel + 1
  30.     txbMessage.text = "Level UP!"
  31.     If GameLevel = 8 Then
  32.       endgame()
  33.     Endif
  34.  
  35. Public Sub endgame()
  36.  
  37.   Dim reply As Integer
  38.  
  39.   reply = Message("game is done - Your score is " & Str(GameScore) & "Play again?", "Yes", "No")
  40.   Select Case reply
  41.     Case 1
  42.       SetupGame()
  43.     Case 2
  44.       Quit
  45.  
  46.  
  47.  
  48.  
  49.  
  50. Public Sub SetupGame()
  51.  
  52.  
  53.   GameLevel = 1
  54.   GameScore = 0
  55.   LCDScore.text = Str(GameScore)
  56.   DestroypPenalty = False
  57.   lastfilled = 0
  58.   ThisRound = 49
  59.  
  60.   BtnField11.text = "..."
  61.   BtnField12.text = "..."
  62.   BtnField13.text = "..."
  63.   BtnField14.text = "..."
  64.   BtnField15.text = "..."
  65.  
  66.   BtnField21.text = "..."
  67.   BtnField22.text = "..."
  68.   BtnField23.text = "..."
  69.   BtnField24.text = "..."
  70.   BtnField25.text = "..."
  71.  
  72.   BtnField31.text = "..."
  73.   BtnField32.text = "..."
  74.   BtnField33.text = "..."
  75.   BtnField34.text = "..."
  76.   BtnField35.text = "..."
  77.  
  78.   BtnField41.text = "..."
  79.   BtnField42.text = "..."
  80.   BtnField43.text = "..."
  81.   BtnField44.text = "..."
  82.   BtnField45.text = "..."
  83.  
  84.   BtnField51.text = "..."
  85.   BtnField52.text = "..."
  86.   BtnField53.text = "..."
  87.   BtnField54.text = "..."
  88.   BtnField55.text = "..."
  89.  
  90.   PushStack()
  91.   PushStack()
  92.   PushStack()
  93.   PushStack()
  94.   PushStack()
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. Public Sub Form_Open()
  103.  
  104.  
  105.  
  106.   Iconstring[0] = "..."
  107.   Iconstring[1] = "]$["
  108.   Iconstring[2] = "]@["
  109.   Iconstring[3] = "]#["
  110.   Iconstring[4] = "]:["
  111.   Iconstring[5] = "]+["
  112.   Iconstring[6] = "]=["
  113.   Iconstring[7] = "]-["
  114.  
  115.   Iconstring[8] = ")$("
  116.   Iconstring[9] = ")@("
  117.   Iconstring[10] = ")#("
  118.   Iconstring[11] = "):("
  119.   Iconstring[12] = ")+("
  120.   Iconstring[13] = ")=("
  121.   Iconstring[14] = ")-("
  122.  
  123.   Iconstring[15] = "}$\{"
  124.   Iconstring[16] = "}@\{"
  125.   Iconstring[18] = "}#\{"
  126.   Iconstring[19] = "}:\{"
  127.   Iconstring[20] = "}+\{"
  128.   Iconstring[21] = "}=\{"
  129.   Iconstring[22] = "}-\{"
  130.  
  131.   Iconstring[23] = "[$]"
  132.   Iconstring[24] = "[@]"
  133.   Iconstring[25] = "[#]"
  134.   Iconstring[26] = "[:]"
  135.   Iconstring[27] = "[+]"
  136.   Iconstring[28] = "[=]"
  137.   Iconstring[29] = "[-]"
  138.  
  139.   Iconstring[30] = "($)"
  140.   Iconstring[31] = "(@)"
  141.   Iconstring[32] = "(#)"
  142.   Iconstring[33] = "(:)"
  143.   Iconstring[34] = "(+)"
  144.   Iconstring[35] = "(=)"
  145.   Iconstring[36] = "(-)"
  146.  
  147.   Iconstring[37] = "\{$}"
  148.   Iconstring[38] = "\{@}"
  149.   Iconstring[39] = "\{#}"
  150.   Iconstring[40] = "\{:}"
  151.   Iconstring[41] = "\{+}"
  152.   Iconstring[42] = "\{=}"
  153.   Iconstring[43] = "\{-}"
  154.  
  155.   Iconstring[44] = "|$|"
  156.   Iconstring[45] = "|@|"
  157.   Iconstring[46] = "|#|"
  158.   Iconstring[47] = "|:|"
  159.   Iconstring[48] = "|+|"
  160.   Iconstring[49] = "|=|"
  161.   Iconstring[50] = "|-|"
  162.  
  163.  
  164.   SetupGame()
  165.  
  166.  
  167.  
  168. Public Sub BtnStack1_Click()
  169.  
  170.   If DestroypPenalty Then
  171.     GameScore = Int(GameScore / 2)
  172.     LCDScore.text = Str(GameScore)
  173.   PushStack
  174.   DestroypPenalty = True
  175.  
  176.  
  177. Public Sub EmptyOrFull()
  178.  
  179.   Dim countofempty As Integer
  180.  
  181.   countofempty = 0
  182.  
  183.   If BtnField15.text = "..." Then countofempty += 1
  184.   If BtnField14.text = "..." Then countofempty += 1
  185.   If BtnField13.text = "..." Then countofempty += 1
  186.   If BtnField12.text = "..." Then countofempty += 1
  187.   If BtnField11.text = "..." Then countofempty += 1
  188.  
  189.  
  190.   If BtnField25.text = "..." Then countofempty += 1
  191.   If BtnField24.text = "..." Then countofempty += 1
  192.   If BtnField23.text = "..." Then countofempty += 1
  193.   If BtnField22.text = "..." Then countofempty += 1
  194.   If BtnField21.text = "..." Then countofempty += 1
  195.  
  196.  
  197.   If BtnField35.text = "..." Then countofempty += 1
  198.   If BtnField34.text = "..." Then countofempty += 1
  199.   If BtnField33.text = "..." Then countofempty += 1
  200.   If BtnField32.text = "..." Then countofempty += 1
  201.   If BtnField31.text = "..." Then countofempty += 1
  202.  
  203.  
  204.   If BtnField45.text = "..." Then countofempty += 1
  205.   If BtnField44.text = "..." Then countofempty += 1
  206.   If BtnField43.text = "..." Then countofempty += 1
  207.   If BtnField42.text = "..." Then countofempty += 1
  208.   If BtnField41.text = "..." Then countofempty += 1
  209.  
  210.  
  211.   If BtnField55.text = "..." Then countofempty += 1
  212.   If BtnField54.text = "..." Then countofempty += 1
  213.   If BtnField53.text = "..." Then countofempty += 1
  214.   If BtnField52.text = "..." Then countofempty += 1
  215.   If BtnField51.text = "..." Then countofempty += 1
  216.  
  217.   If countofempty = 25 Then
  218.     GameScore = 2 * GameScore
  219.     txbMessage.text = "BONUS - you cleared the board"
  220.     LCDScore.text = Str(GameScore)
  221.  
  222.   If countofempty = 0 Then
  223.     endgame
  224.  
  225.  
  226. Public Sub BtnField15_Click()
  227.  
  228.   Dim MatchCount As Integer
  229.  
  230.  
  231.   MatchCount = 0
  232.   EdgeBonus = 1
  233.  
  234.   If BtnField15.text <> "..." Then
  235.     txbMessage.text = "That is not empty"
  236.   Else
  237.  
  238.      
  239.     If lastfilled = 15 Then
  240.       txbMessage.text = "Multi-Click Bonus = 100"
  241.       GameScore = GameScore + 100
  242.       LCDScore.text = Str(GameScore)
  243.     Endif
  244.  
  245.     lastfilled = 15
  246.  
  247.     txbMessage.text = ""
  248.     BtnField15.text = BtnStack1.Text
  249.     PushStack
  250.  
  251.     MatchCount = 0
  252.  
  253.     'north
  254.     If BtnField11.text = BtnField15.Text Then
  255.       MatchCount = MatchCount + 1
  256.       EdgeBonus += 1
  257.       BtnField11.text = "..."
  258.     Endif
  259.  
  260.     'south
  261.     If BtnField14.text = BtnField15.Text Then
  262.       MatchCount = MatchCount + 1
  263.       BtnField14.Text = "..."
  264.     Endif
  265.    
  266.     'east
  267.     If BtnField25.text = BtnField15.Text Then
  268.       MatchCount = MatchCount + 1
  269.       BtnField25.Text = "..."
  270.     Endif
  271.  
  272.     'west
  273.     If BtnField55.text = BtnField15.Text Then
  274.       MatchCount = MatchCount + 1
  275.       EdgeBonus += 1
  276.       BtnField55.Text = "..."
  277.     Endif
  278.  
  279.     If MatchCount > 0 Then
  280.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  281.       BtnField15.Text = "..."
  282.       DestroypPenalty = False
  283.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  284.       LCDScore.text = Str(GameScore)
  285.     Endif
  286.  
  287.   EmptyOrFull
  288.  
  289. Public Sub BtnField14_Click()
  290.  
  291.   Dim MatchCount As Integer
  292.  
  293.  
  294.  
  295.   If BtnField14.text <> "..." Then
  296.     txbMessage.text = "That is not empty"
  297.   Else
  298.  
  299.      
  300.     If lastfilled = 14 Then
  301.       txbMessage.text = "Multi-Click Bonus = 100"
  302.       GameScore = GameScore + 100
  303.       LCDScore.text = Str(GameScore)
  304.     Endif
  305.  
  306.     lastfilled = 14
  307.  
  308.     txbMessage.text = ""
  309.     BtnField14.text = BtnStack1.Text
  310.     PushStack
  311.  
  312.     MatchCount = 0
  313.     EdgeBonus = 1
  314.      
  315.     'north
  316.     If BtnField15.text = BtnField14.Text Then
  317.       MatchCount = MatchCount + 1
  318.       BtnField15.text = "..."
  319.     Endif
  320.  
  321.     'south
  322.     If BtnField13.text = BtnField14.Text Then
  323.       MatchCount = MatchCount + 1
  324.       BtnField13.Text = "..."
  325.     Endif
  326.    
  327.     'east
  328.     If BtnField24.text = BtnField14.Text Then
  329.       MatchCount = MatchCount + 1
  330.       BtnField24.Text = "..."
  331.     Endif
  332.  
  333.     'west
  334.     If BtnField54.text = BtnField14.Text Then
  335.       MatchCount = MatchCount + 1
  336.       EdgeBonus += 1
  337.       BtnField54.Text = "..."
  338.     Endif
  339.  
  340.     If MatchCount > 0 Then
  341.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  342.       BtnField14.Text = "..."
  343.       DestroypPenalty = False
  344.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  345.       LCDScore.text = Str(GameScore)
  346.     Endif
  347.  
  348.   EmptyOrFull
  349.  
  350. Public Sub BtnField13_Click()
  351.  
  352.   Dim MatchCount As Integer
  353.  
  354.  
  355.   MatchCount = 0
  356.   EdgeBonus = 1
  357.  
  358.   If BtnField13.text <> "..." Then
  359.     txbMessage.text = "That is not empty"
  360.   Else
  361.  
  362.      
  363.     If lastfilled = 13 Then
  364.       txbMessage.text = "Multi-Click Bonus = 100"
  365.       GameScore = GameScore + 100
  366.       LCDScore.text = Str(GameScore)
  367.     Endif
  368.  
  369.     lastfilled = 13
  370.  
  371.     txbMessage.text = ""
  372.     BtnField13.text = BtnStack1.Text
  373.     PushStack
  374.  
  375.     MatchCount = 0
  376.  
  377.     'north
  378.     If BtnField14.text = BtnField13.Text Then
  379.       MatchCount = MatchCount + 1
  380.       BtnField14.text = "..."
  381.     Endif
  382.  
  383.     'south
  384.     If BtnField12.text = BtnField13.Text Then
  385.       MatchCount = MatchCount + 1
  386.       BtnField12.Text = "..."
  387.     Endif
  388.    
  389.     'east
  390.     If BtnField23.text = BtnField13.Text Then
  391.       MatchCount = MatchCount + 1
  392.       BtnField23.Text = "..."
  393.     Endif
  394.  
  395.     'west
  396.     If BtnField53.text = BtnField13.Text Then
  397.       MatchCount = MatchCount + 1
  398.       EdgeBonus += 1
  399.       BtnField53.Text = "..."
  400.     Endif
  401.  
  402.     If MatchCount > 0 Then
  403.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  404.       BtnField13.Text = "..."
  405.       DestroypPenalty = False
  406.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  407.       LCDScore.text = Str(GameScore)
  408.     Endif
  409.  
  410.   EmptyOrFull
  411.  
  412.  
  413.  
  414.  
  415. Public Sub BtnField12_Click()
  416.  
  417.   Dim MatchCount As Integer
  418.  
  419.  
  420.   MatchCount = 0
  421.   EdgeBonus = 1
  422.  
  423.   If BtnField12.text <> "..." Then
  424.     txbMessage.text = "That is not empty"
  425.   Else
  426.  
  427.      
  428.     If lastfilled = 12 Then
  429.       txbMessage.text = "Multi-Click Bonus = 100"
  430.       GameScore = GameScore + 100
  431.       LCDScore.text = Str(GameScore)
  432.     Endif
  433.  
  434.     lastfilled = 12
  435.  
  436.     txbMessage.text = ""
  437.     BtnField12.text = BtnStack1.Text
  438.     PushStack
  439.  
  440.     MatchCount = 0
  441.  
  442.     'north
  443.     If BtnField13.text = BtnField12.Text Then
  444.       MatchCount = MatchCount + 1
  445.       BtnField13.text = "..."
  446.     Endif
  447.  
  448.     'south
  449.     If BtnField11.text = BtnField12.Text Then
  450.       MatchCount = MatchCount + 1
  451.       BtnField11.Text = "..."
  452.     Endif
  453.    
  454.     'east
  455.     If BtnField22.text = BtnField12.Text Then
  456.       MatchCount = MatchCount + 1
  457.       BtnField22.Text = "..."
  458.     Endif
  459.  
  460.     'west
  461.     If BtnField52.text = BtnField12.Text Then
  462.       MatchCount = MatchCount + 1
  463.       EdgeBonus += 1
  464.       BtnField52.Text = "..."
  465.     Endif
  466.  
  467.     If MatchCount > 0 Then
  468.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  469.       BtnField12.Text = "..."
  470.       DestroypPenalty = False
  471.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  472.       LCDScore.text = Str(GameScore)
  473.     Endif
  474.  
  475.   EmptyOrFull
  476.  
  477.  
  478.  
  479.  
  480. Public Sub BtnField11_Click()
  481.  
  482.   Dim MatchCount As Integer
  483.  
  484.  
  485.   MatchCount = 0
  486.   EdgeBonus = 1
  487.  
  488.   If BtnField11.text <> "..." Then
  489.     txbMessage.text = "That is not empty"
  490.   Else
  491.  
  492.      
  493.     If lastfilled = 11 Then
  494.       txbMessage.text = "Multi-Click Bonus = 100"
  495.       GameScore = GameScore + 100
  496.       LCDScore.text = Str(GameScore)
  497.     Endif
  498.  
  499.     lastfilled = 11
  500.  
  501.     txbMessage.text = ""
  502.     BtnField11.text = BtnStack1.Text
  503.     PushStack
  504.  
  505.  
  506.     'north
  507.     If BtnField12.text = BtnField11.Text Then
  508.       MatchCount = MatchCount + 1
  509.       BtnField12.text = "..."
  510.     Endif
  511.  
  512.     'south
  513.     If BtnField15.text = BtnField11.Text Then
  514.       MatchCount = MatchCount + 1
  515.       EdgeBonus += 1
  516.       BtnField15.Text = "..."
  517.     Endif
  518.    
  519.     'east
  520.     If BtnField21.text = BtnField11.Text Then
  521.       MatchCount = MatchCount + 1
  522.       BtnField21.Text = "..."
  523.     Endif
  524.  
  525.     'west
  526.     If BtnField52.text = BtnField11.Text Then
  527.       MatchCount = MatchCount + 1
  528.       EdgeBonus += 1
  529.       BtnField53.Text = "..."
  530.     Endif
  531.  
  532.     If MatchCount > 0 Then
  533.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  534.       BtnField11.Text = "..."
  535.       DestroypPenalty = False
  536.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  537.       LCDScore.text = Str(GameScore)
  538.     Endif
  539.  
  540.   EmptyOrFull
  541.  
  542.  
  543.  
  544. Public Sub BtnField25_Click()
  545.  
  546.   Dim MatchCount As Integer
  547.  
  548.  
  549.   MatchCount = 0
  550.   EdgeBonus = 1
  551.  
  552.   If BtnField25.text <> "..." Then
  553.     txbMessage.text = "That is not empty"
  554.   Else
  555.  
  556.      
  557.     If lastfilled = 25 Then
  558.       txbMessage.text = "Multi-Click Bonus = 100"
  559.       GameScore = GameScore + 100
  560.       LCDScore.text = Str(GameScore)
  561.     Endif
  562.  
  563.     lastfilled = 25
  564.  
  565.     txbMessage.text = ""
  566.     BtnField25.text = BtnStack1.Text
  567.     PushStack
  568.  
  569.  
  570.     'north
  571.     If BtnField21.text = BtnField25.Text Then
  572.       MatchCount = MatchCount + 1
  573.       EdgeBonus += 1
  574.       BtnField21.text = "..."
  575.     Endif
  576.  
  577.     'south
  578.     If BtnField24.text = BtnField25.Text Then
  579.       MatchCount = MatchCount + 1
  580.       'EdgeBonus += 1
  581.       BtnField24.Text = "..."
  582.     Endif
  583.    
  584.     'east
  585.     If BtnField35.text = BtnField25.Text Then
  586.       MatchCount = MatchCount + 1
  587.       BtnField35.Text = "..."
  588.     Endif
  589.  
  590.     'west
  591.     If BtnField15.text = BtnField25.Text Then
  592.       MatchCount = MatchCount + 1
  593.       'EdgeBonus += 1
  594.       BtnField15.Text = "..."
  595.     Endif
  596.  
  597.     If MatchCount > 0 Then
  598.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  599.       BtnField25.Text = "..."
  600.       DestroypPenalty = False
  601.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  602.       LCDScore.text = Str(GameScore)
  603.     Endif
  604.  
  605.   EmptyOrFull
  606.  
  607.  
  608.  
  609. Public Sub BtnField24_Click()
  610.  
  611.   Dim MatchCount As Integer
  612.  
  613.  
  614.   MatchCount = 0
  615.   EdgeBonus = 1
  616.  
  617.   If BtnField24.text <> "..." Then
  618.     txbMessage.text = "That is not empty"
  619.   Else
  620.  
  621.      
  622.     If lastfilled = 24 Then
  623.       txbMessage.text = "Multi-Click Bonus = 100"
  624.       GameScore = GameScore + 100
  625.       LCDScore.text = Str(GameScore)
  626.     Endif
  627.  
  628.     lastfilled = 24
  629.  
  630.     txbMessage.text = ""
  631.     BtnField24.text = BtnStack1.Text
  632.     PushStack
  633.  
  634.  
  635.     'north
  636.     If BtnField25.text = BtnField24.Text Then
  637.       MatchCount = MatchCount + 1
  638.       'EdgeBonus += 1
  639.       BtnField25.text = "..."
  640.     Endif
  641.  
  642.     'south
  643.     If BtnField23.text = BtnField24.Text Then
  644.       MatchCount = MatchCount + 1
  645.       'EdgeBonus += 1
  646.       BtnField23.Text = "..."
  647.     Endif
  648.    
  649.     'east
  650.     If BtnField34.text = BtnField24.Text Then
  651.       MatchCount = MatchCount + 1
  652.       'EdgeBonus += 1
  653.       BtnField34.Text = "..."
  654.     Endif
  655.  
  656.     'west
  657.     If BtnField14.text = BtnField24.Text Then
  658.       MatchCount = MatchCount + 1
  659.       'EdgeBonus += 1
  660.       BtnField14.Text = "..."
  661.     Endif
  662.  
  663.     If MatchCount > 0 Then
  664.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  665.       BtnField24.Text = "..."
  666.       DestroypPenalty = False
  667.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  668.       LCDScore.text = Str(GameScore)
  669.     Endif
  670.  
  671.   EmptyOrFull
  672.  
  673.  
  674.  
  675. Public Sub BtnField23_Click()
  676.  
  677.   Dim MatchCount As Integer
  678.  
  679.  
  680.   MatchCount = 0
  681.   EdgeBonus = 1
  682.  
  683.   If BtnField23.text <> "..." Then
  684.     txbMessage.text = "That is not empty"
  685.   Else
  686.  
  687.      
  688.     If lastfilled = 23 Then
  689.       txbMessage.text = "Multi-Click Bonus = 100"
  690.       GameScore = GameScore + 100
  691.       LCDScore.text = Str(GameScore)
  692.     Endif
  693.  
  694.     lastfilled = 23
  695.  
  696.     txbMessage.text = ""
  697.     BtnField23.text = BtnStack1.Text
  698.     PushStack
  699.  
  700.  
  701.     'north
  702.     If BtnField24.text = BtnField23.Text Then
  703.       MatchCount = MatchCount + 1
  704.       'EdgeBonus += 1
  705.       BtnField24.text = "..."
  706.     Endif
  707.  
  708.     'south
  709.     If BtnField22.text = BtnField23.Text Then
  710.       MatchCount = MatchCount + 1
  711.       'EdgeBonus += 1
  712.       BtnField22.Text = "..."
  713.     Endif
  714.    
  715.     'east
  716.     If BtnField33.text = BtnField23.Text Then
  717.       MatchCount = MatchCount + 1
  718.       'EdgeBonus += 1
  719.       BtnField34.Text = "..."
  720.     Endif
  721.  
  722.     'west
  723.     If BtnField13.text = BtnField23.Text Then
  724.       MatchCount = MatchCount + 1
  725.       'EdgeBonus += 1
  726.       BtnField13.Text = "..."
  727.     Endif
  728.  
  729.     If MatchCount > 0 Then
  730.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  731.       BtnField23.Text = "..."
  732.       DestroypPenalty = False
  733.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  734.       LCDScore.text = Str(GameScore)
  735.     Endif
  736.  
  737.   EmptyOrFull
  738.  
  739.  
  740. Public Sub BtnField22_Click()
  741.  
  742.   Dim MatchCount As Integer
  743.  
  744.  
  745.   MatchCount = 0
  746.   EdgeBonus = 1
  747.  
  748.   If BtnField22.text <> "..." Then
  749.     txbMessage.text = "That is not empty"
  750.   Else
  751.  
  752.      
  753.     If lastfilled = 22 Then
  754.       txbMessage.text = "Multi-Click Bonus = 100"
  755.       GameScore = GameScore + 100
  756.       LCDScore.text = Str(GameScore)
  757.     Endif
  758.  
  759.     lastfilled = 22
  760.  
  761.     txbMessage.text = ""
  762.     BtnField24.text = BtnStack1.Text
  763.     PushStack
  764.  
  765.  
  766.     'north
  767.     If BtnField23.text = BtnField22.Text Then
  768.       MatchCount = MatchCount + 1
  769.       'EdgeBonus += 1
  770.       BtnField23.text = "..."
  771.     Endif
  772.  
  773.     'south
  774.     If BtnField21.text = BtnField22.Text Then
  775.       MatchCount = MatchCount + 1
  776.       'EdgeBonus += 1
  777.       BtnField21.Text = "..."
  778.     Endif
  779.    
  780.     'east
  781.     If BtnField32.text = BtnField22.Text Then
  782.       MatchCount = MatchCount + 1
  783.       'EdgeBonus += 1
  784.       BtnField32.Text = "..."
  785.     Endif
  786.  
  787.     'west
  788.     If BtnField12.text = BtnField22.Text Then
  789.       MatchCount = MatchCount + 1
  790.       'EdgeBonus += 1
  791.       BtnField12.Text = "..."
  792.     Endif
  793.  
  794.     If MatchCount > 0 Then
  795.       txbMessage.Text = Str$(MatchCount) & " Items Matched"
  796.       BtnField22.Text = "..."
  797.       DestroypPenalty = False
  798.       GameScore = GameScore + 100 * MatchCount * EdgeBonus
  799.       LCDScore.text = Str(GameScore)
  800.     Endif
  801.  
  802.   EmptyOrFull
  803.  
  804.  
  805.  
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Guru
cogier is in the usergroup ‘Guru’
To upload a file to this forum: -

In your File Manager locate your program folder, right click on it and select 'compress'. Save the file using 'tar.gz'.

Click on the 'Attachments' tab and click on 'Add files' button. Locate your compressed file and upload. Select 'display in line' and that's it.

I'll have a look at your program but it would be better if you could upload the whole program.

<IMG src="http://www.cogier.com/gambas/fileload.png"> </IMG>

When adding code to the forum use the 'gb' button rather than the '</>' button as it will make your code look much better: -

Using code: -

Code

Public Sub TextBoxEntry_KeyPress(Optional bTrigger As Boolean)

Using 'gb': -

Code (gambas)

  1. Public Sub TextBoxEntry_KeyPress(Optional bTrigger As Boolean)
Online now: No Back to the top

Post

Posted
Rating:
#12
Trainee
Here is what I have so far.

This is licensed under GNU v3 - find the latest copy of the GNU Public License at The GNU General Public License v3.0 - GNU Project - Free Software Foundation

Attachment

Partially complete Tiles game

Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Guru
cogier is in the usergroup ‘Guru’
I am not sure I fully understand the program but I have had a nice afternoon messing with the code. I apologise for my code layout, it's just that's how I like it. ;)

I have got the code down from 1170 lines to 275. I have added a logo. You can now resize the form and the font size will automatically resize. There is now a 'Edge Bonus' banner. When a matching pair is found you can now see the pair before they disappear. Note the use of 'Group' 'AllFieldButtons' for all the 'BtnField' buttons.

Things to watch for in your code: -
Only use 'Quit' in command line programs. In GUI programs use 'Me.Close' to close the form.
You can use 'Inc' (Increase) or 'Dec' (Decrease) to add or subtract 1 from a value.
So 'x = x + 1'  can be just 'Inc x'
There is no need to 'Dim x as Integer' and then set it value to 0, it's 0 already. You can do this if you want: -
'Dim x as Integer = 15'

If I have missed the point with some part of the program please let me know or if you want an explanation of any of the code let me know.

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#14
Trainee
 I wanted to run it, but I seem to be missing a 'spring' - something special in your environment?
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Guru
cogier is in the usergroup ‘Guru’
What version of Gambas are you using?

If it is earlier than 3.11.0 then you need to update. The 'Spring' feature was add in this version.

Close Gambas.
Copy the code below.

Code

sudo add-apt-repository -y ppa:gambas-team/gambas3 && sudo apt-get update && sudo apt-get -y install gambas3
Open a Terminal on you computer.
Paste in the code by right clicking in Terminal and selecting Paste.
Press [Enter]
Enter your password and press [Enter] (You may not see anything happening when you type your password but if you input it correctly all will be fine).
Lots of text will be created…….
When the above is finished restart Gambas.

This will give you access to the Gambas repository and update your version of Gambas to 3.12.2. It will also keep you updated when there are further updates.
Online now: No Back to the top

Post

Posted
Rating:
#16
Trainee
 I may have to distro hop away from Devuan, apearantly the current version (codename ascii) can't make use of that PPA..  Back to KDE Neon I suppose.

but not till my weekend (tues/wednesday)
Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Guru
cogier is in the usergroup ‘Guru’
OK I suggest Linux Mint 64bit with the Cinnamon desktop or Ubuntu 18.04 LTS or if you want KDE get Kubuntu 18.04.

However, here is the same code with no 'Springs'.

Attachment
Online now: No Back to the top
1 guest and 0 members have just viewed this.