Minecraft Mine-SweeperYou may remember or have even played the classic Minesweeper game which dates back to the 1960's as one of the earliest mainframe computer games. Over the years it has been bundled with most operating systems and even featured as a mini game variation on the New Super Mario Bros. This project will walk you through how you can create a simple version in Minecraft, yes a Minecraft Mine-Sweeper! The program sets out a arena of blocks, one of the blocks is a Mine, each time you stand on a block you turn it to gold and collect points, but, watch out for the Mine as it will end the game, (and cover you in lava!).
1. Getting StartedThe first step is to ensure that your Raspberry Pi is up to date,
In the LX Terminal type: sudo apt-get upgrade sudo apt-get update Next load up the Python editor, IDLE and start a new window. You need to import the following modules by typing, import random import time from mcpi import minecraft mc = minecraft.Minecraft.create() 2. Create the BoardTo create the arena or board which will contain the Mine is a simple step, firstly you find your players currently location in the world using the code,
x, y, z = mc.player.getPos() Then use the mc.setBlocks code to to place blocks, mc.setBlocks(x, y-1, z, x+20, y-1, z+20, 58). The 58, is the ID of the block which is a crafting table. You can chose your own material and change it by alerting this number, a list of block IDs can be found here: You can also increase or decrease the size of the board by changing the + 20. In the code example above the board size is 20 x 20 blocks which gives you a 400 hundred block arena to play within. 3. Creating the MineTo create the Mine you use a code to generate a random number between 1 and 10, mine = random.randrange(0, 11, 1)
In step 2 you found the player's location on the board, this data, the X, Y, and Z position can be used to place the Mine on the board. Take the player's position and add the random number to the position - this creates a random Mine block anywhere on the board. mine_x = int(x+mine) mine_y = int(y-1) mine_z = int(z+mine) The last step is to use the Set Block to place the Mine, use the code below, mc.setBlock(mine_x, mine_y, mine_z,58) The 58 is the block ID which you can change if your wish to see where the Mine has been placed. This useful for testing that the rest of the code is working correctly. |
Minecraft Mine-Sweeper4. Check the Player's PositionThe last part of the game is to create a while loop which checks whether you are standing on the Mine, if you are then it is Game Over, if not, then the block changes to gold. Because the player's position is used to build the original board and place the Mine you are required to find the players position again and store it as new variable (otherwise the board shifts around). To change the block to gold when the player is standing on the block, use the code,
mc.setBlock(x1, y1-1, z1, 41), 41 is the ID for gold. You can customise the block to change to any block you wish. However, if you trigger the Mine then you can flood the board with Lava: mc.setBlocks(x-5, y+1, z-5, x+5, y+2, z+5, 10) while True: x1, y1, z1 = mc.player.getTilePos() time.sleep(0.1) if (x1, y1-1, z1) == (mine_x, mine_y, mine_z): mc.setBlocks(x-5, y+1, z-5, x+5, y+2, z+5, 10) mc.postToChat("G A M E O V E R") break else: mc.setBlock(x1, y1-1, z1, 41) mc.postToChat("GAME OVER") Use the mc.postToChat to send and display a message in the Minecraft World updating you that the game is over - it will also display a score which is based on the number of seconds that you remained alive before your triggered to Mine - The full and complete program can be download below form GitHub, feel free to develop the program further, maybe add more mines, make the board bigger or even indicate to the player how close to the mine they are. 5. Download the Code |
- Home
- Python
- Ras Pi
-
Pi Hardware
- Pi-Hacks
-
Pi-Hacks 2
- The Joker
- Hologram Machine
- Google Vision: Camera Tell
- Yoda Tweets
- Pi Phone
- Darth Beats
- Twitter Keyword Finder
- Crimbo Lights Hack
- Xmas Elf
- Halloween 2016
- Halloween Hack 2015
- Socrative Zombie
- Voice Translation
- The Blue-Who Finder
- GPIO, Twitter
- Pi Chat Bot >
- PiGlow & Email
- Pibrella Alarm System
- SMS with Python >
- Pi-Hacks 3
- Minecraft
- Computing
- Contact Me
- Random Hacks