Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. from slitherlib import Slither, Direction
  2. from random import randint, random
  3.  
  4.  
  5. def create_new_world(game_size_x, game_size_y):
  6. world = {}
  7. world["Width"] = game_size_x
  8. world["Height"] = game_size_y
  9. world["Running"] = True
  10. world["Direction"] = Direction.UP or Direction.DOWN or Direction.RIGHT or Direction.LEFT
  11. world["Field"] = list()
  12. world["snakeX"] = game_size_x // 2
  13. world["snakeY"] = game_size_y // 2
  14. world["GameOver"] = True
  15. for i in range(world["Width"]):
  16. world["Field"].append([])
  17. for j in range(world["Height"]):
  18. world["Field"][i].append(None)
  19.  
  20. world["Field"][game_size_x // 2][game_size_y // 2] = "O" # The head of the snake will appear
  21.  
  22. for i in range(world["Width"]):
  23. for j in range(world["Height"]):
  24. if world["Field"][i][j] is None and random() <= 0.01: # 1% of chance to insert the enem(y)(ies) on the world
  25. world["Field"][i][j] = "X"
  26. elif world["Field"][i][j] is None and random() <= 0.025: # 2.5% of chance to insert the food(s) on the world
  27. world["Field"][i][j] = randint(1, 10)
  28. return
  29.  
  30.  
  31. def game_to_string(world):
  32. for i in range(world["Width"]):
  33. for j in range(world["Height"]):
  34. if world["Field"][i][j] is None:
  35. world["Field"][i][j] = "."
  36. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement