demigod_game 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGY1ZWFlYWE0Mjk4MjU2MTg5OWYwYzMwZDY0YTM4ZjcyMWQwZDZhMA==
4
+ YTExYTI0MDdhNWMyMThlZDA3ZmJiN2IzY2M5ZDA2MTg5Yjc4NDVlZg==
5
5
  data.tar.gz: !binary |-
6
- MDc5MGM0MjU3MzNhOGFjNDgyOWVlM2JlY2Q2YjY4MzlkNmU4MjcyZQ==
6
+ NmFjMDY3ZGY3NmE2YWMxODc4NGI1MmMzNTBhY2U2MmM0MTRiNTIxMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmRjYmIzNWU1OTFlYzJlYzc2OWYwMDE4ZGVkMjdhMzU0YjI2OWIxZmY5MTNm
10
- ZDdlY2NjOWVhMzZkYzFmOGQ4MDJlMGEwMGE4MWI4YzI5MTZiN2YxYmE1NTVj
11
- NzEzOWVjNGFhZmYwOTYyZWRhYTBkNGQwMTYzNzA3NzYyZWM0YmU=
9
+ M2I0YmFjZTJjZDZlYWNlYjUyM2Y1MzgyMTJmYzFlZDQxZDkwMmNjY2YzM2Yy
10
+ YTQ5OWYxNWRhYjI2OGVkZWY3YTg1NTk4MmJiZmQxNmVhMzhkNjJjMjBkY2Vk
11
+ ZmU3ODJlY2U0NTMxOGViZDcxOGJkYzVlZGI5ZTQzZGNlZDUzYTk=
12
12
  data.tar.gz: !binary |-
13
- ZmVmODM1NGFlNWNhNWFlZDUzOWUzYmNjZTBlNzQ2YWUwNDMyYWQ3OTNkNjhl
14
- YTY0YzZhOGI0MmI1ODA0NjY2YmY2MzE3ZWY1MGNkYWIxODU3MDI1NTFhYWM5
15
- OTQwZTNhN2ExODJkMzRhYTIwODhlYTdlNDgyZDI0NTM5MjBjOTI=
13
+ MTkyNWZiOGE5YjE2MDUxNGU1M2M1MmRmMTVlM2I3NDQ4NDJmNTRhOGFiYjNi
14
+ ZWNkYzI2ZTI3M2YyOGY2NDc0NTk1MWQ3MjVkMDQ5ZGVjNWNmZjQ4NDMwMDI5
15
+ YjYwNWQzOTExNTk0M2Y1Zjk1ZTQyMzk5NDFlMDQxMzg5M2VmYTc=
data/README.md CHANGED
@@ -1,29 +1,37 @@
1
- # DemigodGame
2
-
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'demigodGame'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install demigodGame
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
1
+ NEW: You can now install the game with 'gem install demigod_game' and then run the game using 'demigod'!!
2
+
3
+ Hello
4
+ =======================================
5
+ This is just some self practice project where I try to create a bigger game using ruby
6
+
7
+ The game
8
+ --------
9
+ is an island building game, where you need to manage your resources in
10
+ order to unleash the dragon from a dragon shrine and get his
11
+ powers and immortality.. Yeah, very original..
12
+
13
+ How to play
14
+ ----------
15
+ Each turn you can choose a tile and either raise it (using favor), or build on it (using other resources).
16
+ Sea (_) turns into Plains (P) which turns into either a forest (F) or a mountain ridge (R). Forests can still be converted to mountains.
17
+ The building are houses, sheeps, woodcutters, chapels, mines and dragon shrine, which give you population, food, wood, favor and iron respectivelt
18
+ Building the dragon shrine is winning the game (not yet implemened)
19
+
20
+ Buildings
21
+ ---------
22
+ **houses:**
23
+ can be built on plains and in forests, provide 1 population per turn
24
+ **sheeps:**
25
+ can only be built on plains, provides 1 food per turn
26
+ note: you lose 1 food per population you have, and lost population if you lack food
27
+ **woodcutters:**
28
+ provide 1 wood per turn, which is your basic building resource
29
+ **chapels:**
30
+ provide 1 favor per 10 population you have (not yet implemented in that way)
31
+ **mines:**
32
+ provide 1 iron per turn
33
+ **dragon shrine:**
34
+ win condition, build this and you win!
35
+ more info
36
+ ---------
37
+ most of the hard data will still probably change, so it will remain for you to find it out :P
@@ -21,7 +21,6 @@ class Demigod
21
21
  def initialize (world, resources = GameData::STARTING_RESOURCES)
22
22
  @world = world
23
23
  @resources = resources
24
- system "clear" or system "cls"
25
24
  end
26
25
 
27
26
  # Handles a turn, main function of the game
@@ -40,27 +39,28 @@ class Demigod
40
39
  UiHandler.print_turn_message
41
40
 
42
41
  # Asks the user for a tile to do his action on
43
- decision = gets.chomp
42
+ decision = UiHandler.get_decision()
44
43
 
45
- until (@world.exists?(decision) || decision == '')
44
+ until (@world.valid?(decision) || decision == '')
46
45
  UiHandler.print_error(UiHandler::NO_TILE)
47
46
  UiHandler.print_turn_message
48
- decision = gets.chomp
47
+ decision = UiHandler.get_decision()
49
48
  end
50
49
 
51
50
  unless decision == ''
52
51
  tile = @world.get_tile decision # returns the tile at decision
53
- tile.print_options
54
-
55
- # asks for action on tile
56
- decision = gets.chomp
57
52
 
58
- # tile.accepts? uses number of resources to decide if a move is valid
59
- until tile.accepts?(decision, @resources)
53
+ # checks for legality of move on tiles using tile.accepts? and tile.check_cost
54
+ until tile.accepts?(decision)
60
55
  break if decision == ''
61
- UiHandler.print_error(UiHandler::INVALID)
62
- tile.print_options
63
- decision = gets.chomp
56
+ UiHandler.print_tile_options(tile)
57
+ decision = UiHandler.get_decision()
58
+ if (!tile.accepts?(decision))
59
+ UiHandler.print_error(UiHandler::INVALID)
60
+ elsif (!tile.check_cost(decision, @resources))
61
+ decision = nil
62
+ UiHandler.print_error(UiHandler::RESOURCES)
63
+ end
64
64
  end
65
65
 
66
66
  if decision != ''
@@ -71,7 +71,7 @@ class Demigod
71
71
  end
72
72
 
73
73
  # Clears the screen
74
- system "clear" or system "cls"
74
+ UiHandler.clear_messages()
75
75
  end
76
76
 
77
77
  private
@@ -52,6 +52,17 @@ module GameData
52
52
  :r => RAISE_RIDGE_PRICE
53
53
  }
54
54
 
55
+ OPTIONS = {:w => "Woodcutter",
56
+ :s => "Sheep",
57
+ :d => "Dragon Shrine",
58
+ :m => "Mine",
59
+ :c => "Chapel",
60
+ :h => "House",
61
+ :p => "Plains",
62
+ :f => "Forest",
63
+ :r => "Ridge"
64
+ }
65
+
55
66
  def self.get_price(sym)
56
67
  return PRICES[sym.to_sym]
57
68
  end
@@ -6,46 +6,13 @@
6
6
  require_relative 'GameData'
7
7
  class Tile
8
8
 
9
- attr_reader :raisable, :buildable, :built_on, :x, :y
9
+ attr_reader :options, :built_on, :x, :y
10
10
  def initialize(x, y)
11
11
  @x = x
12
12
  @y = y
13
- @raisable = []
14
- @buildable = []
15
13
  @type = '.'
16
14
  end
17
15
 
18
- # The base tile class is abstract and therfore accepts no value
19
- # Should probably be overriden in subclasses
20
- def accepts?(order, resources)
21
- false
22
- end
23
-
24
- def print_options
25
-
26
- if @raisable != [] # raising options
27
- print "You can raise with:"
28
- @raisable.each do |name|
29
- print " #{name.to_s} | "
30
- end
31
- puts
32
- end
33
-
34
- if @buildable != [] # building options
35
- print "You can build with:"
36
- @buildable.each do |name|
37
- print " #{name.to_s} | "
38
- end
39
- puts
40
- end
41
-
42
- puts UiHandler::RAISE_WARNING if @built_on
43
- puts UiHandler::BACK
44
-
45
-
46
- print UiHandler::PROMPT
47
- end
48
-
49
16
  def to_s
50
17
  "#{@type}#{@built_on}"
51
18
  end
@@ -57,27 +24,18 @@ class Tile
57
24
  end
58
25
 
59
26
  # Checks if an order is valid
60
- def accepts?(order, resources)
61
- return false if !order.match( /\A\w\Z/ ) # vaild command
27
+ def accepts?(order)
28
+ return false if !order || !order.match( /\A\w\Z/) # vaild command
62
29
 
63
- (@raisable + @buildable).each do |check| # checks which order was given
64
- if (check.to_s == order)
65
- cost = GameData.get_price(check)
66
- puts "This costs #{cost}"
67
- if !check_cost(cost, resources)
68
- puts "Not enough resources!"
69
- return false
70
- end
71
- return true
72
- end
30
+ @options.each do |check| # checks which order was given
31
+ return true if (check.to_s == order)
73
32
  end
74
33
  false
75
34
  end
76
35
 
77
- private
78
-
79
- def check_cost(cost, resources)
80
-
36
+ def check_cost(order, resources)
37
+ cost = GameData.get_price(order)
38
+ puts cost
81
39
  # checks each resource for the correct amount
82
40
  cost.each do |resource, amount|
83
41
  return false if amount > resources[resource]
@@ -91,7 +49,7 @@ class Sea < Tile
91
49
 
92
50
  def initialize(x, y)
93
51
  super(x, y)
94
- @raisable = [:p]
52
+ @options = [:p]
95
53
  @type = '-'
96
54
  end
97
55
  end
@@ -101,7 +59,7 @@ class Ridge < Tile
101
59
 
102
60
  def initialize(x, y)
103
61
  super(x, y)
104
- @buildable = [:m, :c, :d]
62
+ @options = [:m, :c, :d]
105
63
  @type = 'R'
106
64
  end
107
65
  end
@@ -111,8 +69,7 @@ class Plains < Tile
111
69
 
112
70
  def initialize(x, y)
113
71
  super(x, y)
114
- @raisable = [:r, :f]
115
- @buildable = [:h, :c, :s]
72
+ @options = [:r, :f, :h, :c, :s]
116
73
  @type = 'P'
117
74
  end
118
75
  end
@@ -122,8 +79,7 @@ class Forest < Tile
122
79
 
123
80
  def initialize(x, y)
124
81
  super(x, y)
125
- @buildable = [:w, :c, :h]
126
- @raisable = [:r]
82
+ @options = [:w, :c, :h, :r]
127
83
  @type = 'F'
128
84
  end
129
85
  end
@@ -1,6 +1,8 @@
1
1
  # Module to handle most of the output to the screen
2
2
  # =================================================
3
3
 
4
+ require_relative 'GameData'
5
+
4
6
  module UiHandler
5
7
 
6
8
  NEW_GAME = "Welcome to Demigod! What size would you want your world to be?"
@@ -11,7 +13,11 @@ module UiHandler
11
13
  BACK = "Press enter on an empty line to go back"
12
14
  INVALID = "That's an invalid move!"
13
15
  LOST = "You ran out of resources, I guess you lose..."
14
- WIN = "The dragon shrine is built and so the dragons grant you all the powers of immortality"
16
+ WIN = "The dragon shrine is built and so the dragons grant you all the powers of immortality"
17
+ AVAILABLE = "Available moves are: "
18
+ RESOURCES = "Not enough resources!"
19
+
20
+ # output #
15
21
 
16
22
  def self.print_world(world)
17
23
  puts
@@ -50,12 +56,41 @@ module UiHandler
50
56
  end
51
57
 
52
58
  def self.print_turn_message
53
- puts "Choose a tile to work on. Enter 2 numbers with a space in between i.e. \"1 1\""
54
- print PROMPT
59
+ puts "Choose a tile to work on. Enter 2 numbers with a space in between i.e. \"1 1\""
60
+ print PROMPT
55
61
  end
56
62
 
57
- def self.print_error(error_str)
63
+ def self.print_error(error_str="An error has occured")
58
64
  puts "Oops! #{error_str}"
59
65
  puts
60
66
  end
67
+
68
+ def self.print_lost_message()
69
+ puts "You ran out of resources! you lost!"
70
+ puts "(one of youre resources turned negative)"
71
+ puts
72
+ end
73
+
74
+ def self.print_win_message
75
+ puts WIN
76
+ end
77
+
78
+ def self.print_tile_options(tile)
79
+ puts (AVAILABLE)
80
+ tile.options.each do |key|
81
+ print ("#{key} - #{GameData::OPTIONS[key]}, ")
82
+ end
83
+ puts BACK
84
+ print PROMPT
85
+ end
86
+
87
+ def self.clear_messages()
88
+ #system "clear" or system "cls"
89
+ end
90
+
91
+ # input #
92
+
93
+ def self.get_decision()
94
+ gets.chomp()
95
+ end
61
96
  end
@@ -37,7 +37,7 @@ class World
37
37
  elsif order.match(/\A[wsmchd]\Z/) # for build of any building
38
38
  build_on_tile(tile, DECISIONS[:build][order.to_sym])
39
39
  else
40
- puts "Error occured, continuing but turn skipped."
40
+ UiHandler.print_error()
41
41
  end
42
42
  end
43
43
 
@@ -60,15 +60,14 @@ class World
60
60
  resources.each do |name, value| # lose condition
61
61
  if value < 0
62
62
  system "clear" or system "cls"
63
- puts "#{name} is negative!"
64
- puts UiHandler::LOST
63
+ UiHandler.print_lost_message
65
64
  exit
66
65
  end
67
66
  end
68
67
  resources
69
68
  end
70
69
 
71
- def exists? (str)
70
+ def valid? (str)
72
71
  str.strip!
73
72
  return false if !str.match(/\A\d+\s\d+\Z/)
74
73
  true
@@ -131,11 +130,11 @@ private
131
130
  tile.build(BUILDABLE[building.to_sym])
132
131
  @buildings[building.to_sym] += 1
133
132
  if building.to_sym == :dragon
134
- puts UiHandler::WIN
133
+ UiHandler.print_win_message
135
134
  exit
136
135
  end
137
136
  else # This shouldn't happen normally
138
- puts "There's already a building here"
137
+ puts "This shouldn't have happened (Buidling already in square)"
139
138
  end
140
139
 
141
140
  end
@@ -1,3 +1,3 @@
1
1
  module DemigodGame
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/demigodGame/demigod'
3
+ require_relative '../lib/demigodGame/world'
4
+
5
+ class MyUnitTests < Test::Unit::TestCase
6
+
7
+ def setup
8
+ puts "setup!"
9
+ end
10
+
11
+ def teardown
12
+ puts "teardown!"
13
+ end
14
+
15
+ def test_basic
16
+ dummygod = Demigod.new(World.new)
17
+ end
18
+
19
+ end
data/test_demigod.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/demigod_game/demigod'
3
+
4
+ class MyUnitTests < Test::Unit::TestCase
5
+
6
+ def setup
7
+ puts "setup!"
8
+ end
9
+
10
+ def teardown
11
+ puts "teardown!"
12
+ end
13
+
14
+ def test_basic
15
+ puts "I RAN!"
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demigod_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuval
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,8 @@ files:
61
61
  - lib/demigodGame/UiHandler.rb
62
62
  - lib/demigodGame/World.rb
63
63
  - lib/demigodGame/version.rb
64
+ - test/test_demigod.rb
65
+ - test_demigod.rb
64
66
  homepage: ''
65
67
  licenses:
66
68
  - MIT
@@ -85,4 +87,5 @@ rubygems_version: 2.2.2
85
87
  signing_key:
86
88
  specification_version: 4
87
89
  summary: Build your own island and unleash the dragons!
88
- test_files: []
90
+ test_files:
91
+ - test/test_demigod.rb