Last active
December 19, 2015 10:29
-
-
Save cnosuke/5940434 to your computer and use it in GitHub Desktop.
ECARD from KAIJI
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 'pry' | |
module ECard | |
class Game | |
attr_reader :players | |
def initialize | |
@players = [ Player.new(:emperor), Player.new(:slave) ] | |
end | |
def fight | |
compare(@players.first.select, @players.last.select) | |
end | |
def compare(a,b) | |
if a.role_point * b.role_point == -1 | |
return -1 | |
else | |
a.role_point <=> b.role_point | |
end | |
end | |
end | |
class Player | |
attr_reader :cards | |
def initialize(role) | |
@cards = [ Card.new(role)] | |
4.times{ @cards << Card.new(:citizen) } | |
end | |
def select | |
@cards.shuffle!.pop | |
end | |
end | |
class Card | |
attr_reader :role | |
def initialize(role) | |
@role = role | |
end | |
def role_point | |
{ | |
:emperor => 1, | |
:citizen => 0, | |
:slave => -1 | |
}.fetch(@role) | |
end | |
end | |
end | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment