Restarting game
Restarting game
Restarting game
Restarting game
Restarting game
Restarting game Restarting game Restarting game Restarting game Restarting game Restarting game Restarting game Restarting game
Restarting game Restarting game
Restarting game
Go Back  Xtreme Visual Basic Talk > > > Restarting game


Reply
 
Thread Tools Display Modes
  #1  
Old 04-30-2011, 05:24 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Question Restarting game


All,

Upon changing the field size a game should restart. Upon trying to do so I see the previous grid (e.g. 10x10) displayed on top of the new one (e.g. 4x4). How would I prevent this and indeed start the game fresh?Many thanks for your ideas and input.

Adri
Reply With Quote
  #2  
Old 04-30-2011, 07:22 PM
AtmaWeapon's Avatar
AtmaWeaponRestarting game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I can't tell you anything about code I can't see.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 05-01-2011, 05:02 PM
masterpreenx masterpreenx is offline
Newcomer
 
Join Date: Sep 2010
Location: Davao City Philippines
Posts: 24
Default

how did you place your grid? picture boxes or something? =) code is needed :P
Reply With Quote
  #4  
Old 05-03-2011, 10:20 AM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Exclamation Restarting game

Masterpreenx, AtmaWeapon, all,

I used the code as displayed (partly) below:


Private Sub Show_GameBoard()
Dim Number, R, C As Integer
Dim OffsetX, OffsetY As Integer
Dim BoxSize, FontSize As Integer

BoxSize = CInt((Me.ClientSize.Width * 0.8) / gi_GridSize)
OffsetX = CInt((Me.ClientSize.Width - (gi_GridSize * BoxSize)) / 2)
OffsetY = 2
FontSize = 18 - gi_GridSize
For R = 1 To gi_GridSize
For C = 1 To gi_GridSize
Number = (((R - 1) * gi_GridSize) + C)
Btn = New Button ' Make a New button
With Btn
.Text = CStr(GameArray(R, C)) ' Create unique name and caption
.Name = "Button" + CStr(Number)
.Location = New Point(((C - 1) * BoxSize) + OffsetX, ((R - 1) * BoxSize) + OffsetY) ' Hor, Vert
.Size = New Size(BoxSize, BoxSize) ' Use 'New Size' here, not 'New Point (Width, Height)'
.Font = New Font("Tahoma", FontSize, FontStyle.Regular)
.ForeColor = g_ArrColor(gi_ColorSet, 1)
.BackColor = g_ArrColor(gi_ColorSet, 2)
.Visible = True
End With
Me.Controls.Add(Btn) ' Add the button to the form
AddHandler Btn.Click, AddressOf Btn_Click ' Specify the routine that handles Click events
gb_OldBtn = Btn
Next
Next
Label2.Text = "BoxSize: " & CStr(BoxSize) ' Temporary text; will be overwritten by gi_Score(1)
ShowScore()
ShowPlayer()
End Sub


Private Sub MaxIt_Form_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Initialize()
Make_GameArray()
Show_GameBoard()
End Sub


Private Sub MenuItemFieldSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemCustomize.Click
gi_OldGridSize = gi_GridSize ' Save keeping
My.Forms.MaxitFieldSize.ShowDialog()
If gi_OldGridSize <> gi_GridSize Then
'Clean old screen....
'
'ReDim GameArray(12, 12)
'Refresh()
' If items remain in the list, remove the first item.
'If Controls.Count > 0 Then Controls.RemoveAt(0)
'If Btn.Controls.Count > 0 Then Btn.Controls.RemoveAt(0)
'If Me.Controls.Count > 0 Then Me.Controls.RemoveAt(0)

'Me.Initialize()
'Me.Refresh()
Initialize()
Make_GameArray()
Show_GameBoard()
End If
End Sub



I also attached the full directory to this mail, zipped, ico's and .exe's removed. As you can see the game is far from finished, but the basic stuff is there and the core is drawn in red text. What is needed now is that the screen get cleared before a (new) grid of buttons is drawn having also the new size (between 3 and 12). You can see the commands I tried in green text...
Hope anyone can help and advise.

Adri

Last edited by Adri17; 03-22-2017 at 11:03 AM.
Reply With Quote
  #5  
Old 05-03-2011, 11:29 AM
AtmaWeapon's Avatar
AtmaWeaponRestarting game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Something's wrong with your .zip file; I can't open it.

MakeGameArray() is probably interesting. Initialize() might be interesting too.

From what little I do see, you're only removing one control from the screen in MenuItemFieldSize_Click(); that's commented out but it could be the problem. You have to remove all of the old controls or they're going to remain. I'm not sure if that's the problem, but it could be.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #6  
Old 05-03-2011, 12:30 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Question Restarting game

AtmaWeapon,

I re-zipped the file, complete this time, and add this to this reply.

I see what you mean with 'only removing one control' and might have to loop through the list, but how? I'll have to figure this out. Will this also clear the screen as well or does it need additional commands?

Adri

Last edited by Gruff; 05-03-2011 at 12:55 PM.
Reply With Quote
  #7  
Old 05-03-2011, 02:23 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Exclamation Restarting game

All,

Should have understand the system cannot be fooled and will not accept 'exe' files, even when in a 'zip'......
I removed 'bin' and 'obj' directories and re-zipped one more time. Attached as well.

Adri

Last edited by Adri17; 03-22-2017 at 11:03 AM.
Reply With Quote
  #8  
Old 05-03-2011, 02:52 PM
AtmaWeapon's Avatar
AtmaWeaponRestarting game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Pocket PC... OK, that's a strange one. I had a look. It's just like I thought.

You add the buttons to the form's controls collection on line 126. If you want to get rid of a button, you have to remove it from that controls collection. Right now, when you resize the grid, you add new buttons for the grid, but since they are added after the existing grid they show up behind it.

The quickest fix? Add this line to Show_GameBoard() somewhere at the top:
Code:
Me.Controls.Clear()
It turned out that wasn't the best idea. That got rid of all the othe rcontrols on the form. So don't do that. You want to get rid of a bunch of buttons, but only the buttons that represent the grid. The best way to keep track of those buttons is a control array; it's just a plain old array with controls in it. You can add it with a minimum of effort. Here's the changes I made with context lines around them when needed. Since I added lines, obviously the line numbers make no sense if you aren't going in order:
Line 56 add:
Code:
Private _buttons() As New List(Of Button)()
<blank line>
ShowGameBoard(),
line 108-112
Code:
Dim BoxSize, FontSize As Integer
For Each button As Button In _buttons
    Me.Controls.Remove(button)
Next
_buttons.Clear()
That zaps the old buttons.

line 132-133
Code:
Me.Controls.Add(Btn)
_buttons.Add(Btn)
That puts the buttons in the array as you created them.

That's it. A handful of lines and you're done. Clever use of that list could eliminate the need for GameArray.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #9  
Old 05-05-2011, 03:51 AM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Question Restarting game

AtmaWeapon,

I added the lines as instructed but get an error message, see 'NoNew.jpg' attached. Apparently this command is not allowed here. I therefore removed it -as suggested by VB- but next I get a whole more errors, see 'NewRemoved.jpg'.....
A 'Catch22' case? Any idea?

The GameArray is something I am planning to use later on upon implementing some logic with computer-oponent.

Thanks again for looking into this,

Adri

Last edited by Adri17; 03-22-2017 at 11:03 AM.
Reply With Quote
  #10  
Old 05-05-2011, 04:17 AM
PlausiblyDamp's Avatar
PlausiblyDampRestarting game PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The line of code
Code:
Private _buttons() as New List(Of Button)
is declaring _buttons as an array but you are assigning a List to it. Try changing the code to
Code:
Private _buttons as New List(Of Button)
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #11  
Old 05-05-2011, 06:19 AM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Smile Restarting game

PlausiblyDamp,

Thant was the solution! I also had to re-locate some command because originally this was reference to before being created, but it is solved now. In my source code it looks like this now (and seems to work):

Private Sub CleanScreen()
For Each button As Button In _buttons
Me.Controls.Remove(button)
Next
_buttons.Clear()
End Sub

Private Sub MenuItemFieldSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemSize.Click
gi_OldGridSize = gi_GridSize ' Save keeping
My.Forms.MaxitFieldSize.ShowDialog()
If gi_OldGridSize <> gi_GridSize Then
CleanScreen() Initialize()
Make_GameArray()
Show_GameBoard()
End If
End Sub


(Formatting screwed up, sorry)
Many thanks, all, again! On to the next issue.....

Adri
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
Restarting game
Restarting game
Restarting game Restarting game
Restarting game
Restarting game
Restarting game Restarting game Restarting game Restarting game Restarting game Restarting game Restarting game
Restarting game
Restarting game
 
Restarting game
Restarting game
 
-->