Guest User

Untitled

a guest
Oct 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. require 'curses'
  2. Curses.init_screen
  3. Curses.stdscr.keypad true
  4. maze = Array.new
  5.  
  6. file = File.new("maze.txt","r")
  7. while (line = file.gets)
  8. maze.push line.chomp
  9. end
  10. xcoordinate = 2
  11. ycoordinate = 2
  12. monsterxcoord = 22
  13. monsterycoord = 39
  14.  
  15. loop do
  16. case Curses.getch
  17. when ?w
  18. if (maze[ycoordinate - 1][xcoordinate] != "*")
  19. maze[ycoordinate - 1][xcoordinate] = "@"
  20. maze[ycoordinate][xcoordinate] = "-"
  21. ycoordinate = ycoordinate - 1
  22. end
  23. when ?s
  24. if (maze[ycoordinate + 1][xcoordinate] != "*")
  25. maze[ycoordinate + 1][xcoordinate] = "@"
  26. maze[ycoordinate][xcoordinate] = "-"
  27. ycoordinate = ycoordinate + 1
  28. end
  29. when ?a
  30. if (maze[ycoordinate][xcoordinate - 1] != "*")
  31. maze[ycoordinate][xcoordinate - 1] = "@"
  32. maze[ycoordinate][xcoordinate] = "-"
  33. xcoordinate = xcoordinate - 1
  34. end
  35. when ?d
  36. if (maze[ycoordinate][xcoordinate + 1] != "*")
  37. maze[ycoordinate][xcoordinate + 1] = "@"
  38. maze[ycoordinate][xcoordinate] = "-"
  39. xcoordinate = xcoordinate + 1
  40. end
  41. end
  42. Curses.clear
  43. Curses.refresh
  44. maze.each do |element|
  45. puts element + "\r\n"
  46. end
  47. end
Add Comment
Please, Sign In to add comment