I DON'T KNOW HOW THIS IS BROKEN BUT IT IS

This commit is contained in:
Paul Liverman
2015-12-05 23:53:38 -08:00
parent 345bd58b3b
commit 072322f1d7
4 changed files with 26 additions and 3 deletions

View File

@@ -61,6 +61,10 @@ function Card:moveTo(x, y, r)
self.r = r or self.r self.r = r or self.r
end end
function Card:getPosition()
return self.x, self.y, self.r
end
function Card:flip() function Card:flip()
if self.face == "down" then if self.face == "down" then
self.face = "up" self.face = "up"

View File

@@ -12,6 +12,7 @@ Deck.static.height = 89*2
function Deck:initialize(cards) function Deck:initialize(cards)
self.cards = cards or {} self.cards = cards or {}
print(self.cards) --NOTE DEBUG
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.r = 0 self.r = 0
@@ -45,6 +46,10 @@ function Deck:moveTo(x, y, r)
self.r = r or self.r self.r = r or self.r
end end
function Deck:getPosition()
return self.x, self.y, self.r
end
function Deck:flip() function Deck:flip()
if self.face == "down" then if self.face == "down" then
self.face = "up" self.face = "up"
@@ -74,8 +79,10 @@ function Deck:drawCards(count)
if count and (count > 1) then if count and (count > 1) then
local new = {} local new = {}
while (count > 1) and (#self.cards > 1) do while (count > 1) and (#self.cards > 0) do
insert(new, remove(self.cards)) local card = remove(self.cards)
card.face = self.face
insert(new, card)
end end
self:update() self:update()
@@ -83,6 +90,7 @@ function Deck:drawCards(count)
return Deck(new) return Deck(new)
else else
local card = remove(self.cards) local card = remove(self.cards)
card.face = self.face
self:update() self:update()

View File

@@ -1,3 +1,9 @@
function love.conf(t) function love.conf(t)
t.identity = "52cards"
t.console = true t.console = true
t.window.title = "52 Cards"
t.window.width = 960
t.window.height = 540
t.window.resizeable = true
end end

View File

@@ -5,8 +5,9 @@ local insert = table.insert
local lg = love.graphics local lg = love.graphics
local lm = love.mouse local lm = love.mouse
local items = {} local inspect = require "lib.inspect"
local items = {}
local function makeDeck(jokers) local function makeDeck(jokers)
local cards = {} local cards = {}
@@ -120,6 +121,7 @@ function love.mousepressed(x, y, button)
holding = table.remove(items, i) holding = table.remove(items, i)
else else
holding = items[i]:drawCards(1) holding = items[i]:drawCards(1)
end
break break
end end
end end
@@ -154,6 +156,9 @@ function love.mousepressed(x, y, button)
elseif items[item]:isInstanceOf(Card) then elseif items[item]:isInstanceOf(Card) then
local card = table.remove(items, item) local card = table.remove(items, item)
local deck = Deck({card, holding}) local deck = Deck({card, holding})
--deck:moveTo(card.x, card.y)
deck:moveTo(card:getPosition())
print(inspect(deck)) --NOTE DBEUG
insert(items, deck) insert(items, deck)
holding = false holding = false
elseif items[item]:isInstanceOf(Deck) then elseif items[item]:isInstanceOf(Deck) then