From 345bd58b3bf8977dd8058ab255aa5de1469e1c98 Mon Sep 17 00:00:00 2001 From: Paul Liverman Date: Sat, 5 Dec 2015 23:31:02 -0800 Subject: [PATCH] fixed lack of ability to draw a card, added Decks collapsing into cards --- src/Deck.lua | 14 +++++++++++++- src/main.lua | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Deck.lua b/src/Deck.lua index abd456d..f1e63c5 100644 --- a/src/Deck.lua +++ b/src/Deck.lua @@ -78,9 +78,15 @@ function Deck:drawCards(count) insert(new, remove(self.cards)) end + self:update() + return Deck(new) else - return remove(self.cards) + local card = remove(self.cards) + + self:update() + + return card end end @@ -110,4 +116,10 @@ function Deck:getCards() return self.cards end +function Deck:update() + if #self.cards < 2 then + self = self.cards[1] --turn into a Card (no idea if this will break anything Oo) + end +end + return Deck diff --git a/src/main.lua b/src/main.lua index a2e8f45..858429c 100644 --- a/src/main.lua +++ b/src/main.lua @@ -69,7 +69,7 @@ function love.draw() --All cards in a deck are facing the same way automatically. if not holding then --not holading anything - lg.print("Left click to grab a card or deck. Scroll over a deck to shuffle it. Right click to flip a card or the cards in a deck.", 2, lg.getHeight() - 14) + lg.print("Left click to grab a card or draw a card. Scroll down over a deck to shuffle it, scroll up to pick up a deck. Right click to flip a card or the cards in a deck.", 2, lg.getHeight() - 14) else local hovering = false @@ -116,7 +116,10 @@ function love.mousepressed(x, y, button) if not holding then for i=#items,1,-1 do if isOnItem(x, y, items[i]) then - holding = table.remove(items, i) + if items[i]:isInstanceOf(Card) then + holding = table.remove(items, i) + else + holding = items[i]:drawCards(1) break end end @@ -158,12 +161,12 @@ function love.mousepressed(x, y, button) holding = false end end - elseif button == "wu" then --WU AND WD ARE ALMOST IDENTICAL, COLLAPSE THEM INTO ONE WHERE POSSIBLE if not holding then for i=#items,1,-1 do --ABSTRACT THIS FOR, I DO IT TOO MUCH ? if isOnItem(x, y, items[i]) and items[i]:isInstanceOf(Deck) then - items[i]:shuffleCards() + --items[i]:shuffleCards() -- now we pick it up instead! + holding = table.remove(items, i) break end end