https://pastein.ru/t/EpV
скопируйте уникальную ссылку для отправки
from mcpi.minecraft import Minecraft
import mcpi.block as block
import minecraftstuff
import time
import random
import threading
from mcpi import minecraft
# Константы арены
ARENAX = 10
ARENAZ = 20
ARENAY = 3
# Создание арены
def createArena(pos):
mc = Minecraft.create()
mc.setBlocks(pos.x - 1, pos.y, pos.z - 1,
pos.x + ARENAX + 1, pos.y - 3, pos.z + ARENAZ + 1,
block.GRASS.id)
mc.setBlocks(pos.x - 1, pos.y + 1, pos.z - 1,
pos.x + ARENAX + 1, pos.y + ARENAY, pos.z + ARENAZ + 1,
block.GLASS.id)
mc.setBlocks(pos.x, pos.y + 1, pos.z,
pos.x + ARENAX, pos.y + ARENAY, pos.z + ARENAZ,
block.AIR.id)
# Создание препятствий
# Стена
def theWall(arenaPos, wallZPos):
mc = Minecraft.create()
wallPos = minecraft.Vec3(arenaPos.x, arenaPos.y + 1, arenaPos.z + wallZPos)
wallShape = minecraftstuff.MinecraftShape(mc, wallPos)
wallShape.setBlocks(
0, 1, 0,
ARENAX, ARENAY - 1, 0,
block.BRICK_BLOCK.id)
while not gameOver:
wallShape.moveBy(0, 1, 0)
time.sleep(1)
wallShape.moveBy(0, -1, 0)
time.sleep(1)
# Река
def theRiver(arenaPos, riverZPos):
mc = Minecraft.create()
RIVERWIDTH = 4
BRIDGEWIDTH = 2
mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos,
arenaPos.x + ARENAX, arenaPos.y, arenaPos.z + riverZPos + RIVERWIDTH - 1,
block.AIR.id)
mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos,
arenaPos.x + ARENAX, arenaPos.y - 2, arenaPos.z + riverZPos + RIVERWIDTH - 1,
block.WATER.id)
bridgePos = minecraft.Vec3(arenaPos.x, arenaPos.y, arenaPos.z + riverZPos + 1)
bridgeShape = minecraftstuff.MinecraftShape(mc, bridgePos)
bridgeShape.setBlocks(
0, 0, 0,
BRIDGEWIDTH - 1, 0, RIVERWIDTH - 3,
block.WOOD_PLANKS.id)
# Движение моста влево и вправо
# Сколько шагов между левым и правым краем арены
steps = ARENAX - BRIDGEWIDTH + 1
while not gameOver:
for left in range(0, steps):
bridgeShape.moveBy(1, 0, 0)
time.sleep(1)
for right in range(0, steps):
bridgeShape.moveBy(-1, 0, 0)
time.sleep(1)
def theHoles(arenaPos, holesZPos):
mc = Minecraft.create()
HOLES = 15
HOLESWIDTH = 3
while not gameOver:
holes = []
for count in range(0, HOLES):
x = random.randint(arenaPos.x, arenaPos.x + ARENAX)
z = random.randint(arenaPos.z + holesZPos, arenaPos.z + holesZPos + HOLESWIDTH)
holes.append(minecraft.Vec3(x, arenaPos.y, z))
for hole in holes:
mc.setBlock(hole.x, hole.y, hole.z, block.WOOL.id, 15)
time.sleep(0.25)
for hole in holes:
mc.setBlocks(hole.x, hole.y, hole.z,
hole.x, hole.y - 2, hole.z,
block.AIR.id)
time.sleep(2)
for hole in holes:
mc.setBlocks(hole.x, hole.y, hole.z,
hole.x, hole.y - 2, hole.z,
block.GRASS.id)
time.sleep(0.25)
# Размещение алмазов
def createDiamonds(arenaPos, number):
mc = Minecraft.create()
for diamond in range(0, number):
x = random.randint(arenaPos.x, arenaPos.x + ARENAX)
z = random.randint(arenaPos.z, arenaPos.z + ARENAZ)
mc.setBlock(x, arenaPos.y + 1, z, block.DIAMOND_BLOCK.id)
# Основная программа
# Создание объекта Minecraft
mc = Minecraft.create()
# Создание флага gameOver
gameOver = False
# Позиция арены
arenaPos = mc.player.getTilePos()
# Построение арены
createArena(arenaPos)
WALLZ = 10
wall_t = threading.Thread(
target=theWall,
args=(arenaPos, WALLZ))
wall_t.start()
RIVERZ = 4
river_t = threading.Thread(
target=theRiver,
args=(arenaPos, RIVERZ))
river_t.start()
HOLESZ = 15
holes_t = threading.Thread(
target=theHoles,
args=(arenaPos, HOLESZ))
holes_t.start()
# Константы уровней
LEVELS = 3
DIAMONDS = [3, 5, 9]
TIMEOUTS = [30, 25, 20]
# Установка уровня и очков
level = 0
points = 0
# Игровой цикл, пока игра не закончится
while not gameOver:
createDiamonds(arenaPos, DIAMONDS[level])
diamondsLeft = DIAMONDS[level]
mc.player.setPos(arenaPos.x + 1, arenaPos.y + 1, arenaPos.z + 1)
start = time.time()
levelComplete = False
while not gameOver and not levelComplete:
time.sleep(0.1)
hits = mc.events.pollBlockHits()
for hit in hits:
blockHitType = mc.getBlock(hit.pos.x, hit.pos.y, hit.pos.z)
if blockHitType == block.DIAMOND_BLOCK.id:
mc.setBlock(hit.pos.x, hit.pos.y, hit.pos.z, block.AIR.id)
diamondsLeft = diamondsLeft - 1
pos = mc.player.getTilePos()
if pos.y < arenaPos.y:
mc.player.setPos(arenaPos.x + 1, arenaPos.y + 1, arenaPos.z + 1)
# Достиг ли игрок конца арены и собрал все алмазы?
if pos.z == arenaPos.z + ARENAZ and diamondsLeft == 0:
levelComplete = True
# Истекло ли время
secondsLeft = TIMEOUTS[level] - (time.time() - start)
if secondsLeft < 0:
gameOver = True
mc.postToChat("Время истекло")
# Уровень пройден?
if levelComplete:
points = points + (DIAMONDS[level] * int(secondsLeft))
mc.postToChat("Уровень пройден - Очки = " + str(points))
level = level + 1
if level == LEVELS:
gameOver = True
mc.postToChat("Поздравляем - Все уровни пройдены")
mc.postToChat("Игра оконечена - набранные очки = " + str(points))