HexCell-演示布尔标志操作的游戏(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/hexcell-a-game-to-demonstrate-boolean-flag-operati-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 2 分钟阅读 - 904 个词 阅读量 0HexCell-演示布尔标志操作的游戏(译文)
原文地址:https://www.codeproject.com/Articles/15118/HexCell-a-game-to-demonstrate-boolean-flag-operati
原文作者:Duncan Edwards Jones
译文由本站 robot-v1.0 翻译
前言
A game (based on Soduku) to demonstrate boolean flag setting.
演示布尔标志设置的游戏(基于Soduku).
警告-会浪费很多灰质!(Warning - can waste a lot of grey matter!)
介绍(Introduction)
游戏规则对于完成Soduku的任何人都是显而易见的.基本上,网格被划分为16个象限,并且每一行,每一列和每一象限必须包含16种可能的颜色中的一种,并且仅包含其中一种.(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.) 您可以使用鼠标左键从当前单元格的16种可能性中选择或取消选择颜色.如果您知道给定的单元只能包含一种颜色,则可以使用鼠标右键快捷菜单来选择一种颜色.另外,如果您输入的错误,则该菜单上的选项可以将单元格清除回所有16种可能性.(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.) 可以保存网格并将其加载到XML文件(扩展名为(Grids can be saved and loaded to an XML file (with the extension).xhx(.xhx*)*),其中包含一个示例.(*) and there is one example included.*) 该程序演示了如何使用标志值(定义为2的幂的整数)来设置或取消设置32位整数中的位.(*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
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VB Windows .NET .NET2.0 Visual-Studio VS2005 Dev 新闻 翻译