Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Game Programming > Computer as oponent


Reply
 
Thread Tools Display Modes
  #1  
Old 05-17-2011, 12:38 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Location: Netherlands
Posts: 17
Question Computer as oponent


All,

Whilst developing a game (for the PocketPC, but it also works on a PC) I have created a function which should act as the move the computer, as oponent player, should make. The game-grid is build as a variable square of 'buttons' and the computer does calculate the correct 'button' to select. My problem now is how to implement this into the code correctly. What location and/or what construction is to be used? The human-player actions are caught by an "Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)" event, but how can I implement such alike for the compuer function? The computer might be the first player and the "Btn_Click" event is therefore not the correct starting point to call for the coputer function, I assume....

For better reference I added the VB2005 source code to this mail; I hope this helps. I hope I made enough comments in the code to be clear. Lots of lines are to be taken out eventually and the code optimized, but that is not the point now....
Any comments or thoughts and help is welcome, many thanks in advance!

Adri
Attached Files
File Type: zip DeviceApplication2.zip (40.4 KB, 0 views)
Reply With Quote
  #2  
Old 05-17-2011, 01:11 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

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

When the button is clicked, something happens. You should make it so the computer can make that something happen without clicking a button. Here's one easy way. Instead of this:
Code:
Sub Button_Click(...) Handles ....
    ' Do a bunch of stuff
End Sub
Start with this:
Code:
Sub Button_Click(...) Handles ...
    MakeMove()
End Sub

Sub MakeMove()
    ' Do a bunch of stuff
End Sub
Now MakeMove() can happen any time, not just when a button is clicked. The rest is making it understand who's making the move and taking the appropriate action.
__________________
.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-24-2011, 10:53 AM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Location: Netherlands
Posts: 17
Default

AtmaWepaon,

Thanks for the idea. I solved it in a slightly different way, but you did give me an idea in the correct direction. Final testing starts now....

Adri
Reply With Quote
  #4  
Old 06-13-2011, 05:46 AM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Location: Netherlands
Posts: 17
Default

All,



Completed the game. Source and result can be found at:

http://sourceforge.net/projects/maxitppc/



Thanks all for the help!
Reply With Quote
Reply

Tags
computer, function, game, move, oponent


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
 
 
-->