0

I have a couple of split panels nested inside of each other. The problem is, I'm rendering an 8x8 tiled game inside of the center panel. Basically, the height and width of the panel need to be an odd multiples of 8 so I can find the center tile displayed easily.

I'm using VB.net so all .net solutions are acceptable :)

EDIT sorry, that was confusing a bit...

I mean, I need the width and height to be divisible by 8. The number 8 is multiplied by should be odd:

EDIT AGAIN these numbers below do not refer to the size. They refer to two number being multiplied. I've changed them to a * to show this. These numbers below apply to both the height and width. One number should be odd, the other 8. 8*x

5*8 - Good

6*8 - Bad

Freesnöw
  • 30,619
  • 30
  • 89
  • 138
  • What? I thought all multiples of 8 were even... am I missing something? – corsiKa Sep 11 '11 at 20:09
  • I'm not sure what the actual question is--if you have an even number, inc or dec to make it odd. But no, you don't mean you need the width and height to be divisible by eight. – Dave Newton Sep 11 '11 at 20:21

2 Answers2

1

You can check if something is odd by doing mod 2 to the number. So just do

if number mod 2 == 1:
   code for board
Matt Habel
  • 1,493
  • 2
  • 14
  • 35
0

You stated that you need both the height and the width be divisable by 8 but in your example only height is divisible by it. anyway here's one way to do it:

place this into a resize event handler:

Dim Height as Integer = SplitControl1.Panel1.Width
    If Height mod 8 <> 0 then
  Height -= (Height mod 8)
End If

Height += 9 //This ensures that the Height is not 0 and still is divisible by 8 + 1 (to be odd)

and

Dim Width as Integer = SplitControl1.Panel1.Width
If Width mod 8 <> 0 then
   Width -= (Width mod 8)
End If

Width += 9 //This ensures that the Width is not 0 and still is divisible by 8 + 1 (to be odd)

finally

SplitControl1.Panel1.Width = Width
SplitControl1.Panel1.Height = Height
Qqbt
  • 802
  • 2
  • 8
  • 33
  • I've explained this again in my OP. Sorry for the confusion. Imagine you divided the panel into 8x8 squares. The count of tiles going across and down should be odd, but still 8x8 full squares should be visible (as opposed to half of a square showing). – Freesnöw Sep 11 '11 at 20:41