Mastermind Problem
Mastermind Problem
Mastermind Problem
Mastermind Problem
Mastermind Problem
Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem
Mastermind Problem Mastermind Problem
Mastermind Problem
Go Back  Xtreme Visual Basic Talk > > > Mastermind Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2004, 02:18 PM
GamesRule GamesRule is offline
Junior Contributor
 
Join Date: Apr 2003
Location: Milton Keynes
Posts: 385
Default Mastermind Problem


Hey

Ive been developing a mastermind game as I thought it would be an easy game to start with in VB.Net.

Going well as I searched the forum for the equivalent control array. I have this code...

Code:
Private WithEvents pan As Panel Dim ctl As Control For Each ctl In Controls If ctl.GetType() Is GetType(Panel) Then AddHandler ctl.Click, AddressOf pan_click End If Next Private Sub pan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pan.Click Dim Pan As Panel = DirectCast(sender, Panel) If Pan.BackColor.ToString = Color.White.ToString Then 'Changes color to skyblue Pan.BackColor = Color.SkyBlue ElseIf Pan.BackColor.ToString = Color.SkyBlue.ToString Then 'Changes color to red Pan.BackColor = Color.Blue ElseIf Pan.BackColor.ToString = Color.Blue.ToString Then 'Changes color to blue Pan.BackColor = Color.Red ElseIf Pan.BackColor.ToString = Color.Red.ToString Then 'Changes color to brown Pan.BackColor = Color.Yellow ElseIf Pan.BackColor.ToString = Color.Yellow.ToString Then 'Changes color to green Pan.BackColor = Color.Green ElseIf Pan.BackColor.ToString = Color.Green.ToString Then 'Changes color to orange Pan.BackColor = Color.Orange ElseIf Pan.BackColor.ToString = Color.Orange.ToString Then 'Changes color to purple Pan.BackColor = Color.Purple ElseIf Pan.BackColor.ToString = Color.Purple.ToString Then 'Changes color to original white Pan.BackColor = Color.White End If End Sub

So for all the panels on the form, this code comes into play. How Can I now check if the users guess is the same as the randomized answer? Because I cant work out how now to see if each one is the same...

EG
Solution: Red, Green, Yellow, Blue
Guess: Red, Yellow, Green, Blue

So how can I Compare each square?

Thanks
__________________
Ian
The Only Way To Be Totally Right, Is To Lie.
Reply With Quote
  #2  
Old 01-20-2004, 08:01 AM
Iceplug's Avatar
IceplugMastermind Problem Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Sorry, but there are no control array events in VB.NET.
You'll probably have to make a separate event for each control, and then make each of these events call a sub with the index as the parameter.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-21-2004, 11:25 AM
Machaira's Avatar
MachairaMastermind Problem Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

One thing I've done is to store the index of the control in it's Tag property. You can then do something like:

Code:
'Assumes you've populated this with 4 random colors Dim Answer(3) As Color Private Sub pan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pan.Click Dim Pan As Panel = DirectCast(sender, Panel) If Pan.BackColor.Equals(Answer(Pan.Tag)) Then 'colors match End If End Sub

Note that you don't have to resort to converting colors to strings to compare them. You can use the Equals method.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Subclassing as a Method of Problem Solving John Tutors' Corner 1 05-12-2003 10:32 PM
A Problem for The Expert Programmers – or maybe not! cballe General 2 07-15-2002 07:48 PM
A problem for the Guru programmers cballe General 3 06-26-2002 10:55 AM
Timers jemerico General 7 05-30-2001 06:30 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Mastermind Problem
Mastermind Problem
Mastermind Problem Mastermind Problem
Mastermind Problem
Mastermind Problem
Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem Mastermind Problem
Mastermind Problem
Mastermind Problem
 
Mastermind Problem
Mastermind Problem
 
-->