Click here to Skip to main content
15,867,832 members
Articles / Mobile Apps

Color Invasion for the PocketPC or .NET

Rate me:
Please Sign up or sign in to vote.
3.83/5 (16 votes)
28 May 2004CPOL6 min read 52.9K   304   25   2
This is my submission for the .NET CF contest for May 2004. It is a game utilizing the .NET Compact Framework for the PocketPC that demonstrates the ease and power or .NET CF. The game allows singleplayer mode against the computer, or Multiplayer over a network or Internet connection.

Sample Image - ColorInvasion_PocketPC.jpg

Introduction

This game demonstrates the simple, yet powerful .NET Compact framework that allows concurrent development for the PocketPC as well as the PC. The code is a demonstration of multithreading, networking via TCP/IP, drawing using graphics, and simple game and AI mechanics. The game is based on a risk style arcade game I saw at a truck stop.

Background

This version of the game was inspired by the .NET Compact Framework Contest in May of 2004. It is written in C#. The networking code was a push to stand out and represents my first ever attempt at networking, something made very simple in .NET CF.

Using the code

Thanks to the .NET Framework, the source includes a Compiled Help File (.chm) that documents the namespaces, classes and their methods/properties.

To compile the code, you need VC.NET and possibly the embedded VC 4.0 download from Microsoft. Simply compile and deploy to the PocketPC, Pocket emulator, or run directly from your machine.

Points of Interest

This is my first attempt at a game and the first time I've ever done networking. The .NET CF made it possible to do both very quickly.

I noticed some benefits afforded to me because of .NET and .NET CF:

  • Faster Development! .NET Compact Framework provides namespaces and classes you need at your fingertips, so you can autocomplete your way to the finish line.
  • Portability! Develop in C# and run on both the PC and PocketPC. Once I had converted the PC version to .NET, it was simply executing the binary on the PC or PocketPC! With the .NET CF, I can recompile for other mobile devices! Measure once, cut Twice...ad infinum.
  • Networking. What could be a cooler use for WAN cards than to play against other PocketPC users? I'll tell you: playing the same game, the same executable, against a person running on a computer with your new WAN PocketPC. Maybe you don't have a Pocket... play computer on computer - Over the Internet!
    1. Works from behind Firewalls - Just connect out to another person over the net not behind a firewall.
    2. Work over LAN - It shows your IP to Instant Message or tell your friend to connect to. If you're behind a firewall, your Internet IP Address will be the same as your LAN IP address.
  • Better Drawing Code:
    1. Smaller distributable because instead of bitmaps, I used the GDI+ classes in .NET.
    2. Graphics class allows for redrawing just the updated tiles instead of drawing the whole screen.
    3. Complex Filled Polygons with .NET GDI+.
  • Collections with Garbage Collection! Instead of using an external set of tools like for common containers, Collections keep with the style and conventions of the rest of C# .NET.
  • Source Code Documentation: .NET specifies a schema for commenting that allows XML generation of comments. Follow the rules, use a tool provided with the IDE, and you have generated documentation for later reference between you or your team!

Rules

  1. Each player starts in their respective corner with a default color. The Host (or singleplayer) is in the bottom left hand corner. The person joining the Client is in the upper right hand corner.
  2. They take turns switching colors back and forth.
  3. You cannot change to the same color as the Opponent.

Gameplay

When you change colors, any tile surrounding your current set will be added to your collection. The point of the game is to occupy the most spaces on the board. If you play over TCP with another person, you take turns back and forth. If you are playing single player, the Computer AI takes a turn and returns almost immediately. The AI becomes progressively harder, the more games you win. If you win 6 games in a row, it becomes the hardest to get. If you can beat this, then you need to play against a human!

Multiplayer

In order to get Multiplayer working, you must follows these steps:

  1. Execute the binary on both machines and hit NO to the Single player dialog.
  2. Note the IP address of the host and relay this to the other player. Start the host connection for your LAN or over the Internet.
    • If the 'Net' and 'LAN' IP addresses are the same, this client cannot host a game over the Internet, but it can join a game hosted on the Internet.
    • If you are hosting over the Internet, check the 'Net' radio button and press host.
    • If both machines are on a Local Area Network (LAN), either machine may host.
  3. After the Host is running, have the Client type in the IP address into the box and press the Join button.
    • Even if you are behind a firewall, you should be able to connect to a Host over the Internet that is not behind a firewall.
    • If both machines are behind a firewall, a connection cannot be made.
    • If both machines are behind the same Firewall, connect using the LAN.
  4. Once the connection has been made, the Host will generate a board and send it to the joining player.
  5. The Host is the first player, who is in the bottom left hand corner on both machines. The Host takes the first turn. The joining client's buttons are disabled until it is its turn.
  6. The Client is the second player and its tiles are in the upper right hand corner.
  7. After the game is finished, it tells you who won and asks you if you want to play again. Choose yes if you want to play again.
  8. If you are connected to a machine, then it will ask you if you would like to use the same connection to play another game.

Requirements

Requires that you download and install .NET CF onto your Mobile device. This is only necessary once to enjoy the multitude of applications to follow.

Screen Shots

This is a picture of the beginning of a match between the emulator and the desktop. Notice, the boards are the same, that means they're connected and playing!

Image 2

This is a picture of the beginning of a match between a Computer and another Computer. Notice, the boards are the same, that means they're connected and playing!

Image 3

This is a picture of the Networking box. If you click on "Net", you get your connected IP for your service. If you are behind a firewall, you get the LAN IP in this box. If you click on "LAN", you can see your LAN IP address.

Image 4

Special Thanks

Where would we be without our friends and family? Special thanks goes out to all those who helped test and made suggestions for this project:

  • Testers:
    • My Love, My Wife, Thanks.
    • My family for testing it.
    • My dad for showing me that 'just because I wrote it' doesn't mean that he can't wipe the floor with me.
    • The crew at GameDev.Net for testing the Win32 Version.
  • Suggestors
    • All of the above.

A special thanks to Mr. Lewey Geselowitzs for helping me debug this application, compile and test it on his PocketPC, and for general coolness. Cheers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Philips
United States United States
I'm a senior software engineer at Philips. I work on Precision Diagnostics software.

Comments and Discussions

 
General[Message Deleted] Pin
Danny Rodriguez27-Jan-08 9:18
Danny Rodriguez27-Jan-08 9:18 
GeneralNeed your help Pin
Chandana Subasinghe23-Jun-06 11:48
Chandana Subasinghe23-Jun-06 11:48 
I am trying to consume web services inside my pocket PC 2002 emulator (Came with VS 2003).
But I could not connect to internet using my emulator even though my PC which runs that emulator has internet connected.
I would be glad if you can give some advices for me to connect my emulator in to internet

kind regards,
chandana subasinghe

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.