-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCharacter.rb
More file actions
76 lines (56 loc) · 1.31 KB
/
Copy pathCharacter.rb
File metadata and controls
76 lines (56 loc) · 1.31 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
class Character
# variables for tracking the current position of the charac
@board
@x = 0 # position in the x dimension
@y = 0 # position in the y dimension
#makes @grid the same as the board
def initialize (board)
set_board(board)
end
# every movement method checks will make nothing if the space where
# the user wants to move to contains a '#'
#
# moves up one space. In the X dimension
def move_up
@y -= 1 unless @y == 0 || @board[(@y - 1)][@x] == "#"
# remeber that the first row is 0
end
# moves one space to the right in the Y dimension
def move_right
@x += 1 unless @x == (@board[0].size - 1) || @board[@y][(@x + 1)] == "#"
end
# moves one space down in the x dimension
def move_down
@y += 1 unless @y == (@board.size - 1) || @board[(@y + 1)][@x] == "#"
end
# moves one space to the left in Y dimension
def move_left
@x -= 1 unless @x == 0 || @board[@y][(@x - 1)] == "#"
end
#changes board
def set_board( board )
@board = board
end
#gets board
def get_board
@board
end
# changes position_x
def set_x_position( pos )
@x = pos
end
#changes position_y
def set_y_position( pos )
@y = pos
end
# draws the character in the board
def draw_in_board(char)
@board[@y][@x] = char
end
def get_x_pos
return @x
end
def get_y_pos
return @y
end
end