Knuckleheads 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +11 -0
- data/README +11 -0
- data/bin/knuckleheads +23 -0
- data/bin/players.csv +5 -0
- data/bin/players2.csv +12 -0
- data/lib/knuckleheads/auditable.rb +11 -0
- data/lib/knuckleheads/bill_player.rb +24 -0
- data/lib/knuckleheads/clumsy_player.rb +15 -0
- data/lib/knuckleheads/crazy_player.rb +28 -0
- data/lib/knuckleheads/die.rb +23 -0
- data/lib/knuckleheads/game.rb +96 -0
- data/lib/knuckleheads/game_turn.rb +23 -0
- data/lib/knuckleheads/hilary_player.rb +14 -0
- data/lib/knuckleheads/homo_nazi_player.rb +14 -0
- data/lib/knuckleheads/islamic_nazi_player.rb +14 -0
- data/lib/knuckleheads/playable.rb +29 -0
- data/lib/knuckleheads/player.rb +53 -0
- data/lib/knuckleheads/treasure_trove.rb +22 -0
- data/spec/knuckleheads/treasure_trove_rspec.rb +53 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb744459e86f27845199175f245eda6e7206aad2
|
4
|
+
data.tar.gz: 04c209ec5e9dcb6ce0b53776149a977c04dc8d4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92182384009570794a873483a9fcc836c37160409ea84c1e2f551250df416fa692803cd56976c35ce294d56716cc74afbe74d5543579b198ef3b42f924dde442
|
7
|
+
data.tar.gz: 8fc18433eda7403058e83490d5459540cc503d5c362e0b4a195d240404a2b34c0ffc9cb673671af11fb27cb04cc92871748ee6b3757bc1551c94564ee877f2d2
|
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
Copyright (c) 2014 Seth Allen
|
4
|
+
|
5
|
+
|
6
|
+
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:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
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.
|
11
|
+
|
data/README
ADDED
data/bin/knuckleheads
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Knuckleheads
|
4
|
+
|
5
|
+
require_relative '../lib/knuckleheads/game'
|
6
|
+
|
7
|
+
knuckleheads = Game.new("Knuckleheads")
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
9
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
10
|
+
|
11
|
+
puts "How many game rounds? (0 to exit)"
|
12
|
+
|
13
|
+
numrounds = gets
|
14
|
+
numrounds ||= ''
|
15
|
+
numrounds = numrounds.chomp.to_i
|
16
|
+
|
17
|
+
if numrounds > 0
|
18
|
+
knuckleheads.play(numrounds)
|
19
|
+
knuckleheads.print_high_scores
|
20
|
+
knuckleheads.save_high_scores
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/bin/players.csv
ADDED
data/bin/players2.csv
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
barack obama,clumsy
|
2
|
+
joe biden,crazy
|
3
|
+
john kerry,normal
|
4
|
+
harry reid,normal
|
5
|
+
nancy pelosi,normal
|
6
|
+
richard dawkins,normal
|
7
|
+
sam harris,normal
|
8
|
+
john geiss,clumsy
|
9
|
+
hilary clinton,hilary
|
10
|
+
osama bin laden,islamicnazi
|
11
|
+
alec baldwin,homonazi
|
12
|
+
bill clinton,bill
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/player'
|
4
|
+
|
5
|
+
class BillPlayer < Player
|
6
|
+
|
7
|
+
def w00t
|
8
|
+
super
|
9
|
+
puts "#{@name}: I feel your pain."
|
10
|
+
end
|
11
|
+
|
12
|
+
def skipped
|
13
|
+
super
|
14
|
+
puts "#{@name}: That depends on the definition of 'was'."
|
15
|
+
end
|
16
|
+
|
17
|
+
def blam
|
18
|
+
super
|
19
|
+
puts "#{@name}: I did not have sex with that woman!"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/player'
|
4
|
+
|
5
|
+
class ClumsyPlayer < Player
|
6
|
+
|
7
|
+
def found_treasure(treasure)
|
8
|
+
points = treasure.points / 2
|
9
|
+
@treasures[treasure.name] += points
|
10
|
+
puts "#{@name} found a #{treasure.name} worth #{points} points."
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/player'
|
4
|
+
|
5
|
+
class CrazyPlayer < Player
|
6
|
+
|
7
|
+
def initialize(name,health=100)
|
8
|
+
super(name, health)
|
9
|
+
@numw00ts = 0
|
10
|
+
@numblams = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def w00t
|
14
|
+
super
|
15
|
+
@numw00ts += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def blam
|
19
|
+
super
|
20
|
+
@numblams += 1
|
21
|
+
if @numblams > (@numw00ts/2)
|
22
|
+
puts "#{@name}: NOT FAIR! I got blammed #{@numblams} times and only w00ted #{@numw00ts} tinmes!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/auditable'
|
4
|
+
|
5
|
+
class Die
|
6
|
+
|
7
|
+
include Auditable
|
8
|
+
|
9
|
+
attr_reader :number
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
roll
|
13
|
+
end
|
14
|
+
|
15
|
+
def roll
|
16
|
+
@number = rand(1..6)
|
17
|
+
audit
|
18
|
+
@number
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/bill_player'
|
4
|
+
require_relative '../knuckleheads/clumsy_player'
|
5
|
+
require_relative '../knuckleheads/crazy_player'
|
6
|
+
require_relative '../knuckleheads/game_turn'
|
7
|
+
require_relative '../knuckleheads/hilary_player'
|
8
|
+
require_relative '../knuckleheads/homo_nazi_player'
|
9
|
+
require_relative '../knuckleheads/islamic_nazi_player'
|
10
|
+
require_relative '../knuckleheads/player'
|
11
|
+
require_relative '../knuckleheads/treasure_trove'
|
12
|
+
|
13
|
+
class Game
|
14
|
+
|
15
|
+
attr_reader :title
|
16
|
+
|
17
|
+
def initialize(title)
|
18
|
+
@title = title
|
19
|
+
@players = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_player(a_player)
|
23
|
+
@players << a_player
|
24
|
+
end
|
25
|
+
|
26
|
+
def play(rounds)
|
27
|
+
puts "There are #{@players.size} players in #{@title}: "
|
28
|
+
@players.each do |player|
|
29
|
+
puts player
|
30
|
+
end
|
31
|
+
treasures = TreasureTrove::TREASURES
|
32
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
33
|
+
treasures.each do |treasure|
|
34
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
35
|
+
end
|
36
|
+
|
37
|
+
1.upto(rounds) do |round|
|
38
|
+
puts "\nRound #{round}:"
|
39
|
+
@players.each do |player|
|
40
|
+
GameTurn.take_turn(player)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_high_scores
|
46
|
+
puts "\n#{@title} High Scores:"
|
47
|
+
@players.sort.each do |player|
|
48
|
+
puts "\n#{player.name}'s point totals:"
|
49
|
+
player.each_treasure do |treasure|
|
50
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
51
|
+
end
|
52
|
+
puts "#{player.health} health points"
|
53
|
+
puts "#{player.score} grand total score"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_players(from_file)
|
58
|
+
File.readlines(from_file).each do |line|
|
59
|
+
line = line.chomp
|
60
|
+
name, type = line.split(",")
|
61
|
+
case type
|
62
|
+
when 'bill'
|
63
|
+
player = BillPlayer.new(name)
|
64
|
+
when "clumsy"
|
65
|
+
player = ClumsyPlayer.new(name)
|
66
|
+
when "crazy"
|
67
|
+
player = CrazyPlayer.new(name)
|
68
|
+
when 'hilary'
|
69
|
+
player = HilaryPlayer.new(name)
|
70
|
+
when 'homonazi'
|
71
|
+
player = HomoNaziPlayer.new(name)
|
72
|
+
when 'islamicnazi'
|
73
|
+
player = IslamicNaziPlayer.new(name)
|
74
|
+
else
|
75
|
+
player = Player.new(name)
|
76
|
+
end
|
77
|
+
add_player(player)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def save_high_scores(to_file="high_scores.txt")
|
82
|
+
File.open(to_file, "w") do |file|
|
83
|
+
file.puts "#{@title} High Scores:"
|
84
|
+
place = 0
|
85
|
+
@players.sort.each do |player|
|
86
|
+
place += 1
|
87
|
+
formatted_name = "#{place}. #{player.name}".ljust(20, '.')
|
88
|
+
formatted_place = player.score.to_s.rjust(10,'.')
|
89
|
+
file.puts "#{formatted_name}#{formatted_place}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require_relative '../knuckleheads/die'
|
4
|
+
require_relative '../knuckleheads/player'
|
5
|
+
|
6
|
+
module GameTurn
|
7
|
+
|
8
|
+
def self.take_turn(player)
|
9
|
+
die = Die.new
|
10
|
+
case die.number
|
11
|
+
when 1..2
|
12
|
+
player.blam
|
13
|
+
when 5..6
|
14
|
+
player.w00t
|
15
|
+
else
|
16
|
+
player.skipped
|
17
|
+
end
|
18
|
+
player.found_treasure(TreasureTrove.random)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
module Playable
|
4
|
+
|
5
|
+
def blam
|
6
|
+
@health -= 10
|
7
|
+
puts "#{@name} got blammed!"
|
8
|
+
end
|
9
|
+
|
10
|
+
def skipped
|
11
|
+
puts "#{@name} was skipped."
|
12
|
+
end
|
13
|
+
|
14
|
+
def w00t
|
15
|
+
@health += 15
|
16
|
+
puts "#{@name} got w00ted!"
|
17
|
+
end
|
18
|
+
|
19
|
+
def strong?
|
20
|
+
@health >= 100
|
21
|
+
end
|
22
|
+
|
23
|
+
def wimpy?
|
24
|
+
@health < 100
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
require_relative '../knuckleheads/playable'
|
6
|
+
|
7
|
+
class Player
|
8
|
+
|
9
|
+
include Playable
|
10
|
+
|
11
|
+
attr_accessor :name
|
12
|
+
attr_reader :health
|
13
|
+
|
14
|
+
def initialize(name, health=100)
|
15
|
+
@name = name.titleize
|
16
|
+
@health = health
|
17
|
+
@treasures = Hash.new(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"I'm #{@name} with a health of #{@health} and a score of #{score}."
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
@health + points
|
26
|
+
end
|
27
|
+
|
28
|
+
def <=>(other)
|
29
|
+
other.score <=> score
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_name_and_score
|
33
|
+
puts "#{@name} (#{score})"
|
34
|
+
end
|
35
|
+
|
36
|
+
def found_treasure(treasure)
|
37
|
+
@treasures[treasure.name] += treasure.points
|
38
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
39
|
+
end
|
40
|
+
|
41
|
+
def points
|
42
|
+
@treasures.values.reduce(0,:+)
|
43
|
+
end
|
44
|
+
|
45
|
+
def each_treasure
|
46
|
+
@treasures.each do |name, points|
|
47
|
+
yield Treasure.new(name, points)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
Treasure = Struct.new(:name, :points)
|
4
|
+
|
5
|
+
module TreasureTrove
|
6
|
+
|
7
|
+
TREASURES = [
|
8
|
+
Treasure.new(:pie, 5),
|
9
|
+
Treasure.new(:bottle, 25),
|
10
|
+
Treasure.new(:hammer, 50),
|
11
|
+
Treasure.new(:skillet, 100),
|
12
|
+
Treasure.new(:broomstick, 200),
|
13
|
+
Treasure.new(:crowbar, 400)
|
14
|
+
]
|
15
|
+
|
16
|
+
def self.random
|
17
|
+
TREASURES.sample
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Knuckleheads
|
2
|
+
|
3
|
+
require 'knuckleheads/treasure_trove'
|
4
|
+
|
5
|
+
describe Treasure do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@treasure = Treasure.new(:hammer, 50)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a name attribute" do
|
12
|
+
expect(@treasure.name).to eq(:hammer)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a points attribute" do
|
16
|
+
expect(@treasure.points).to eq(50)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe TreasureTrove do
|
22
|
+
|
23
|
+
it "has six treasures" do
|
24
|
+
expect(TreasureTrove::TREASURES.size).to eq(6)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a pie worth 5 points" do
|
28
|
+
expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a bottle worth 25 points" do
|
32
|
+
expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a hammer worth 50 points" do
|
36
|
+
expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a skillet worth 100 points" do
|
40
|
+
expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has a broomstick worth 200 points" do
|
44
|
+
expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has a crowbar worth 400 points" do
|
48
|
+
expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Knuckleheads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Allen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-30 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: "Knuckleheads is played by:\n\n\tknuckleheads [ < input file > ]\n\nwhere\n\n\t<
|
28
|
+
input file > defaults to bin/players.csv\n\nThe scores are written to a file called
|
29
|
+
high_scores.txt\n\n\n"
|
30
|
+
email: x59htes@gmail.com
|
31
|
+
executables:
|
32
|
+
- knuckleheads
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- bin/knuckleheads
|
39
|
+
- bin/players.csv
|
40
|
+
- bin/players2.csv
|
41
|
+
- lib/knuckleheads/auditable.rb
|
42
|
+
- lib/knuckleheads/bill_player.rb
|
43
|
+
- lib/knuckleheads/clumsy_player.rb
|
44
|
+
- lib/knuckleheads/crazy_player.rb
|
45
|
+
- lib/knuckleheads/die.rb
|
46
|
+
- lib/knuckleheads/game.rb
|
47
|
+
- lib/knuckleheads/game_turn.rb
|
48
|
+
- lib/knuckleheads/hilary_player.rb
|
49
|
+
- lib/knuckleheads/homo_nazi_player.rb
|
50
|
+
- lib/knuckleheads/islamic_nazi_player.rb
|
51
|
+
- lib/knuckleheads/playable.rb
|
52
|
+
- lib/knuckleheads/player.rb
|
53
|
+
- lib/knuckleheads/treasure_trove.rb
|
54
|
+
- spec/knuckleheads/treasure_trove_rspec.rb
|
55
|
+
homepage:
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.2.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: This is a game of knuckleheads
|
79
|
+
test_files:
|
80
|
+
- spec/knuckleheads/treasure_trove_rspec.rb
|