diablo_game 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b22c0b9c22a5d5f76be63b0c607d2f06e62064ba
4
+ data.tar.gz: a262d0bd73aaa413b38acf33c8e74a375462d792
5
+ SHA512:
6
+ metadata.gz: 31767229e869454239253e30461d0c3382fcb98b149a4f38f4e49897327e364004537c265406f358e675c1f5f941d99b8e02e48b4c41cf0bd8400d84a8632e65
7
+ data.tar.gz: 7250308c1e22dfbef3d409833b9bcbd46882fd986dc8ecc53ab5b54008335ef1e7d5059fdabb5f62a442c73540d98c10566731984b01c00f8a2ef2fb3f6e3802
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016 Mann Software
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ This is an example application used in The Pragmatic Studio's Ruby Programming course by Howard Mann amended for a Diablo game theme.
data/bin/diablo_game ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/diablo_game/level"
4
+ require_relative "../lib/diablo_game/hero"
5
+ require_relative "../lib/diablo_game/blacksmith_player"
6
+
7
+ level = DiabloGame::Level.new("Sanctuary")
8
+ puts "Welcome to Act I: #{level.title}"
9
+
10
+ default_player_file = File.join(File.dirname(__FILE__),'heroes.csv')
11
+ level.load_players(ARGV.shift || default_player_file)
12
+
13
+ blacksmith = DiabloGame::BlacksmithPlayer.new("Blacksmith", 100)
14
+ level.add_hero(blacksmith)
15
+
16
+
17
+ loop do
18
+ puts "\nHow many stages to play? (type a number or 'quit' to exit)"
19
+ answer = gets.chomp.downcase
20
+ case answer
21
+ when /^\d+$/
22
+ level.play(answer.to_i)
23
+ when 'quit', 'exit'
24
+ level.print_stats
25
+ break
26
+ else
27
+ puts "Please type number of stages or 'quit' to exit"
28
+ end
29
+ end
30
+
31
+ puts "\nThank you for playing Diablo".ljust(60,'.')
32
+ puts "\n"
data/bin/heroes.csv ADDED
@@ -0,0 +1,4 @@
1
+ Necromancer,60
2
+ Barbarian,120
3
+ Druid,80
4
+ Paladin,100
@@ -0,0 +1,31 @@
1
+ require_relative "hero"
2
+ require_relative "jewel"
3
+ require_relative "playable_mixin"
4
+
5
+ module DiabloGame
6
+ class BlacksmithPlayer < Hero
7
+ def dig(jewel)
8
+ bonus_dig = Jewel.new(jewel.name, jewel.points * 3)
9
+ super(bonus_dig)
10
+ end
11
+
12
+ def hit
13
+ @health -= 60
14
+ puts "#{@name} was hit! Health is now: #{@health}"
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ if __FILE__ == $0
22
+ blacksmith = DiabloGame::BlacksmithPlayer.new("Blacksmith", 100)
23
+
24
+ coal = DiabloGame::Jewel.new(:coal, 5)
25
+
26
+ puts blacksmith
27
+ blacksmith.dig(coal)
28
+ blacksmith.hit
29
+ puts blacksmith
30
+
31
+ end
@@ -0,0 +1,10 @@
1
+ module DiabloGame
2
+ class Dice
3
+ attr_reader :number
4
+
5
+ def roll
6
+ @number = rand(1..6)
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "playable_mixin"
2
+
3
+ module DiabloGame
4
+ class Hero
5
+ include Playable
6
+
7
+ attr_reader :health
8
+ attr_accessor :name
9
+
10
+ def initialize(name, health=100)
11
+ @name = name.capitalize
12
+ @health = health
13
+ @found_jewel = Hash.new(0)
14
+ end
15
+
16
+ def name=(new_name)
17
+ @name = new_name.capitalize
18
+ end
19
+
20
+ def points
21
+ @found_jewel.values.reduce(0,:+)
22
+ end
23
+
24
+ def to_s
25
+ "#{@name} has health of #{@health} and a total of #{points} item points."
26
+ end
27
+
28
+ def dig(jewel)
29
+ @found_jewel[jewel.name] += jewel.points
30
+ puts "#{@name} digs for #{jewel.name} worth #{jewel.points} points. Satchel: #{@found_jewel}."
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ if __FILE__ == $0
38
+ puts "Test: hero.rb".ljust(70,'.')
39
+ hero1 = DiabloGame::Hero.new("Hero")
40
+ puts hero1
41
+ hero1.hit
42
+ hero1.heal
43
+ puts hero1
44
+
45
+
46
+
47
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "hero"
2
+
3
+ module DiabloGame
4
+ Jewel = Struct.new(:name,:points)
5
+
6
+ module PossibleJewels
7
+ JEWELS = [
8
+ Jewel.new(:Coal, 5),
9
+ Jewel.new(:Coal, 5),
10
+ Jewel.new(:Coal, 5),
11
+ Jewel.new(:Coal, 5),
12
+ Jewel.new(:Ruby, 50),
13
+ Jewel.new(:Sapphire, 100),
14
+ Jewel.new(:Diamond, 200),
15
+ Jewel.new(:Emerald, 300),
16
+ Jewel.new(:Unobtanium!, 1000)
17
+ ]
18
+
19
+ def self.random
20
+ JEWELS.sample
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ if __FILE__ == $0
28
+
29
+ jewel_rand = DiabloGame::PossibleJewels.random
30
+ puts "Dig for random jewel = #{jewel_rand.name} worth #{jewel_rand.points} total points."
31
+
32
+
33
+ end
@@ -0,0 +1,73 @@
1
+ require_relative 'hero'
2
+ require_relative 'level_turn'
3
+ require_relative 'jewel'
4
+ require_relative 'print_stats_mixin'
5
+
6
+
7
+ module DiabloGame
8
+ class Level
9
+ include PrintStats
10
+
11
+ attr_reader :title
12
+
13
+ def initialize(title)
14
+ @title = title
15
+ @heroes = []
16
+ end
17
+
18
+ def add_hero(insert)
19
+ @heroes.push(insert)
20
+ end
21
+
22
+ def load_players(from_file)
23
+ puts "\nLoading heroes from file path = #{from_file}:"
24
+ File.readlines(from_file).each do |line|
25
+ puts line
26
+ name, health = line.split(',')
27
+ hero = Hero.new(name, Integer(health))
28
+ add_hero(hero)
29
+ end
30
+ end
31
+
32
+ def play(stages)
33
+ 1.upto(stages) do |x|
34
+ puts "\nStage #{x}".ljust(60,'.')
35
+ puts "\nStarting round stats for stage #{x}:"
36
+
37
+ @heroes.each do |hero|
38
+ if hero.health >=0
39
+ puts hero
40
+ else
41
+ puts "xxx #{hero.name} is dead xxx"
42
+ end
43
+ end
44
+
45
+ @heroes.each do |hero|
46
+ if hero.health >= 0
47
+ puts "\n"
48
+ LevelTurn.take_turn(hero)
49
+ else
50
+ puts "\nxxx #{hero.name} is dead skip round xxx"
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ if __FILE__ == $0
63
+ puts "Test: level.rb".ljust(70,'.')
64
+ level = DiabloGame::Level.new("Sanctuary")
65
+ puts "Welcome to Act I: #{level.title}"
66
+
67
+ level.load_players("/Users/howardmann/studio_game/diablo_game/bin/hero.csv")
68
+
69
+ level.play(10)
70
+
71
+ level.print_stats
72
+
73
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'hero'
2
+ require_relative 'dice'
3
+ require_relative 'jewel'
4
+
5
+
6
+ module DiabloGame
7
+ module LevelTurn
8
+ def self.take_turn(hero)
9
+ dice = DiabloGame::Dice.new
10
+
11
+ case dice.roll
12
+ when 2,4,6
13
+ puts "#{hero.name} rolled an even number (#{dice.number})"
14
+ hero.hit
15
+ when 1,3,5
16
+ puts "#{hero.name} rolled an odd number (#{dice.number})"
17
+ hero.heal
18
+ else
19
+ puts "this should not come up"
20
+ end
21
+
22
+ jewel_rand = DiabloGame::PossibleJewels.random
23
+ hero.dig(jewel_rand)
24
+
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,19 @@
1
+ module DiabloGame
2
+ module Playable
3
+
4
+ def hit
5
+ @health -= 30
6
+ puts "#{@name} was hit! Health is now: #{@health}"
7
+ end
8
+
9
+ def heal
10
+ @health += 15
11
+ puts "#{@name} was healed. Health is now: #{@health}"
12
+ end
13
+
14
+ def dead?
15
+ @health <= 0
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,23 @@
1
+ module DiabloGame
2
+ module PrintStats
3
+
4
+ def print_stats
5
+ dead_heroes = @heroes.select { |hero| hero.dead?}
6
+ survive_heroes = @heroes.reject { |hero| hero.dead?}
7
+ sorted_survive_heroes = survive_heroes.sort {|a,b| b.points <=> a.points}
8
+
9
+ puts "\n#{title} survivor total points:"
10
+ sorted_survive_heroes.each do |hero|
11
+ formatted_name = hero.name.ljust(20,'.')
12
+ puts "#{formatted_name} #{hero.points}"
13
+ end
14
+
15
+ puts "\n#{title} dead heroes:"
16
+ dead_heroes.each do |hero|
17
+ formatted_name = hero.name.ljust(20,'.')
18
+ puts "#{formatted_name} Dead!"
19
+ end
20
+ end
21
+ end
22
+
23
+ end
File without changes
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diablo_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Howard Mann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |
28
+ This is an example application used in The Pragmatic Studio's Ruby Programming course by Howard Mann amended for a Diablo game theme.
29
+ email: howardmann27@gmail.com
30
+ executables:
31
+ - diablo_game
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README
37
+ - bin/diablo_game
38
+ - bin/heroes.csv
39
+ - lib/diablo_game/blacksmith_player.rb
40
+ - lib/diablo_game/dice.rb
41
+ - lib/diablo_game/hero.rb
42
+ - lib/diablo_game/jewel.rb
43
+ - lib/diablo_game/level.rb
44
+ - lib/diablo_game/level_turn.rb
45
+ - lib/diablo_game/playable_mixin.rb
46
+ - lib/diablo_game/print_stats_mixin.rb
47
+ - spec/diablo_game/hero_spec.rb
48
+ - spec/diablo_game/jewel_spec.rb
49
+ - spec/diablo_game/level_spec.rb
50
+ homepage:
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '1.9'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.4.6
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Diablo themed game based on pragmatic studio homework
74
+ test_files:
75
+ - spec/diablo_game/hero_spec.rb
76
+ - spec/diablo_game/jewel_spec.rb
77
+ - spec/diablo_game/level_spec.rb