Untitled

 avatar
unknown
plain_text
21 days ago
1.9 kB
4
Indexable
import random
# Initialize game variables
player_x = 0
player_y = 0
inventory = []
map_size = 100
map_data = []
# Generate map
for i in range(map_size):
    row = []
    for j in range(map_size):
        block_type = random.randint(0, 3)
        if block_type == 0:
            row.append("grass")
        elif block_type == 1:
            row.append("wood")
        elif block_type == 2:
            row.append("stone")
        elif block_type == 3:
            row.append("coal")
    map_data.append(row)
# Game loop
while True:
    # Handle player movement
    if key_press == "left":
        player_x -= 1
    elif key_press == "right":
        player_x += 1
    elif key_press == "space":
        player_y -= 1
    # Handle block breaking
    if mouse_click:
        block_x = mouse_x
        block_y = mouse_y
        block_type = map_data[block_y][block_x]
        if block_type == "grass" and inventory.count("wooden pickaxe") > 0:
            map_data[block_y][block_x] = "empty"
            inventory.append("grass")
        elif block_type == "wood" and inventory.count("stone pickaxe") > 0:
            map_data[block_y][block_x] = "empty"
            inventory.append("wood")
        # Add more block types and crafting logic here
    # Draw game screen
    for y in range(map_size):
        for x in range(map_size):
            block_type = map_data[y][x]
            if block_type == "grass":
                print("G", end="")
            elif block_type == "wood":
                print("W", end="")
            elif block_type == "stone":
                print("S", end="")
            elif block_type == "coal":
                print("C", end="")
            elif block_type == "empty":
                print(" ", end="")
        print()
    # Draw player
    print("Player: (" + str(player_x) + ", " + str(player_y) + ")")
    # Draw inventory
    print("Inventory: " + str(inventory))
Editor is loading...
Leave a Comment