diff --git a/environment.rb b/environment.rb new file mode 100644 index 000000000..4b8731045 --- /dev/null +++ b/environment.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +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} + 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: '', status: nil} + @extra_shift = { id: @id, hours: 8, payment: 0.0, facility: '', status: nil} + end + end + end +end diff --git a/error_test.rb b/error_test.rb new file mode 100644 index 000000000..54aa6f040 --- /dev/null +++ b/error_test.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require_relative './environment' + +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) + 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 + + def new_mission(name: nil, objective: nil, pack: nil) + 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 + +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] diff --git a/game.rb b/game.rb new file mode 100644 index 000000000..864ce66bb --- /dev/null +++ b/game.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require './environment' + +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: %i[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]