Testowo z dźwigiem. Do zmiany.
This commit is contained in:
parent
f65d014f43
commit
904a9199eb
|
@ -0,0 +1,8 @@
|
|||
pick
|
||||
put
|
||||
lift
|
||||
place
|
||||
leave
|
||||
load
|
||||
unload
|
||||
transport
|
|
@ -0,0 +1,29 @@
|
|||
require 'json'
|
||||
class Crane
|
||||
attr_accessor :name, :words
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
|
||||
def introduce
|
||||
puts "Hello, sir. I'm #{name} the Crane."
|
||||
end
|
||||
|
||||
def get_words
|
||||
file = File.read('test.json')
|
||||
@words = JSON.parse(file)
|
||||
#puts words
|
||||
end
|
||||
|
||||
def if_understand
|
||||
return @words.length > 1
|
||||
end
|
||||
|
||||
def response
|
||||
file = File.read('past_forms.json')
|
||||
past_formes = JSON.parse(file)
|
||||
puts (if @words.values.any? { |e| @words.key(e).eql? "movement" } then "I #{past_formes[@words["movement"]] + ' ' + @words["directions"]}" else "Ooops" end)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
require 'json'
|
||||
|
||||
#txt = open("actions.txt")
|
||||
#print txt.read
|
||||
txt = open("input.txt")
|
||||
#puts txt.read
|
||||
filenames = ["actions.txt", "directions.txt", "movement.txt"]
|
||||
dictionary = {}
|
||||
#filenames.each do |name|
|
||||
#f = File.read(name).include?
|
||||
#end
|
||||
txt.each_line do |line|
|
||||
filenames.each do |name|
|
||||
if File.read(name).include?line
|
||||
dictionary[name.chomp('.txt')] = line.chomp("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts dictionary
|
||||
File.open("test.json", "w") {|f| f.write(dictionary.to_json)}
|
|
@ -0,0 +1,10 @@
|
|||
right
|
||||
left
|
||||
forward
|
||||
backwards
|
||||
onwards
|
||||
back
|
||||
west
|
||||
east
|
||||
north
|
||||
south
|
|
@ -0,0 +1,4 @@
|
|||
forward
|
||||
chess
|
||||
move
|
||||
load
|
|
@ -0,0 +1,8 @@
|
|||
require_relative 'crane_class'
|
||||
|
||||
c = Crane.new("Roman")
|
||||
c.introduce
|
||||
c.get_words
|
||||
puts c.words
|
||||
puts h = c.if_understand
|
||||
c.response
|
|
@ -0,0 +1,7 @@
|
|||
go
|
||||
move
|
||||
come
|
||||
travel
|
||||
proceed
|
||||
back
|
||||
head
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"go":"went",
|
||||
"move":"moved",
|
||||
"come":"came",
|
||||
"travel":"traveled",
|
||||
"proceed":"proceeded",
|
||||
"back":"backed",
|
||||
"head":"headed"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"directions":"forward","movement":"move","actions":"load"}
|
Loading…
Reference in New Issue