Class: Demigod
- Inherits:
-
Object
- Object
- Demigod
- Defined in:
- lib/demigodGame/Demigod.rb
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#initialize(world, resources = GameData::STARTING_RESOURCES) ⇒ Demigod
constructor
Starts a new game - each demigod has one world to rule accepts different starting resources as a parameter.
-
#turn ⇒ Object
Handles a turn, main function of the game.
Constructor Details
#initialize(world, resources = GameData::STARTING_RESOURCES) ⇒ Demigod
Starts a new game - each demigod has one world to rule accepts different starting resources as a parameter
21 22 23 24 |
# File 'lib/demigodGame/Demigod.rb', line 21 def initialize (world, resources = GameData::STARTING_RESOURCES) @world = world @resources = resources end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
16 17 18 |
# File 'lib/demigodGame/Demigod.rb', line 16 def resources @resources end |
Instance Method Details
#turn ⇒ Object
Handles a turn, main function of the game
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 |
# File 'lib/demigodGame/Demigod.rb', line 27 def turn # calculates new amount of resources using the production function # world.production accepts a resources hash and returns a newly # calculated resource hash based on production @resources = @world.production(@resources) p @resources #do_event # ========= TODO ========= # # part 2 of every turn UiHandler.print_world(@world) UiHandler. # Asks the user for a tile to do his action on decision = UiHandler.get_decision() until (@world.valid?(decision) || decision == '') UiHandler.print_error(UiHandler::NO_TILE) UiHandler. decision = UiHandler.get_decision() end unless decision == '' tile = @world.get_tile decision # returns the tile at decision # checks for legality of move on tiles using tile.accepts? and tile.check_cost until tile.accepts?(decision) break if decision == '' UiHandler.(tile) decision = UiHandler.get_decision() if (!tile.accepts?(decision)) UiHandler.print_error(UiHandler::INVALID) elsif (!tile.check_cost(decision, @resources)) decision = nil UiHandler.print_error(UiHandler::RESOURCES) end end if decision != '' price = GameData.get_price(decision) @resources = reduce(price) @world.advance(tile, decision) end end # Clears the screen UiHandler.() end |