-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
josechavez--practice5 #30
base: practice-day5
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
module Environment | ||
class Depot | ||
attr_accessor :packs | ||
def initialize | ||
@packs = { | ||
simple_transportation_pack: { | ||
intelligence: [:cellphone], | ||
items: [:medipack, :chevy_versa] | ||
}, | ||
standard_transportation_pack: { | ||
intelligence: [:cellphone, :antenna], | ||
arsenal: [:colt_1911], | ||
items: [:handcuffs, :medipack, :chemistry, :chevy_versa] | ||
}, | ||
simple_mission_pack: { | ||
intelligence: [:infopack, :laptop, :cellphone, :antenna], | ||
arsenal: [[:colt_1911], [:handcuffs, :medipack, :chemistry, :financial]] | ||
}, | ||
standar_mission_pack: { | ||
intelligence: [:infopack, :laptop, :cellphone, :antenna], | ||
arsenal: [:remington_870, :colt_1911, :machete, :hatchet], | ||
items: [:handcuffs, :medipack, :chemistry, :financial] | ||
} | ||
} | ||
end | ||
end | ||
|
||
class Control | ||
attr_accessor :missions | ||
@@modes = [:paused, :aborted, :accomplished, :failed] | ||
def initialize | ||
@missions = {} | ||
end | ||
|
||
def new_mission name:, objective:, pack: | ||
@missions[name] = { | ||
objective: objective, | ||
status: :active, | ||
pack: pack | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would state hashes like this in one line if possible. |
||
end | ||
|
||
@@modes.each do |mode| | ||
define_method("set_mission_to_#{mode}") do |mission| | ||
@missions[mission][:status] = mode | ||
end | ||
end | ||
end | ||
|
||
|
||
class Human | ||
attr_accessor :id, :name, :personal_data, :professional_data | ||
|
||
def initialize name: nil | ||
@name = name | ||
@id = object_id | ||
end | ||
|
||
define_method("set_personal_data") do |surname:, age:, country:, language:, marital_status:, children:| | ||
@personal_data = { | ||
surname: surname, | ||
age: age, | ||
country: country, | ||
language: language, | ||
marital_status: marital_status, | ||
children: children | ||
} | ||
end | ||
|
||
define_method("set_professional_data") do |position:, occupation:, skills: , observations: | | ||
@professional_data = { | ||
position: position, | ||
occupation: occupation, | ||
skills: skills, | ||
observations: observations | ||
} | ||
end | ||
|
||
class Worker < Human | ||
attr_accessor :standard_shift, :extra_shift | ||
|
||
def initialize name | ||
super name: name | ||
@standard_shift = { | ||
id: @id, | ||
hours: 8, | ||
payment: 0.0, | ||
facility: "", #(or nil) | ||
status: nil #(will be of type ) | ||
} | ||
@extra_shift = { | ||
id: @id, #Id of the object when created. | ||
hours: 8, | ||
payment:0.0, | ||
facility: "", #(or nil) | ||
status: nil #(will be of type Symbol) | ||
} | ||
end | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An extra empty line at the end of the file would be great. It is taken as a good practice. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require_relative './environment.rb' | ||
|
||
class ErrorTest | ||
include Environment | ||
attr_accessor :board, :depot, :control | ||
|
||
def initialize | ||
@board = { | ||
players: {}, | ||
control: {}, | ||
status: nil | ||
} | ||
@depot = Environment::Depot.new | ||
@control = Environment::Control.new | ||
end | ||
|
||
def new_worker name: nil | ||
begin | ||
raise NameError, 'Name cannot be empty' if name.nil? | ||
|
||
@board[:players].store name, Environment::Human::Worker.new(name) | ||
rescue NameError => e | ||
puts "Error: #{e}" | ||
end | ||
end | ||
|
||
|
||
|
||
def new_mission name: nil, objective: nil, pack: nil | ||
begin | ||
raise NameError, 'name cannot be empty' if name.nil? | ||
raise NameError, 'Objetive cannot be empty' if objective.nil? | ||
raise NameError, 'Pack cannot be empty' if pack.nil? | ||
|
||
@control.new_mission(name: name, objective: objective, pack: pack) | ||
@board[:control][:missions] = @control.missions | ||
rescue NameError => e | ||
puts "Error: #{e}" | ||
end | ||
end | ||
end | ||
|
||
error_test = ErrorTest.new | ||
player = error_test.new_worker | ||
|
||
player2 = error_test.new_mission name: "Fer", objective: "Conquer the zone" | ||
|
||
# player1 = error_test.new_worker name: 'Diego' | ||
# diego.set_personal_data(surname: 'Mota', age: 40, marital_status: :single, children: 0, country: :mx, language: :es) | ||
# diego.set_professional_data(position: 'SE', occupation: 'IT', skills: [:ruby, :blender], observations: 'none') | ||
# puts "#{diego.name}, #{diego.class}", diego.personal_data, diego.professional_data | ||
|
||
# name = :alpha; objective = 'Get Alpha to the base'; pack = :simple_transportation_pack | ||
# error_test.new_mission(name: name, objective: objective, pack: error_test.depot.packs[pack]) | ||
# puts error_test.control.missions[:alpha] | ||
# error_test.control.set_mission_to_accomplished(:alpha) and puts error_test.control.missions[:alpha] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, I would try to use an extra empty line at the end of the file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require './environment.rb' | ||
|
||
class Game | ||
attr_accessor :board, :depot, :control | ||
|
||
def initialize | ||
@board = { | ||
players: {}, | ||
control: {}, | ||
status: nil | ||
} | ||
@depot = Environment::Depot.new | ||
@control = Environment::Control.new | ||
end | ||
|
||
|
||
def new_worker name: nil | ||
worker = Environment::Human::Worker.new(name) | ||
@board[:players][name] = worker | ||
end | ||
|
||
def new_mission name:, objective:, pack: | ||
@control.new_mission(name: name, objective: objective, pack: pack) | ||
@board[:control][:missions] = @control.missions | ||
end | ||
end | ||
|
||
game = Game.new | ||
diego = game.new_worker name: 'Diego' | ||
diego.set_personal_data(surname: 'Mota', age: 40, marital_status: :single, children: 0, country: :mx, language: :es) | ||
diego.set_professional_data(position: 'SE', occupation: 'IT', skills: [:ruby, :blender], observations: 'none') | ||
puts "#{diego.name}, #{diego.class}", diego.personal_data, diego.professional_data | ||
|
||
name = :alpha; objective = 'Get Alpha to the base'; pack = :simple_transportation_pack | ||
game.new_mission(name: name, objective: objective, pack: game.depot.packs[pack]) | ||
puts game.control.missions[:alpha] | ||
game.control.set_mission_to_accomplished(:alpha) and puts game.control.missions[:alpha] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation should be two spaces, be careful when setting the TAB range in your IDE, sometimes Git just ignore the setting and take a tab as a 4-spaces-TAB.