Introduction
This is my first contribution to CodeProject! Twix is a strategy board game that was played on a square plastic board containing a grid of holes for pegs with which you connect bridges.
There are two players in this game who would try to connect an uninterrupted bridge from one edge of the board to the opposite edge of the board. One of the players attempts to connect the left and right edges, while the other tries to do the same with the top and bottom edges. Inevitably, there is conflict and therein lies the strategy of the game.
Players take turns placing pegs onto the grid. When two pegs are in a grid position of one-over and two-away (like a knight in chess moves), a bridge may be placed atop the pegs. Bridges may not cross other bridges! Each peg may have up to eight bridges connected with pegs surrounding it that are placed in the 'valid' grid holes.
Every time a player places a peg, the peg is analyzed to determine if any bridges should be placed (up to eight). It is not necessary to place a peg in any potential bridge location, i.e., it is not necessary to place bridges and connect pegs in every turn.
Bridges are placed on like-colored pegs. Bridges may not cross other bridges and will not be allowed.
Some enhancements I have made:
- Timer to enforce that player must make a move or forfeit their turn.
- A credit system based on time and new bridges that reward a quick player move.
- A creature is awarded to a player who has accumulated enough points (The cursor will change to indicate that a creature may be launched). This creature is assigned a location on the board (an opponent's peg in a strategic location is a good one). The creature will work its way over to that location, and if a peg is there, will grab it and relocate it to an empty grid position.
Code Discussion
The reasons I undertook this project:
- It was a cool game that I can't find anymore.
- It was an interesting problem to solve.
- It was a good starting platform to introduce a useful playing field for my creature object.
The trickiest part of developing this game was the bridge connection/blockage detection. The next difficult problem was the win condition detection. The latter required recursion, the former required a lot of boundary checking and thoughtful looping.
The creature is a specialty of mine that I came up with almost ten years ago. It learns how to migrate towards a coordinate by randomly flailing its appendages until a 'good' move is determined. A good move is one where its elbow and its feet are closer to the destination than its current elbow and feet configuration. Then the creature iterates through the two configurations repeatedly (extending its arms, grabbing with its feet, and extending and contracting its elbow) until its destination is reached, or its distance from the destination increases. I'm very proud of this little guy and finally found an interesting use for it in a game.
The game is run by a timer in the main Windows form. Every time the timer event occurs, a set of list objects is called upon to do work. There is an explosion list, an arm list, a peg list (which contain bridge lists) and the board object. The graphics is page flipped to provide a smooth look.
Crack open Globals.cs to change the board size, the speed of the creatures, their spawn rate in demo mode, etc.
Desired Future Enhancements
- Sound!! Nice ambient background and a heartbeat that increases as the players get closer to winning would be cool. Explosion sounds, creature walking sounds, grabbing sounds, etc.
- Computer AI for one player mode.
- Two players over the network would be awesome, but a significant and possibly difficult restructuring of the code is required.
- More interesting events and sub-goals for players to strive for (enclosing something causes something to occur, etc.)
- Port to DirectX, DirectSound, DirectPlay.
History
- 19th October, 2004: Initial version
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.