Click here to Skip to main content
6,630,901 members and growing! (19,969 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Game Development » Games     Intermediate License: The Code Project Open License (CPOL)

HexCell - a game to demonstrate boolean flag operations

By Duncan Edwards Jones

A game (based on Soduku) to demonstrate boolean flag setting.
VB, Windows, .NET 2.0VS2005, Dev
Posted:9 Aug 2006
Views:19,214
Bookmarked:15 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
7 votes for this article.
Popularity: 2.54 Rating: 3.00 out of 5
1 vote, 14.3%
1

2
2 votes, 28.6%
3

4
4 votes, 57.1%
5

Sample Image - Screenshot.jpg

Warning - can waste a lot of grey matter!

Introduction

The rules of the game will be immediately obvious to anyone who has done Soduku. Basically, the grid is divided into 16 quadrants, and each row, column, and quadrant must contain one and only one of each of the 16 possible colours.

You can select or unselect colours from the 16 possibilities for the current cell using the left mouse button. If you know that a given cell can only contain one colour, there is a right-mouse shortcut menu to select a colour. Also, there is an option on that menu to clear a cell back to all 16 possibilities if (when) you get it wrong.

Grids can be saved and loaded to an XML file (with the extension .xhx) and there is one example included.

This program demonstrates using flag values (integers defined as powers of two) to set or unset bits in a 32 bit integer.

<Flags()> _
Public Enum CellPossibleValues
    CellValue_0 = &H1
    CellValue_1 = &H2
    CellValue_2 = &H4
    CellValue_3 = &H8
    CellValue_4 = &H10
    CellValue_5 = &H20
    CellValue_6 = &H40
    CellValue_7 = &H80
    CellValue_8 = &H100
    CellValue_9 = &H200
    CellValue_A = &H400
    CellValue_B = &H800
    CellValue_C = &H1000
    CellValue_D = &H2000
    CellValue_E = &H4000
    CellValue_F = &H8000
End Enum

These values are then added to or removed from the cell's possible values, using boolean operations:

''' <summary>

''' Adds the value to the possible values for this cell

''' </summary>

''' <PARAM name="value"></PARAM>

''' <remarks></remarks>

Public Sub SetValue(ByVal value As CellPossibleValues)
    CellValue = _CellValue Or value
End Sub

''' <summary>

''' Removes the value from the possible

''' colour values held by this hex cell

''' </summary>

''' <PARAM name="Value"></PARAM>

''' <remarks></remarks>

Public Sub UnsetValue(ByVal Value As CellPossibleValues)
    CellValue = _CellValue And (&HFFFF - Value)
End Sub

License

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

About the Author

Duncan Edwards Jones


Member
Microsoft MVP 2006, 2007
Visual Basic .NET
Occupation: Software Developer (Senior)
Location: Ireland Ireland

Other popular Game Development articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralToo easy PinmemberDuncan Edwards Jones3:41 11 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 Aug 2006
Editor: Smitha Vijayan
Copyright 2006 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project