Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'curses'
- Curses.init_screen
- Curses.stdscr.keypad true
- maze = Array.new
- file = File.new("maze.txt","r")
- while (line = file.gets)
- maze.push line.chomp
- end
- xcoordinate = 2
- ycoordinate = 2
- monsterxcoord = 22
- monsterycoord = 39
- loop do
- case Curses.getch
- when ?w
- if (maze[ycoordinate - 1][xcoordinate] != "*")
- maze[ycoordinate - 1][xcoordinate] = "@"
- maze[ycoordinate][xcoordinate] = "-"
- ycoordinate = ycoordinate - 1
- end
- when ?s
- if (maze[ycoordinate + 1][xcoordinate] != "*")
- maze[ycoordinate + 1][xcoordinate] = "@"
- maze[ycoordinate][xcoordinate] = "-"
- ycoordinate = ycoordinate + 1
- end
- when ?a
- if (maze[ycoordinate][xcoordinate - 1] != "*")
- maze[ycoordinate][xcoordinate - 1] = "@"
- maze[ycoordinate][xcoordinate] = "-"
- xcoordinate = xcoordinate - 1
- end
- when ?d
- if (maze[ycoordinate][xcoordinate + 1] != "*")
- maze[ycoordinate][xcoordinate + 1] = "@"
- maze[ycoordinate][xcoordinate] = "-"
- xcoordinate = xcoordinate + 1
- end
- end
- Curses.clear
- Curses.refresh
- maze.each do |element|
- puts element + "\r\n"
- end
- end
Add Comment
Please, Sign In to add comment