crapsgame 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/crapsgame +12 -0
- data/lib/crapsgame/dice.rb +9 -0
- data/lib/crapsgame/player.rb +97 -0
- data/lib/crapsgame.rb +15 -19
- metadata +7 -3
data/bin/crapsgame
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'crapsgame.rb'
|
4
|
+
|
5
|
+
c = Crapsgame.new
|
6
|
+
doublecash = (c.player.cash + c.player.standardbetvalue) * 2
|
7
|
+
|
8
|
+
while(gets.chomp != "q" && c.player.cash >= c.player.standardbetvalue && c.player.cash < doublecash)
|
9
|
+
c.roll
|
10
|
+
c.displaygamedata
|
11
|
+
c.player.displaystatus
|
12
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
class Player
|
2
|
+
|
3
|
+
attr_accessor :maxpointstobet, :oddsbetvalue, :standardbetvalue, :cash
|
4
|
+
attr_accessor :numberbets, :passbet, :comebet
|
5
|
+
|
6
|
+
POINTS = [4, 5, 6, 8, 9, 10]
|
7
|
+
|
8
|
+
def initialize(maxpointstobet=3, oddsbetvalue = 10, standardbetvalue = 5, cash = 200)
|
9
|
+
@maxpointstobet = maxpointstobet
|
10
|
+
@oddsbetvalue = oddsbetvalue
|
11
|
+
@standardbetvalue = standardbetvalue
|
12
|
+
@cash = cash
|
13
|
+
|
14
|
+
@numberbets = {4 => [0,0], 5 => [0,0], 6 => [0,0], 8 => [0,0], 9 => [0,0], 10 => [0,0]}
|
15
|
+
@comebet = 0
|
16
|
+
@passbet = @standardbetvalue
|
17
|
+
@cash -= @standardbetvalue
|
18
|
+
end
|
19
|
+
|
20
|
+
def payout(roll_value, point_on)
|
21
|
+
case roll_value
|
22
|
+
when 2, 3, 12
|
23
|
+
@passbet = @comebet = 0
|
24
|
+
when 11
|
25
|
+
@cash += @passbet + @comebet
|
26
|
+
when 4, 10
|
27
|
+
pointhit(roll_value, 3.0, point_on)
|
28
|
+
when 5, 9
|
29
|
+
pointhit(roll_value, 2.5, point_on)
|
30
|
+
when 6, 8
|
31
|
+
pointhit(roll_value, 2.2, point_on)
|
32
|
+
when 7
|
33
|
+
@cash += (@passbet * 2) + (@comebet * 2)
|
34
|
+
if not point_on then
|
35
|
+
@cash += oddsvalue
|
36
|
+
end
|
37
|
+
clearbets
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def setbets(roll_value, point_on)
|
42
|
+
if POINTS.index(roll_value) then
|
43
|
+
@numberbets[roll_value][0] = @passbet + @comebet
|
44
|
+
if cashforbet?(@oddsbetvalue) then
|
45
|
+
@numberbets[roll_value][1] = @oddsbetvalue
|
46
|
+
@cash -= @oddsbetvalue
|
47
|
+
end
|
48
|
+
@passbet = @comebet = 0
|
49
|
+
end
|
50
|
+
|
51
|
+
if not point_on and @passbet == 0 and cashforbet?(@standardbetvalue) then
|
52
|
+
@passbet = @standardbetvalue
|
53
|
+
@cash -= @passbet
|
54
|
+
end
|
55
|
+
if point_on and @comebet == 0 and cashforbet?(@standardbetvalue) and numberofpoints <= @maxpointstobet then
|
56
|
+
@comebet = @standardbetvalue
|
57
|
+
@cash -= @comebet
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def cashforbet?(bet_ammount)
|
62
|
+
cash - bet_ammount >= 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def oddsvalue
|
66
|
+
oddstotal = 0
|
67
|
+
@numberbets.values.each {|x| oddstotal += x[1]}
|
68
|
+
oddstotal
|
69
|
+
end
|
70
|
+
|
71
|
+
def allbetsvalue
|
72
|
+
@numberbets.values.flatten.inject(:+) + @passbet + @comebet
|
73
|
+
end
|
74
|
+
|
75
|
+
def numberofpoints
|
76
|
+
@numberbets.select {|k,v| v != [0,0]}.count
|
77
|
+
end
|
78
|
+
|
79
|
+
def pointhit(roll_value, multiplier, point_on)
|
80
|
+
@cash += (@numberbets[roll_value][0] * 2) + (@numberbets[roll_value][1] * (point_on ? multiplier : 1))
|
81
|
+
@numberbets[roll_value] = [0,0]
|
82
|
+
end
|
83
|
+
|
84
|
+
def clearbets
|
85
|
+
@numberbets = {4 => [0,0], 5 => [0,0], 6 => [0,0], 8 => [0,0], 9 => [0,0], 10 => [0,0]}
|
86
|
+
@passbet = 0
|
87
|
+
@comebet = 0
|
88
|
+
end
|
89
|
+
|
90
|
+
def displaystatus
|
91
|
+
puts("Cash=$#{@cash}")
|
92
|
+
puts("Bets Total=$#{allbetsvalue}")
|
93
|
+
puts("Passline=$#{@passbet}")
|
94
|
+
puts("Comeline=$#{@comebet}")
|
95
|
+
@numberbets.each {|k,v| puts("Number #{k.to_s} = $#{v[0].to_s} Odds = $#{v[1].to_s}")}
|
96
|
+
end
|
97
|
+
end
|
data/lib/crapsgame.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
1
|
+
require "crapsgame/dice"
|
2
|
+
require "crapsgame/player"
|
3
3
|
|
4
4
|
class Crapsgame
|
5
5
|
include Dice
|
@@ -10,49 +10,45 @@ class Crapsgame
|
|
10
10
|
@player = (player == nil ? Player.new : player)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def rollthedice
|
14
14
|
@currentdice = roll_dice
|
15
15
|
@dicetotal = roll_total(@currentdice)
|
16
|
-
puts("The roll was: #{@dicetotal} (#{@currentdice[0]} and #{@currentdice[1]})")
|
17
16
|
end
|
18
17
|
|
19
18
|
def handle_roll
|
20
19
|
case @dicetotal
|
21
20
|
when 4, 5, 6, 8, 9, 10
|
22
|
-
puts("Point Roll")
|
23
21
|
if(@point == @dicetotal) then
|
24
22
|
@point = 0
|
25
|
-
puts("You Won!")
|
26
23
|
elsif @point == 0 then
|
27
24
|
@point = @dicetotal
|
28
25
|
end
|
29
|
-
when 2, 3, 12
|
30
|
-
puts("Craps")
|
31
26
|
when 7
|
32
|
-
puts("Seven")
|
33
27
|
if @point != 0 then
|
34
|
-
puts("You Lose")
|
35
28
|
@point = 0
|
36
29
|
end
|
37
|
-
when 11
|
38
|
-
puts("Eleven")
|
39
30
|
end
|
40
31
|
end
|
41
32
|
|
42
33
|
def roll
|
43
|
-
|
44
|
-
@player.payout(@dicetotal,
|
34
|
+
rollthedice
|
35
|
+
@player.payout(@dicetotal, point_on?)
|
45
36
|
handle_roll
|
46
|
-
@player.setbets(@dicetotal,
|
47
|
-
displaygamedata
|
48
|
-
|
37
|
+
@player.setbets(@dicetotal, point_on?)
|
38
|
+
#displaygamedata
|
39
|
+
#@player.displaystatus
|
49
40
|
end
|
50
41
|
|
51
42
|
def displaygamedata
|
52
|
-
|
43
|
+
if point_on? then
|
44
|
+
puts("The point is set to #{@point}")
|
45
|
+
else
|
46
|
+
puts("There is no point set")
|
47
|
+
end
|
48
|
+
puts("The current roll is: #{@dicetotal} (#{@currentdice[0]} and #{@currentdice[1]})")
|
53
49
|
end
|
54
50
|
|
55
|
-
def
|
51
|
+
def point_on?
|
56
52
|
@point != 0
|
57
53
|
end
|
58
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crapsgame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,15 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Play the game of craps and test your game plan
|
15
15
|
email: stevencurtiss@hotmail.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- crapsgame
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- lib/crapsgame.rb
|
22
|
+
- lib/crapsgame/dice.rb
|
23
|
+
- lib/crapsgame/player.rb
|
24
|
+
- bin/crapsgame
|
21
25
|
homepage: http://rubygems.org/gems/crapsgame
|
22
26
|
licenses: []
|
23
27
|
post_install_message:
|