0

So I have the makings of a top trump game where the main form is populated with 10 labels, 5 on the player side and 5 on the computer side.

I need guidance on the best way to get the highlighted label/category on the computer side.

So what happens is that you press the New Game button Player selects a category (Say Intelligence). (PlayerlblIntelligence) The Player selected label is highlighted Compare button is pressed.

WHat I want to happen after the Compare button is pressed is that:

Program gets selected player label and stores that value Computer then looks up the same category on it's current card Highlights it and then runs a comparison method.

What is the best way to get the equivalent category and label for the computer (so that it highlights and gets the equivalent category/value.

The way I have it get the value of the selected label is to regex the label text so that it pulls out the number and use that for comparison. However, the wife states that seems wrong and that the program should use some other method instead of the label text (as it shouldn't know anything about that).

I'm just got to the stage where I can't think of a better way to do it.

Link to Gist where the TopTrumpClass and Form classes are

GistHub Source Code

Edit: Thinking out aloud,

1) I get it to read the value of the selected label (so if Intelligence is 85, it gets the int value of 85)
2) Compare that value to the players cardsinhand[0] properties and match it
3) Look at the Computer cardsinhand[0] and look up the same property.
4) Obtain the value and then run a comparison and highlight label method (although how I get it to highlight the right label might be tricky).

Would the steps 1-4 work. If so, what's the best way to match the values to the card's properties. Would I be looking at using Attribute.GetCustomAttribute for example (How to get a property value based on the name)

Community
  • 1
  • 1
Decosta
  • 15
  • 4

1 Answers1

0

Started as a comment, but kept growing :

This is a wee broad, don't you think ? It's not about a specific problem, and nothing is "broken", so it might not be a good fit for this site.
Also, going through 500+ lines of your code isn't gonna happen for me (think about, what's in it for the person taking his time to look at your code ...). Maybe codereview @ stackexchange would be a better fit.

Having said that, your wife is right, reading the label and regexing the result isn't right.

You should probably have the values somewhere (since it's your program). Have you considered maybe a dictionary so you can easily match a string to a value?

Noctis
  • 11,507
  • 3
  • 43
  • 82
  • Good point. I guess it was just a rambling of a best approach. I guess the mods can close it. I just got to the point where I couldn't see a viable solution on how to proceed – Decosta May 14 '14 at 05:16