Game Development Reference
In-Depth Information
(a) Extend the game so that sometimes all the colors of the jewels change. This
can be something controlled by the player (if he/she is stuck), or it can be
done randomly.
(b) When a valid combination of three jewels has been found, add a nice 'disap-
pearing' effect for the jewels, such as making them smaller and smaller, or
flying them outside of the screen in random directions.
(c) Add a feature where there is an extra restriction in some cases, such as only
combinations allowed of the same color, or some jewels are not allowed in
any combination.
3. Tic-tac-toe
Another nice example of a grid-based game is Tic-tac-toe. In this challenge, we'll
go step-by-step through the important parts of building that game.
(a) Start by looking up some nice sprites that you can use for this game. In any
case, you are going to need a sprite for the cross and a sprite for the circle.
Once you've found these sprites, start by making a first version which only
displays circles or crosses on a 3
3 grid on the screen. Here, you can reuse
some of the classes that we built for the Jewel Jam game.
(b) Next, add player input to the game. When the player clicks in the screen, a
cross should appear at that position in the grid. Make sure that you only add
a cross to the grid if the position in the grid is free. In the first version, you
can make it a two-player game, where each player takes a turn after the other
by clicking somewhere. Therefore, you should keep track of whose turn it is,
so that you can add the right element (cross or circle) to the grid.
(c) Now, you need to write the code that handles whether three symbols of the
same type are in a row, column or diagonal. You can do this by using a couple
of for -instructions that check each of the possible combinations.
(d) Finally, handle the different game states: indicate on the screen whose turn
it is, show an overlay if the game has been finished, and add a restart option.
(e) ( difficult ) As a nice extension, you could program a single player mode,
where the player has to play against the computer. The question is: how do
you program the part where the computer decides what to do? A very well-
known common way of implementing computer behavior in such games is
by using the Minimax algorithm. The basic idea behind this algorithm is to
represent all the possible ways that the game can be played as a tree, and
then search through that tree to find an optimal path. The nodes in each tree
represent a choice that is made by the player or by the computer, and the
edges determine the sequence in which these choices are made.
In the case of tic-tac-toe, you can imagine the tree as follows. After starting
the game, the first player has 9 possible locations to choose from. So from
the root node there will be nine outgoing edges. After that, the second player
can choose between the remaining 8 locations. So from each of the 9 nodes,
there will be 8 outgoing edges. From each of these 8 sub nodes, there will
be 7 outgoing edges, and so on, and so on. This will result in a huge tree
containing all the possible outcomes of the game. For each path in this tree,
×
Search WWH ::




Custom Search