Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid
Draw in (graphical) grid Draw in (graphical) grid
Draw in (graphical) grid
Go Back  Xtreme Visual Basic Talk > > > Draw in (graphical) grid


Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2010, 09:40 AM
Fyzer Fyzer is offline
Newcomer
 
Join Date: Jan 2010
Posts: 4
Default Draw in (graphical) grid


I am trying to make a combination of Tic Tac Toe and Connect Four, you need to connect four boxes of your colour, but you can click where you want...

I allready have a grid of 10x10 boxes on a picturebox (502;502).
I made this with .DrawLine and a ForNext, not that hard.
But now I'm stuck. If I click on a box of that grid, it should have a specific colour (2 colours, 2 playes, I'm making it multiplayer).
But I don't know how I should tell the program that it is only that box that is needed to full that is clicked on.

I know my mousecoordinates where I click with
Code:
TextBox1.Text = System.Windows.Forms.Cursor.Position.X.ToString() & " " & System.Windows.Forms.Cursor.Position.Y.ToString()
from here, I don't know how to continue.
-I thought comparing that coordinates with the ones of the boxes (so 502/10 for each box)
-Or if there is clicked it watches the topleft corner of that box (if that is possible).

For both I don't know how to do it. Could someone help me out.
ps: if both of my thinking ways are wrong or harder than it could be, please correct me, I'm only a beginner.

Thanks!
Reply With Quote
  #2  
Old 01-26-2010, 09:55 AM
Qua's Avatar
QuaDraw in (graphical) grid Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

You will need to detect in which grid the user clicked with the mouse as you explained. Lets just discuss how to figure out which box on the x-axis that the user clicked: You know the location where the user clicked, and you know how large the width of each box are. By calculating how many times the position is divisable by the width you will know in which grid location the user clicked. You can perform the exact same calculation for the y-axis to get the exact grid location of the box that was clicked.

Pseudo-code
Code:
Dim clickLocation As Point = New Point(151,125)
Dim totalWidth As Integer = 500
Dim gridVerticalBoxCount = 10
Dim gridVerticalPhysicalSize = totalWidth\gridVerticalBoxCount

'and here we calculate in which box the user clicked
Dim verticalBoxClicked As Integer =clickLocation.X \ gridVerticalPhysicalSize
__________________
Reading is the foundation for all knowledge - Unknown.

Last edited by Qua; 01-26-2010 at 11:12 AM. Reason: fixed the division
Reply With Quote
  #3  
Old 01-26-2010, 10:21 AM
Fyzer Fyzer is offline
Newcomer
 
Join Date: Jan 2010
Posts: 4
Default

fixed

Last edited by Fyzer; 01-27-2010 at 09:27 AM.
Reply With Quote
  #4  
Old 01-26-2010, 10:55 AM
Qua's Avatar
QuaDraw in (graphical) grid Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

I used a randomly selected number for the width. Yes, you should be using the actual width of the picturebox and the actual click location of the mouse instead of my predefined random numbers.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #5  
Old 01-26-2010, 11:05 AM
Fyzer Fyzer is offline
Newcomer
 
Join Date: Jan 2010
Posts: 4
Default

fixed

Last edited by Fyzer; 01-27-2010 at 09:27 AM.
Reply With Quote
  #6  
Old 01-26-2010, 11:11 AM
Qua's Avatar
QuaDraw in (graphical) grid Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

My bad. You should divide the click locations with the physical sizes and not the other way around
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #7  
Old 01-26-2010, 11:25 AM
Fyzer Fyzer is offline
Newcomer
 
Join Date: Jan 2010
Posts: 4
Default

fixed

Last edited by Fyzer; 01-27-2010 at 09:27 AM.
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

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
Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid Draw in (graphical) grid
Draw in (graphical) grid
Draw in (graphical) grid
 
Draw in (graphical) grid
Draw in (graphical) grid
 
-->