Operation Counterstrike – A Minecraft Game For The Pi


After my “Building A Castle In Minecraft With Python” article I wanted to create a Minecraft game that was a bit more interactive. The “find a diamond” type game had already been done so I decided to do a slightly different version with a time limit.

“Operation Counterstrike” was born.

The script randomly places a number of TNT blocks around the map and the player has to find and destroy them all before the timers run out. As in my castle script you can dive in and start adjusting the Python code to change the game play or implement your own ideas.

Initial Setup

In order to make use of this script you will need have Minecraft installed on your Pi with the Python API ready to use. Follow these tutorials if in doubt :

Download Script

The game script needs to be placed into the directory created when setting up the API. In the API setup tutorial linked above I use /home/pi/mcpi-api. You can download the script directly to your Pi using using :

cd ~/mcpi-api
wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/minecraft/counterstrike.py

Alternatively here is a link to the Python game script.

Minecraft TNT blockRunning The Game

Launch Minecraft on the Pi and create a new world. To free the mouse cursor you can press the TAB key.

To run the game you will need to launch the script either from an LXTerminal window on the Pi or a command line on a remote machine that is connected to the Pi (i.e. using Putty).

Navigate to the API folder that you copied the script into and execute it.

cd ~/mcpi-api
python counterstrike.py

Adding a number after the script will set the number of devices to generate. For example :

python counterstrike.py 7

will generate 7. If you do not specify a number the default is 3.

Playing The Game

Once the script is running you should see messages appear in your Minecraft window. You will be told how many devices are out there as well as status messages.

The devices are placed in random positions around the map. Devices on land will be buried under the surface whereas devices in water will rest on the sea-bed. Each device has a randomly generated timer ranging from 80 to 180 seconds.

Operation Counterstrike Screenshot #2

The status updates will report the distance (R) to the nearest device and the lowest timer count (T). The nearest device may not always have the lowest count so you may have less time than you think to find the device that is about to explode!

When you destroy a device you will get bonus time added to all the remaining devices.

Operation Counterstrike Screenshot #1

Find and destroy all the bombs before you run out of time!

PiFace Control & Display

One of my reasons for creating this script was to test my new PiFace Control & Display add-on. This allows you to easily add a 16×2 LCD screen to the Pi with switches. Within the script you will find 5 lines that relate to configuring the PiFace and outputting messages to it.

Operation Counterstrike PiFace

If you want to use one then remove the # symbol from the front of the following 5 lines :

#import pifacecad as pf
#cad = pf.PiFaceCAD()

Have fun and happy hunting!

Possible Future Updates

  • Remove all TNT blocks when player fails to find them so they aren’t left in world
  • Place bonus blocks that give the player extra time or extra clues to TNT block positions
  • Limit the maximum timer value due to bonuses


    • The screen was just there for a bit of fun. I wanted to show beginners that you could combine hardware with your Minecraft creations and weren’t limited to the on-screen world.

  1. Darkflame2308 on

    You should make the tnt explode! You might be able to trigger an explosion at those coordinates, and change the default blast size. Make the world go boom!

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.