|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis 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:
Code discussionThe reasons I undertook this project:
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
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||