Logo Tank Game.

This is a three player seek and destroy tank game. The players control a tank. They need to move it around the board, find the other tanks and shoot at them. The winner is the player with the least damage to their tank at the point when everybody gets bored.

The program contains several elements.

  1. makebrd This sets the board up and gives the tanks random start positions. One player only runs this program at the start.
  2. draw1 This and draw2 and draw3 show the board from the point of view of the three players respectively.
  3. drawbrd This draws the whole board and is a way of cheating or checking that the program is behaving itself.
  4. move1 This moves tank 1. Input boxes are used for speed and absolute heading.
  5. fm1 This makes tank 1 move with its current speed and heading. It also moves all the other vehicles.
  6. moveall This is the procedure which actually moves everything.
  7. tank This draws the tank. Unfortunately logo won't rotate bitmaps so you can't use quality images.
  8. score This prints out the current damage ratings.

To play the game:

  1. Create a network folder called logogame on the drive which matches the drive name in the program. (W: in Whitehaven School. If need be change this by using Notepad in seek and destroy mode.)
  2. One player then runs makebrd.
  3. Each player then uses draw1 etc. to see the board.
  4. Each player then uses move1 etc. to move their tank.
  5. Each player then uses fm1 etc. to repeat the current move.
  6. Use score to view the damage.

makebrd

This creates the game. It writes the coordinates, speeds, headings and damage of the tanks to a file called \\logogame\\oxo.txt
Make sure that you are writing to a extant directory! The easiest way to change the directory code is to open the whole blogwrit.lgo file in notepad and use find/replace in seek and destroy mode. (ie substitute W: for D:)

to makebrd
make "board (array 21 0)
repeat 21 [ setitem repcount-1 :board 0]
setitem 3 :board random 360
setitem 8 :board random 360
setitem 13 :board random 360
setitem 0 :board 300+random 50
setitem 1 :board 150+random 50
setitem 5 :board -300+random 50
setitem 6 :board 150+random 50
setitem 10 :board 0+random 50
setitem 11 :board -200+random 50
openwrite "N:\\logogame\\oxo.txt
setwrite "N:\\logogame\\oxo.txt
repeat 21 [print item repcount-1 :board]
setwrite[]
close "N:\\logogame\\oxo.txt
end

The board uses an array of 21 numbers:

  1. 0 tank1 x coordinate.
  2. 1 tank1 y coordinate.
  3. 2 tank1 speed.
  4. 3 tank1 heading.
  5. 4 tank1 damage.
  6. 5-9 tank2 data.
  7. 10-14 tank3 data.
  8. 15-20 spare numbers.
  9. NB computers count up from 0.

move1

This uses dialog boxes to ask for the tank's new speed and heading. These are then written to the data file. The drawing program is then called to update the tank's position and redraw the board.

to move1
make "speed questionbox [Enter speed][Integer -20 - +20]
make "speed first :speed
if :speed>20 [make "speed 20]
if :speed<-20 [make "speed -20]
make "head questionbox [Enter heading][Integer 0 - 355]
make "head first :head
if :head>355 [make "head 0]
if :head<0 [make "head 0]
setitem 2 :board :speed
setitem 3 :board :head
setitem 15 :board 1
openwrite "N:\\logogame\\oxo.txt
setwrite "N:\\logogame\\oxo.txt
repeat 21 [print item repcount-1 :board]
setwrite[]
close "N:\\logogame\\oxo.txt
moveall
draw1
end

moveall

This moves all the vehicles at once. It is triggered by any player who has ordered their tank to move. Players need to move quickly if they are to keep up with the action.

to moveall
openread "N:\\logogame\\oxo.txt
setread "N:\\logogame\\oxo.txt
repeat 21 [setitem repcount-1 :board first readlist ]
close "N:\\logogame\\oxo.txt
repeat 3 [
make "n (repcount-1)*5
make "dx (item :n+2 :board)*(sin item :n+3 :board)
make "dy (item :n+2 :board)*(cos item :n+3 :board)
setitem :n :board :dx+(item :n :board)
setitem :n+1 :board :dy+(item :n+1 :board)
if (item :n :board)>400 [setitem :n :board 400]
if (item :n :board)<-400 [setitem :n :board -400]
if (item :n+1 :board)>300 [setitem :n :board 300]
if (item :n+1 :board)<-300 [setitem :n :board -300]
]
openwrite "N:\\logogame\\oxo.txt
setwrite "N:\\logogame\\oxo.txt
repeat 21 [print item repcount-1 :board]
setwrite[]
close "N:\\logogame\\oxo.txt
end

draw1

This shows the position of tank1 and anything else that it can see. It also decides if the tank's gun is pointing at anything.

to draw1
cs home ht
openread "N:\\logogame\\oxo.txt
setread "N:\\logogame\\oxo.txt
repeat 21 [setitem repcount-1 :board first readlist ]
close "N:\\logogame\\oxo.txt
pu home setxy item 0 :board item 1 :board pd
rt item 3 :board
tank 1
make "dx (item 5 :board)-(item 0 :board)
make "dy (item 6 :board)-(item 1 :board)
pu home pd
make "bearing towards list :dx :dy
make "bearing (item 3 :board)-:bearing
make "dx :dx*:dx
make "dy :dy*:dy
make "d12 :dx+:dy
if :d12<100000 [
pu home setxy item 5 :board item 6 :board pd
rt item 8 :board
tank 2
if and :bearing>-30 :bearing<30 [ if yesnobox[Tank 2 in range and sights][Shoot to kill?][
ifelse (random 10)>6 [messagebox [Tank1 shooting at Tank2][HIT!]
setitem 9 :board (item 9 :board )+20][messagebox [Tank1 shooting at Tank2][MISS!]]
]]]
make "dx (item 10 :board)-(item 0 :board)
make "dy (item 11 :board)-(item 1 :board)
pu home pd
make "bearing towards list :dx :dy
make "bearing (item 3 :board)-:bearing
make "dx :dx*:dx
make "dy :dy*:dy
make "d12 :dx+:dy
if :d12<100000 [
pu home setxy item 10 :board item 11 :board pd
rt item 13 :board
tank 3
if and :bearing>-30 :bearing<30 [ if yesnobox[Tank 3 in range and sights][Shoot to kill?][
ifelse (random 10)>6 [messagebox [Tank1 shooting at Tank3][HIT!]
setitem 14 :board (item 14 :board )+20][messagebox [Tank1 shooting at Tank3][MISS!]]
]]]
openwrite "N:\\logogame\\oxo.txt
setwrite "N:\\logogame\\oxo.txt
repeat 21 [print item repcount-1 :board]
setwrite[]
close "N:\\logogame\\oxo.txt
end

Notes on draw1.

The current set of speeds and positions are read from the shared data file.
The difference in x coordinates and y coordinates is used to find the distance and bearing to the other vehicles.
If these are close enough then they are drawn on the map.
If the enemy tank is close enough to the direction that the tank is pointing in then the shooting dialog boxes are triggered.
Hits are scored by getting more than 6 out of 10 on a random number generator.
Updated data is then written to the data file.

fm1

This repeats a move if the player is happy with the current heading and speed.

to fm1
moveall
draw1
end

score

This reads the data file and prints ou the current damage listing.

to score
openread "N:\\logogame\\oxo.txt
setread "N:\\logogame\\oxo.txt
repeat 21 [setitem repcount-1 :board first readlist ]
close "N:\\logogame\\oxo.txt
print (se "Tank "damage)
repeat 3 [
print (se "Tank repcount item repcount*5-1 :board)
]
end

tank

This draws a tank using the player's colour.

to tank :col
if :col=1 [ setpc 2 setfc 2]
if :col=2 [ setpc 3 setfc 3]
if :col=3 [ setpc 4 setfc 4]
fd 40 rt 90 fd 10 lt 90 fd 15 rt 90 fd 5 rt 90 fd 15 lt 90 fd 10 rt 90 fd 40
rt 90 fd 25 rt 90
rt 25 fd 25 fill bk 25 lt 25
end

Download the code.

tankgame.lgo

If you already have LOGO running then this link might autorun the code. The best bet is probably to right click this link, save the code and then play with it in the normal way. You could run it through Notepad first to do the directory changes as needed.

Last updated 23rd February 2010