-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBoard.rb
More file actions
79 lines (59 loc) · 1.75 KB
/
Copy pathBoard.rb
File metadata and controls
79 lines (59 loc) · 1.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'colorize'
class Board
@board
@star_count
PLAYER_COLOR_CONST = :yellow
WALL_COLOR_CONST = :red
STAR_COLOR_CONST = :green
# Creates an array with the specified size
def initialize(size)
@board = Array.new(size) {Array.new(size){ '*' } }
@star_count = size*size -2 #only temporary. should be dynamically counted during level build. -2 because on the default board you override two with a wall and the player.
end
# Draw board in terminal
def draw
row = 0
# Repeats the proces n times so as to print every row in the array
@board.size.times do
col = 0
@board[row].size.times do
# color the player icon
# Creates spacing between each item so it looks nicer
if @board[row][col] == 'A'
print @board[row][col].colorize(PLAYER_COLOR_CONST) + ' '
elsif @board[row][col] == '#'
print @board[row][col].colorize(WALL_COLOR_CONST) + ' '
elsif @board[row][col] == '*'
print @board[row][col].colorize(STAR_COLOR_CONST) + ' '
elsif @board[row][col] == ' '
print @board[row][col] + ' '
end
col += 1
end
puts
row += 1
end
puts "\nPress 'q' to exit or the WASD keys to move"
end
# Returns the current board array
def get_board
@board
end
#gets the total number of stars originally on the board
def star_count
@star_count
end
#sets the total number of stars originally on the board
def star_count=(count)
@star_count = count
end
# Sets the board array
def set_board(board)
@board = board
end
# This method will be removed once the boards are loaded from an external file
# Sets obstacle
def set_obstacle(y, x)
@board[y][x] = '#'
end
end