-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMain.rb
More file actions
executable file
·56 lines (40 loc) · 1.09 KB
/
Copy pathMain.rb
File metadata and controls
executable file
·56 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/ruby
['Player', 'Board', 'LoadLevel'].each{|f|require_relative f}
require 'io/console'
brd = nil
ply = nil
# If CL argument exists
if ARGV[0]
# Creates board and player from level passed through CL arguments
brd, ply = load_level_from_args
else
# The size of the array will be n x n
puts "What size will the board be?"
n = gets.chomp.to_i
# Creates a board
brd = Board.new(n)
# Creates a player
ply = Player.new(0,0,brd.get_board())
# Puts a '#' int the position [2][2].
brd.set_obstacle(2,2)
end
#Repeat indefinately
while true do
system("clear") # Clears the terminal every loop (to make it nice :D )
brd.draw() # Draws the board
#Prints score, posibly make a special class to handle statistics?
puts "Score: " + ply.get_score.to_s
#checks if the player has won
if ply.get_score == brd.star_count
puts "RubyMan ate all the stars! You win!"
break
end
# Gets an input from the user correponding to the direction
tt = STDIN.getch
if tt == 'q'
system('clear')
break
else
ply.move(tt)
end
end # End the loop