Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from slitherlib import Slither, Direction
- from random import randint, random
- def create_new_world(game_size_x, game_size_y):
- world = {}
- world["Width"] = game_size_x
- world["Height"] = game_size_y
- world["Running"] = True
- world["Direction"] = Direction.UP or Direction.DOWN or Direction.RIGHT or Direction.LEFT
- world["Field"] = list()
- world["snakeX"] = game_size_x // 2
- world["snakeY"] = game_size_y // 2
- world["GameOver"] = True
- for i in range(world["Width"]):
- world["Field"].append([])
- for j in range(world["Height"]):
- world["Field"][i].append(None)
- world["Field"][game_size_x // 2][game_size_y // 2] = "O" # The head of the snake will appear
- for i in range(world["Width"]):
- for j in range(world["Height"]):
- if world["Field"][i][j] is None and random() <= 0.01: # 1% of chance to insert the enem(y)(ies) on the world
- world["Field"][i][j] = "X"
- elif world["Field"][i][j] is None and random() <= 0.025: # 2.5% of chance to insert the food(s) on the world
- world["Field"][i][j] = randint(1, 10)
- return
- def game_to_string(world):
- for i in range(world["Width"]):
- for j in range(world["Height"]):
- if world["Field"][i][j] is None:
- world["Field"][i][j] = "."
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement