Logo Interactive Grid Based Game.
This is a simple grid based game, similar to draughts, which runs within Logo and uses a central text file for the map and player pieces. All graphics are drawn direct to the Logo screen.
The program contains several elements.
- setup: This sets the board up and gives the players' pieces their start positions. Both players can run this program at the start.
- drawgrid: This generates the background map grid.
- makemap draws the map right at the start.
- readmap reads the map from the textfile.
- writemap writes the map to the textfile.
- playermap: This draws the pieces onto the grid.
- slide: allows players to slide a piece one drid position N,S,E or W.
- hop: allows players to hop over one piece (as in draughts). The piece hopped over is removed if it belongs to the opposition.
- checklegal: checks if a slide move is legal.
- checkhop1:checks that there is a piece to be hopped over.
- checkhop2: checks that there is any empty position to hop into.
To play the game:
- Create a network folder called logogame on the drive which matches the drive name in the program. (W: If need be change this by using 'EDall' in seek and destroy mode.)
- Each player then runs setup.
- Each player then makes moves like mad until no legal moves are left.
- The player controlling the biggest area of the board is the winner.
- You can use command line macros.
- Most errors will not stop the game so just ignore them.
- If the 'file open error' occurs then just close it at the command line and carry on.
Complete gridgame.lgo listing.
Making the board and pieces. | |
makemapThis creates the game. It writes the game information to a text file called "W:\\logogame\\mygame\\mpboard.txt This file is a primitive database. In the current form of the game it contains 132 numbers. The board is a 11x12 grid. All positions are set to 0. Then red 1's and blue 2's are added. Finally it is written to the server.
to makemap playermapThis draws the pieces onto the board. It uses drawgrid first. Bitmap images of the units could be used instead etc. but this would be slower.
to playermap |
drawgridThis generates a grid on which to play the game. It uses LOGO's inbuilt drawing commands as these run much quicker than loading bitmaps. It also uses labels to generate the grid coordinates.
to drawgrid setupThis calls all the programs needed to get the game going.
to setup To run setup type: setup |
Moving the pieces around. | |
slideThis allows the player to slide one grid position in the N,S,E or W directions. Illegal moves are ignored. After a legal move the map is redrawn.
to slide :x :y :direction To use slide type: slide STARTX STARTY "DIRECTION eg slide 2 3 "n |
hopAllows the player to hop over a piece in the N, S, E or W directions. The new positions are calculated and then the legality of the move is checked. If the move is legal then the pieces are adjusted and the board is redrawn. Illegal moves are either ignored or will result in an error message that won't stop the game.
to hop :x :y :direction To use hop type: hop STARTX STARTY "DIRECTION eg hop 2 3 "n |
Checking that moves are legal. | |
checklegal
to checklegal :xin :yin :x1in :y1in |
checkhop1 and 2
to checkhop1 :xin :yin :x1in :y1in |
Reading and writing to the server | |
readmapReads the :mpboard array from the text file.
to readmap |
writemapWrites the :mpboard array to a text file.
to writemap NB the commonest crash occurs when the players clash for access to the txt file. This will result in a 'file already open' error. To resolve this you must use the command line code below to manually close the file.
close "F:\\logogame\\mygame\\mpboard.txt |
Screenshots and MACROS | |
Moving 3 pieces side by side repeat 3 [ slide repcount 1 "n] before after |
Hopping 3 side by side repeat 3 [ hop repcount 0 "n] before after |
Extension ideas.'Fog of War' could be used so that you can only 'see' positions within 2 grid moves of your own pieces. A scoring function could be added and squares marked to show which player last visited, and therefore controls, them. |
Last updated 24th February 2010