Created
March 8, 2011 17:17
-
-
Save ttreitlinger/860579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'player.rb' | |
require 'poker.rb' | |
class Casino | |
def initialize | |
@total_1 = {'John' => 0, 'Mary' => 0, 'Luke' => 0, 'Eimear' => 0} | |
@total_2 = {'John' => 0, 'Mary' => 0, 'Luke' => 0, 'Eimear' => 0} | |
@analyser_1 = Proc.new do |this_game| | |
results = this_game.results | |
# find out who won | |
winner_name = this_game.winner.name.to_s | |
@total_1[winner_name] = @total_1 [winner_name] + 1 | |
end | |
@analyser_2 = Proc.new do |this_game| | |
results = this_game.results | |
# find out who won | |
winner_name = this_game.winner.name.to_s | |
@total_2[winner_name] = @total_2[winner_name] + 1 | |
end | |
end | |
def watch_games | |
players = [Player.new("John"), Player.new("Mary"), Player.new("Luke"), Player.new("Eimear")] | |
poker_game = Poker.new 100, players | |
poker_game.add_observer @analyser_1 | |
poker_game.add_observer @analyser_2 | |
poker_game.play | |
# poker_game.print_results | |
puts " total_1: #{@total_1.to_s}" | |
puts " total_2: #{@total_2.to_s}" | |
end | |
end | |
casino = Casino.new | |
casino.watch_games |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'player.rb' | |
require 'hand.rb' | |
require 'deck.rb' | |
require 'pile.rb' | |
require 'subject.rb' | |
# Class that represents a simple 1-card poker game. | |
class Poker | |
include Subject | |
attr_reader :results, :winner | |
# Create poker game of given number of rounds using players array. | |
def initialize no_of_rounds, players | |
super() | |
@players = players | |
@no_of_rounds = no_of_rounds | |
@results = Hash.new | |
@players.each do |player| | |
@results[player.name] = [] | |
end | |
end | |
# Player the game of Poker. | |
def play | |
@pile = Pile.new | |
@no_of_rounds.times do | |
play_round | |
@pile.empty! | |
end | |
end | |
# Play an individual round. | |
def play_round | |
@deck = Deck.new | |
# deal each player a hand | |
@players.each do |player| | |
player.set_hand(@deck.deal_hand(1)) | |
end | |
# Each player plays a card | |
@players.each do |player| | |
@pile.add(player.play) | |
end | |
winning_card = @pile.calculate_winner | |
@winner = nil | |
# find out who played the winning card | |
@players.each_with_index do |player, i| | |
if winning_card == player.last_card_played | |
@winner = player | |
end | |
end | |
@results[@winner.name] << winning_card.to_string | |
# notify that a round has ended | |
notify_observers | |
end | |
# Print the overall results of the series of rounds | |
def print_results | |
@results.each do |name, results| | |
puts "#{name} won #{@results[name].length} times with #{results}" | |
end | |
end | |
end | |
players = [Player.new("John"), Player.new("Mary"), Player.new("Luke"), Player.new("Eimear")] | |
poker_game = Poker.new 100, players | |
poker_game.play | |
poker_game.print_results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Subject | |
def initialize | |
@observers = [] | |
end | |
def add_observer observer | |
@observers << observer | |
end | |
def delete_observer observer | |
@observers.delete observer | |
end | |
# use PUSH model for notification | |
# Procs will require one argument (a reference to the subject) | |
def notify_observers | |
@observers.each do |observer| | |
observer.call(self) | |
end | |
end | |
end |
I recently went out to dinner with friends and we started talking about different hobbies. It turns out that many of us like to bet, but few of us know the good places. I shared with them a site where you can make different spins and bets - you can try here, and we even tried to play together. The site has many games, as well as a huge number of promotions and bonuses, from free spins to deposit bonuses. My friends liked it, and I was once again convinced that it is a great place to spend time together.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In a casino, everyone can show their luck. It is important to remember that gambling can be dangerous if the hobby turns into a harmful addiction. I’m now reading about deposit hungary, I found information about no deposit casino bonus hungary for myself. The main rule is to spend a lot of time studying. This is what I'm doing now.