-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeknight.rb
More file actions
126 lines (98 loc) · 2.26 KB
/
Copy paththeknight.rb
File metadata and controls
126 lines (98 loc) · 2.26 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#The Knight.
#TODO:
#1. Make the game "turn based"
#2. Plot the positions of the players somehow
class Character
def initialize(name)
@name = name
@x = 1
@y = 1
@health = 100
end
attr_accessor :x
attr_accessor :y
attr_accessor :health
def printStatus()
puts ""
puts "-----------"
puts @name
puts @x
puts @y
puts @health
puts "-----------"
puts ""
end
#def plotPosition()
#TODO: Plot position of both players somehow.
#end
def moveUp()
@y += 1
puts "You took a step up!"
end
def moveDown()
@y -= 1
puts "You took a step down"
end
def moveLeft()
@x -=1
puts "you went left"
end
def moveRight()
@x +=1
puts "you went right"
end
def attack()
#TODO: The players must be at least on one of the same axis to attack.
@health -= 10
puts "Boom, that one hurt him!"
end
def fightEnergyLoss() #It takes energy to fend off an attacker :)
@health -= 1
end
def lowHpMsg()
puts "Uh oh, it's going low!"
end
#TODO: These functions are works in progress and not very good
def switchTurn()
puts ""
puts "-----------"
puts "The last player to play was: "
puts @name
puts "-----------"
puts ""
currentTurn() #todo: pass the current player name into the currentTurn function and update the currentTurn variable
end
def currentTurn()
currentTurn = @name
return currentTurn
end
#These functions are works in progress and not very good
end
player = Character.new("James the Knight")
enemy = Character.new("Robin the Foul")
enemy.y = 2
system "clear" or system "cls"
command = ""
while true
puts "Welcome to The Knight!"
puts "You can 'attack', 'move up', 'move down', 'move left' or 'move right'"
if command == "attack"
#TODO: Only allow an attack if it is your turn
enemy.attack()
player.fightEnergyLoss()
elsif command == "move up"
player.moveUp()
elsif command == "move left"
player.moveLeft()
elsif command == "move down"
player.moveDown()
elsif command == "move right"
player.moveRight()
end
player.printStatus()
enemy.printStatus()
puts "Enter your command"
command = gets.chomp
# optional is to clear the prompt
system "clear" or system "cls"
end