473,800 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

button matching game: how to check to see if two buttons have matching tags

1 New Member
I am building a simple card matching game where the user picks two buttons on a form out of a group of buttons in an attempt to find a match. I have already taken care of the randomization needed to make each game different, but I can't figure out how to check to see if the cards match.

Pseudocode:
Expand|Select|Wrap|Line Numbers
  1. when any one of a group of buttons is pressed
  2.   set button's text = button's tag
  3.   note the button's tag
  4.   search point array for tag, and note the other tag needed for a match
  5.   set game to a "looking for match" state to true
  6.  
  7. then
  8.  
  9. when the next button is pressed
  10.   set button's text = button's tag
  11.   note the button's tag
  12.   see if the current button's tag matches the tag needed for a match
  13.   if it does
  14.     set both this button and the first button clicked to enabled = false
  15.   else if it doesn't
  16.     set both this button and the first button clicked text back to (blank)
  17.   set game to a "looking for match" state to false
  18.  
The main problem I am having is figuring out a way to run code based on "any button of a group of buttons" being clicked. The 24 buttons on the form are named button_01..butt on_20 - surely there is a cleaner way to do this than write the code 20 times, once for each button? Perhaps something like "if a button with the name button_{x}{y} is clicked, do this, where x = 0-2 and y = 0-9?

I believe I have the rest of the game worked out - just can't figure out how to get that first step out of the way!

Thanks in advance for any help you can offer - even if it's to say "you are going about his all wrong!", which could easily be the case.
Mar 6 '07 #1
1 1856
bobneedshelp
17 New Member
I am building a simple card matching game where the user picks two buttons on a form out of a group of buttons in an attempt to find a match. I have already taken care of the randomization needed to make each game different, but I can't figure out how to check to see if the cards match.

Pseudocode:
Expand|Select|Wrap|Line Numbers
  1. when any one of a group of buttons is pressed
  2.   set button's text = button's tag
  3.   note the button's tag
  4.   search point array for tag, and note the other tag needed for a match
  5.   set game to a "looking for match" state to true
  6.  
  7. then
  8.  
  9. when the next button is pressed
  10.   set button's text = button's tag
  11.   note the button's tag
  12.   see if the current button's tag matches the tag needed for a match
  13.   if it does
  14.     set both this button and the first button clicked to enabled = false
  15.   else if it doesn't
  16.     set both this button and the first button clicked text back to (blank)
  17.   set game to a "looking for match" state to false
  18.  
The main problem I am having is figuring out a way to run code based on "any button of a group of buttons" being clicked. The 24 buttons on the form are named button_01..butt on_20 - surely there is a cleaner way to do this than write the code 20 times, once for each button? Perhaps something like "if a button with the name button_{x}{y} is clicked, do this, where x = 0-2 and y = 0-9?

I believe I have the rest of the game worked out - just can't figure out how to get that first step out of the way!

Thanks in advance for any help you can offer - even if it's to say "you are going about his all wrong!", which could easily be the case.
Two ways
Give the button an attribute of card. Match the card attribute.

Make a card array and assign each button a card in the array.
if the two buttons match the same card then there's a match.

Use some OOP so the code isn't being re-used.
Mar 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1510
by: Ruskin | last post by:
Is there an easier way to do this (what I am trying to do, is have 3 radio buttons and when the submit button is clicked, easily determine which radio button was selcted). NOTE: the radio buttons are in 3 different cells of a table, so I can't use the <select></select> tags.... HTML: <form name="SelectOrder"> <tr><tr><input type="radio" name="OrderType" value="C">'C' Orders<br /></input></td></tr>
3
10154
by: Adam | last post by:
Hey guys, I've decided to stop banging my head against the wall and just ask you guys for the answer. I can't seem to find it. I have a form in which I have multiple submit buttons; only, I'm using button tags, not input tags to do it. It seems that IE6 is treating all the button elements as being successful on submit. This is, to say the least, surprising since the Spec is pretty clear that it should.
4
11043
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be provided. If multiple buttons are clicked their information will available on the same document. I'm not...
5
2574
by: Rik Brooks | last post by:
I am using a plain web forms button on an asp page - Is there any way to programatically change it to a custom color? -- ---------------------------------------- Magic is not in the hands of the magician but in the mind of the audience. Animadverto est verus
13
2314
by: James Bond | last post by:
Hello. My 80+ year old father has recently decided to get his first computer. Due to his age (and I suspect lack of playing pong as a child like I did) he lacks the manual dexterity to use a mouse well. He is frequently missing the left mouse button and hitting the right, or less often the middle (wheel) buttons. While he is very slowly getting better with practice, the frustration level is high for him as a result of this (he gets very...
4
1752
by: BrianDH | last post by:
Hi I would ask this questiopn on the NG ASP but it would be days before anyone might respond. I am using vb.net code behind to create buttons to add to a web form. After the buttons are created I get this error: ((Control '_ctl0' of type 'Button' must be placed inside a form tag with runat=server.)) My Code example:
5
15819
by: Sean M. Loftus | last post by:
I have a need to call an html page into the pane I'm viewing using a button on an ASP page. The page itself is an ASP page called from a website. I know a link would work but the rest of the page has buttons and it would look cleaner to use a button. I've tried the below in a few variations, including using a href tags inside the onclick. Anyone have a suggestion on what I'm doing wrong here? <input type="button"...
17
9683
by: Eric | last post by:
I'm new to JavaScript and I wrote this code to play with. Oddly, if I enter text in a box and then press the button, I only get the onChange event for the text box and not the button's onclick event. But if I press the button without entering text first, the button click event does work. What's up? <html> <body> <h3>Events on Buttons and Text Boxes</h3>
8
3332
by: Alvin | last post by:
I'm making a very simple game in SDL, and I'm not asking for SDL help I hope - this looks like something C++ related, so I'll ask here. I have a class for a simple block, or tile, in the game, which can be either on or off. I'm having trouble with the constructor though. class block { private: SDL_Surface *screen;
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.