=begin name: Queen of Diamonds v0.4 author: Dirk Meijer date: April 22nd 2006 description: The graphic part of the app, almost ready! =end require "gosu/gosu" require "Queen_Of_Diamonds_no_graphics" class Table < Gosu::Window attr_accessor(:hand, :visible_cards) def initialize(hand=Deck.new, width=640, height=480, fullscreen=false , framerate=20, caption="Queen of Diamonds", background="#{File.dirname(__FILE__)}/../images/table.png") raise TypeError.new unless caption.respond_to?(:to_s) raise TypeError.new unless background.respond_to?(:to_s) super(width, height, fullscreen, framerate) self.caption=caption.to_s @background=Gosu::Image.new(self, background, false) @visible_cards=[] @hand=hand assign_images end def draw @background.draw(0,0,0) @visible_cards.each do |card| card.draw end end def update @visible_cards.each do |card| card.action end end def assign_images @hand.each do |card| card.front=Gosu::Image.new(self, "#{File.dirname(__FILE__)}/../images/#{card.suit.to_s.downcase}#{card.value.to_s.downcase}.png", false) card.back=Gosu::Image.new(self, "#{File.dirname(__FILE__)}/../images/back.png", false) card.side=card.front card.x = 0 card.y = 0 card.z = 1 card.zoom_x = 1 card.zoom_y = 1 card.angle = 1 card.movements=[] card.table=self end true end end class Card attr_accessor(:x, :y, :zoom_x, :zoom_y, :z, :angle, :front, :back, :side, :movements, :table) attr_reader(:showing) def draw @side.draw_rot(@x, @y, @z, @angle, 0.5, 0.5, @zoom_x, @zoom_y) end def show return false if @showing and @table.visible_cards.include?(self) @table.visible_cards<< self @showing=true end def hide return false if !@showing and !@table.visible_cards.include?(self) @table.visible_cards.delete(self) @showing=false end def action @movements.each do |move| @movements -= [move] if move.step end end def new_slide(*args) @movements<