3 - 1 game
Design Your Own Board Game

In this project, you will design your own board game. The game will be played right on the screen, with turtles as your game pieces.

You’ve probably played board games like this:

To make your board game, you’ll follow these steps:

1. Make the path by stamping squares.
2. Program some of the squares so the turtles turn the corners and stop at the Finish.
3. Create “digital dice.”
4. Make some lucky and unlucky squares.

Line up the squares

To line up the squares perfectly you will need a procedure we call adjust. Using the adjust procedure will cause your square-turtle to “snap” into place before you stamp it. Press Ctrl + F and type the following:

to adjust
setx 40 * round xcor / 40
sety 40 * round ycor / 40

Now right click (or eyeball) your turtle and type adjust stamp as the instruction.

Click OK and place your “square turtle” where you want to begin and just click on the square. It should adjust itself correctly and stamp a square on the screen. You must now drag the square to the next position and continue to click on it to stamp the shape on the screen. If you are unhappy about your board design just use the CG command and start over.

Moving the game pieces

The game pieces you choose will not know which direction to turn with out you programming the corner pieces. The way to fix this is to color the right turn corner pieces a specific color and the left turn corner pieces a different color.
Begin by going to the Drawing Center  and program a color (red if you have not used red as your square color) to turn right if a game piece touches it. 

Test the board

Before we test the board to see if your game pieces travel the board correctly, let put a stop color in the last square. This will tell the game piece that the game is over and stop the piece from moving. Pick a third color to fill the last square and program this color to make the turtle stop (see diagram on right).

Stopall stops whatever instruction a turtle is running.

Next, take your turtle and place it in the start position, turn it to the starting direction, and type the following in the command center:

Now, Roll the Dice!

In some board games you roll the die (one of a pair of dice), in some games you spin a spinner - however it done, you need a way to decide how many squares to move your game piece. This game uses the computer instead of dice.

Program your “digital dice” using the random command. To see what happens, type this in the command center:
show random 6 --press enter--
3 Your answer may be different.

Go back and try the command again. The answer will be unpredictable, but always from 0 to 5. However we need a range of 1 - 6 not 0 - 5. The way to fix this to type the following:
show (random 6) + 1 --press enter--
2 Your answer may be different.

Try it for a few times, and you’ll see you’re now getting numbers from 1 to 6 only.

Its time to put our random command to the test. Create a small text box to show your “digital dice.” Name it Dice:

Insert will show the roll of the dice in the new text box. Try this in the Command Center:
ct insert (random 6) + 1 --press enter--
These commands clears the text box (ct), then prints (insert) the random number in the text box.
Now, write a roll procedure with the random number instruction. Press Ctrl + F and type:

to roll
dice, ct insert (random 6) + 1
With a button that runs roll, you’ll be able to roll the dice with a single click. Create a button  and type roll as its instruction. Leave it set to once. Click on the button a few times to check that it works properly.

Move the Turtle With a “Roll of the Dice”

You have to use the number in the Dice box to make the turtle jump that number of squares. The name of a text box reports the text in the box. Try this:
show dice
3 Your answer may be different -- But it’ll match the number in your text box.

So, you can use the number in the dice reports as the number for repeat. Drag the turtle to the first game square, and face it to the starting direction. Press Ctrl + F and type:

to jump
repeat dice [ fd 40 wait 5 ]

Now program the turtles to perform the jump procedure: Right click the turtle or eyeball the turtle.

(see diagram right)

Now try it out. Click on the roll button and then on the turtle.
Add Another Game Piece So a Friend Can Play

One game piece is fine for testing the game board, but not for playing the game. Hatch another turtle so you can play with a friend! You will probably want to shrink the turtles so that they both fit in the Start square.

To play, each player clicks on the roll button and then on the turtle. Which turtle will finish first?

Rather than dragging each turtle into place and pointing it before you can play the game, why not write a procedure to do it?

Drag both turtles to the Start square and point them in the correct direction. Then type:

t1, show pos --press enter--
-55 -112 This is t1’s starting position. Your answer will be different.

t2, show pos --press enter--
-62 -112 This is t2’s starting position. Your answer will be different.

Flip the page over (Ctrl + F) and write the setup procedure. Use the numbers that pos gave. Also, fill in a number for seth, to point each turtle in the starting direction.

to setup
t1, setpos [ __ __ ] seth __
t2, setpos [ __ __ ] seth __

Finally, create a setup button and then try your game!
Adding Special Squares

At this point, the game is a simple race to the finish. For extra interest, many board games have “special” squares. Some are lucky (go forward 4 squares; take another turn) and others are unlucky (start again; lose a turn).

Here’s an idea for a special square: when a turtle lands, the player is offered a chance for a special roll of the dice. If the player says yes, the dice automatically rolls again and:

The question command is designed for this kind of interaction. Question brings up a dialog box where you can type an answer. Try this in the Command Center:

question [ Do you want to take a chance? Type Yes or No.]

Type yes or no and click OK.

The answer command remembers what was typed:
show answer
yes The answer will be whatever you typed.

Write a procedure to ask the question and check the answer:

to chance
question [ Do you want to take a chance? Type Yes or No. ]
if answer = “yes [ rollagain ]

The line if answer = “yes [ rollagain ] checks the answer. If the answer is yes, then a procedure called rollagain will run.

You’ll have to make a rollagain procedure: rollagain will roll the dice, check the results, and take some action.

to rollagain
if dice = 6 [ repeat 2 [ fd 40 ] ]
if dice = 5 [ fd 40 ]
if dice = 1 [ announce [ Lose one turn . ] ]

Type chance in the Command Center to test it out. Try it a few times to get a result.

You want to run chance when one of the turtles lands on a special square. You don’t want to run it if a turtle only jumps on the square in the middle of a move. In this case, programming a color won’t work.

You need a command named colorunder. Colorunder reports the color that’s underneath the turtle. If you add it to the jump procedure, the turtle will check the color of the square only when it’s finished its move.

Pick a color for the special square (not one of the 4 colors you’ve already used). Find the color’s number -- colorunder reports the number of the color not the name.

Add this line to jump:

to jump
repeat dice [ fd 40 wait 5 ]
if colorunder = __ [ chance ] Put in your color number

Fill a few squares with this color and try the game!

Final Touches

Play a tune for the winner

Write a tune in the Music Editor. Name the tune Winner. Now change the instruction for the Finish square’s color. Add the name of the tune. You can hide the Melody icon since you will never have to click on it.

You could even use announce to add a winning message after the tune is played.

Change the odds

Change what happens when a turtle lands on the special square. As it is, there are actions programmed for 3 of the 6 possible numbers:

if dice = 6 [ repeat 2 [ fd 40 ] ]
if dice = 5 [ fd 40 ]
if dice = 1 [ announce [Lose one turn. ] ]

You can add actions for the other three:

if dice = 4 ...
if dice = 3 ...
if dice = 2 ...

See the awesome GAMES other Crews students have created and published.  Click Here Do you know where a real board game is on the web?
 Click Here

This site was created by Roderick Hames
for the primary purpose of teaching and demonstrating computer skills..
Any distribution or copying without the express or written consent of
Alton C. Crews Middle School or its creator is strictly prohibited.
Copyright© 1998.  Alton C. Crews Middle School: CS