DEVBUZZ Homepage Writing a 2 player Tic-Tac-Toe game in eVB for your Pocket PC
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | Starting Out

Writing a 2 player Tic-Tac-Toe game in eVB for your Pocket PC
Written by Pete Vickers  [author's bio]  [read 59886 times]
Edited by Derek

Download the code   Discuss this article   eVB Ver 3.0   

Page 1  Page 2  Page 3  Page 4 

As any sharp-eyed reader may have noticed, I have a rather sad interest in TCP/IP and its use on the Pocket PC. When working with eVB, it is rather like being interested in constantly banging your head on the wall, but after a while, you forget about the pain, and just get on with it. I got a bee in my bonnet about writing a noughts and crosses (tic-tac-toe) game playable between 2 Pocket PC's using IRDA or ethernet and eVB. During the creation of the game, I used several of the articles on devBuzz, so I thought it may make an interesting project, drawing these areas together in a 'practical' project. A game such as this cries out for a control array, but as we know, these don't exist in eVB. This is where the article Simulating Control Arrays in eVB: http://www.devbuzz.com/content/zinc_evb_control_arrays_pg1.asp came in useful.

Let's have a look at the screen design. We have 2 frames, 1 for sorting out the connections and 1 for the game itself. We will take care of the positioning in code. (See Building a GUI Engine with Frames : http://www.devbuzz.com/content/zinc_evb_gui_frames_pg1.asp)

The 'connections' frame is pretty straightforward, so we will look at the 'game frame' in more detail. The rather fetching pink squares are in fact 9 picture box controls, named xdisp0 to xdisp8. This is where we will put our noughts and crosses. The names will be explained in more detail shortly. We also add a listbox, menubar, timer and of course a Winsock control. The listbox will tell us what is happening, and the timer will allow us to reset the game when we have a winner.

We will only show the more interesting bits of the code, as the project is downloadable.

In our declarations we have:-

Private xdisp(8) As PictureBox

and in Form_Load

Set xdisp(0) = xdisp0
Set xdisp(1) = xdisp1
Set xdisp(2) = xdisp2
Set xdisp(3) = xdisp3
Set xdisp(4) = xdisp4
Set xdisp(5) = xdisp5
Set xdisp(6) = xdisp6
Set xdisp(7) = xdisp7
Set xdisp(8) = xdisp8

This allows us to simulate a control array, as demonstrated in Robert Levy's article.

The rest of the Form_Load procedure is:-

MyScore = 0
opponentScore = 0
opponentName = "Opponent"
If IRDA Then
txtServer.Text = WinSock1.LocalHostName
Else
txtServer.Text = WinSock1.LocalIP
End If
Make_Menu
Frame1.Top = 0
Frame1.Left = 0
Frame1.Width = Me.Width
Frame1.Height = Me.Height
Frame1.ZOrder
IRDA = True
Simpsons = True
Choose_Picture
SoundOn = True

I decided it would be a good idea to use sound in the game, and allow a choice of symbols. My children are addicted to the Simpsons, so the decision was taken out of my hands. To enable the game to be played silently across the table in the board room or a meeting, the sound is configurable, as is the ability to use IRDA or Ethernet. This is where the menubar control comes in, and it is set up in the Make_Menu Procedure. We set Sound, IRDA and the Simpsons options here, so they are checked when the game starts.

Private Sub Make_Menu()
Dim MenuItems
Set MenuItems = _&
MenuBar.Controls.AddMenu("Options")
MenuItems.Items.Add , 1, "Connect Screen"
MenuItems.Items.Add , 2, "Disconnect"
MenuItems.Items.Add , 3, "IRDA"
MenuItems.Items.Item(3).Checked = True
MenuItems.Items.Add , 4, "Sound"
MenuItems.Items.Item(4).Checked = True
MenuItems.Items.Add , 5, "Simpsons"
MenuItems.Items.Item(5).Checked = True
MenuItems.Items.Add , 6, "Exit"
End Sub

We start the game by showing the 'connections' frame. Here we decide whether to be a server or to be a client. If we are a server we will listen for a connection. If we are a client, we must connect to a server. For ethernet, we can use the IP address or name of the server, but for IRDA, we MUST use the name. My 2 Pocket PC's are rather imaginatively called Ipaq and Jornada. If we say that Ipaq is the server, we would 'listen' on Ipaq by clickin on 'Be a Server'. On Jornada, we would enter Ipaq in the textbox, and click on 'Connect To'. This is where I found out that names in IRDA are case-sensitive. 'Connect To' ipaq would not find the server, where 'Connect To' Ipaq works.

The code for the 'listener' is handled by the Winsock Connectionrequest event:-

Private Sub WinSock1_
ConnectionRequest()
On Error GoTo 0
opponentSymbol = "o"
MySymbol = "x"
myName = txtName.Text

WinSock1.Accept

bMyGo = True
WinSock1.SendData _
"OXNAME" & myName & "|"

lstStatus.AddItem _
"Connected to " & WinSock1.RemoteHostIP, 0
bReady = True
lstStatus.AddItem _
"Game Started. You are " & UCase(MySymbol) _
& "'s", 0
lstStatus.AddItem "Your Go", 0
End Sub

Next Page 

Back to Starting Out | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP