Skip to content

Instantly share code, notes, and snippets.

@marksim
Created July 28, 2011 13:03
Show Gist options
  • Save marksim/1111494 to your computer and use it in GitHub Desktop.
Save marksim/1111494 to your computer and use it in GitHub Desktop.
Basic mechanics of the game
SpaceTruckin.play("John", "Paul", "George") do |game|
until game.finished?
game.reset_stages
game.players.each do |player|
stage_name = game.available_stage_names[rand(game.available_stage_names.length)]
case stage_name
when "Demand"
game.select_stage("Demand").play(game.players_in_order_from(player)) do |stage|
stage.place_demand_chip_on(game.planets[rand(game.planets.length)) # player doesn't matter
stage.players.each do |stage_player|
# each player draws 2 resources
stage_player.draw
stage_player.draw
end
end
when "Control"
game.select_stage("Control").play(game.players_in_order_from(player)) do |stage|
player.resources << Card.new(:ship, :temporary => true)
stage.players.each do |stage_player|
stage_player.location.routes.each do |route|
if stage_player.can_control?(route)
stage_player.control(route)
end
end
end
player.remove_temporary_resources
end
when "Ship"
game.select_stage("Ship").play(game.players_in_order_from(player)) do |stage|
player.resources << Card.new(:fuel, :temporary => true)
stage.players.each do |stage_player|
stage_player.location.routes.each do |route|
if stage_player.can_travel?(route)
stage_player.travel(route)
stage_player.location.get_cargo(:half)
if state_player.location.has_demand?
stage_player.sell([3, stage_player.cargo].max)
end
end
end
end
player.remove_temporary_resources
end
when "Protect"
game.select_stage("Protect").play(game.players_in_order_from(player)) do |stage|
player.resources << Card.new(:mine, :temporary => true)
stage.players.each do |stage_player|
stage_player.controlled_routes.each do |route|
if !route.protected? && stage_player.can_protect?(route)
stage_player.protect(route)
end
end
end
player.remove_temporary_resources
end
when "Attack"
game.select_stage("Attack").play(game.players_in_order_from(player)) do |stage|
player = stage.players.first
stage.players[1..-1].each do |stage_player|
stage_player.discard_half_if_more_than_seven_resource_cards
end
case stage.attack_type
when :attack
game.controlled_routes.each do |route|
if route.controlled_by != player
stage.attack_route(route)
end
end
when :remove
if game.attacked_route
game.attack_route(nil)
end
end
end
else
raise "Unknown Stage!"
end
end
game.rotate_players
end
game.standings.each_with_index do |player, place|
puts "#{place} - #{player.name} (#{player.victory_points})"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment