From 1446b2bf9585ad495258fa2e935042c0f3829060 Mon Sep 17 00:00:00 2001 From: Paul Liverman Date: Sat, 5 Dec 2015 23:20:29 -0800 Subject: [PATCH] works still, bout to fuck it up --- src/Card.lua | 18 ++------------- src/Deck.lua | 9 +++++++- src/main.lua | 64 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/Card.lua b/src/Card.lua index 2e714c2..c41834b 100644 --- a/src/Card.lua +++ b/src/Card.lua @@ -35,23 +35,9 @@ function Card:draw(face, x, y, r) if self.rank == "Joker" then lg.print("Joker", cornerOffset - Card.static.width/2, cornerOffset - Card.static.height/2) -- I wanted this to be a symbol for a suit, but the Joker doesn't have one! - lg.print("#") --used to be "J" + lg.print("#") else - lg.print(self.rank .. " of " .. self.suit, cornerOffset - Card.static.width/2, cornerOffset - height/2) - -- I wanted these to be symbols for suits, but for some reason I made them ranks - --[[ - if self.rank == "Ace" then - lg.print("A") - elseif self.rank == "Jack" then - lg.print("J") - elseif self.rank == "Queen" then - lg.print("Q") - elseif self.rank == "King" then - lg.print("K") - else - lg.print(self.rank) - end - --]] + lg.print(self.rank .. " of " .. self.suit, cornerOffset - Card.static.width/2, cornerOffset - Card.static.height/2) if self.suit == "Clubs" then lg.print("♣") elseif self.suit == "Diamonds" then diff --git a/src/Deck.lua b/src/Deck.lua index 456ea1f..abd456d 100644 --- a/src/Deck.lua +++ b/src/Deck.lua @@ -64,8 +64,11 @@ function Deck:shuffleCards() end function Deck:shuffleIn(card) --TODO make capable of handling multiple cards - -- + --insert(self.cards, random(1, #self.cards)) --no, we shuffle everything! + insert(self.cards, card) + self:shuffleCards() end +--TODO ? placeIn() to randomly place within without shuffling whole deck? function Deck:drawCards(count) if count and (count > 1) then @@ -103,4 +106,8 @@ function Deck:placeCardsUnder(cards) end end +function Deck:getCards() + return self.cards +end + return Deck diff --git a/src/main.lua b/src/main.lua index 4b1c655..c168ab2 100644 --- a/src/main.lua +++ b/src/main.lua @@ -99,7 +99,7 @@ function love.draw() else if hovering == "Card" then --deck over card - lg.print("Left click to place deck (will not shuffle card underneath into the deck). Right click to flip cards in the deck.", 2, lg.getHeight() - 14) + lg.print("Left click to place deck (will place card underneath on the bottom of the deck). Right click to flip cards in the deck.", 2, lg.getHeight() - 14) elseif hovering == "Deck" then --deck over deck lg.print("Left click to place deck (will not interact with deck underneath). Scroll up to add this deck on top, scroll down to add this deck on bottom. Right click to flip cards in this deck.", 2, lg.getHeight() - 14) @@ -112,15 +112,6 @@ function love.draw() end function love.mousepressed(x, y, button) - --[[ ORIGINAL TEXT, NOT ACCURATE - Left click will grab a card or deck. - While holding a card: Left click will place it (as long as the mouse is not over a deck). - While holding a card over a deck: Scroll up to place it on top of the deck, scroll down to place it on the bottom of the deck. Right click to shuffle it into the deck. - While holding a deck: Left click will place it (as long as the mouse is not over a deck). - While holding a deck over a deck: Scroll up to place it on top of the deck, scroll down to place it on the bottom of the deck. Right click to shuffle the decks together. - While NOT holding anything: Right click a card to flip it, or right click a deck to flip the cards in it (does not flip order of cards). Scroll over a deck to shuffle it. - All cards in a deck are facing the same way automatically. - --]] if button == "l" then if not holding then for i=#items,1,-1 do @@ -152,18 +143,11 @@ function love.mousepressed(x, y, button) insert(items, deck) holding = false elseif items[item]:isInstanceOf(Deck) then - --TODO shuffle it into the deck + items[item]:shuffleIn(holding) + holding = false end end - --[[ - --card on deck - "Scroll up to place card on top of deck, scroll down to place card on bottom of deck." - --deck over deck - "Scroll up to add this deck on top, scroll down to add this deck on bottom." - --deck over nothing - "Scroll to shuffle the deck." - ]] 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 ? @@ -173,9 +157,24 @@ function love.mousepressed(x, y, button) end end elseif holding:isInstanceOf(Card) then - --TODO easy + for i=#items,1,-1 do + if isOnItem(x, y, items[i]) and items[i]:isInstanceOf(Deck) then + items[i]:placeCardsOn(holding) + holding = false + break + end + end elseif holding:isInstanceOf(Deck) then - --TODO maybe harder + for i=#items,1,-1 do + if isOnItem(x, y, items[i]) and items[i]:isInstanceOf(Deck) then + items[i]:placeCardsOn(holding:getCards()) + holding = false + break + end + end + if holding then --if we didn't just get rid of it... + holding:shuffleCards() + end end elseif button == "wd" then if not holding then @@ -186,9 +185,24 @@ function love.mousepressed(x, y, button) end end elseif holding:isInstanceOf(Card) then - --TODO easy + for i=#items,1,-1 do + if isOnItem(x, y, items[i]) and items[i]:isInstanceOf(Deck) then + items[i]:placeCardsUnder(holding) + holding = false + break + end + end elseif holding:isInstanceOf(Deck) then - --TODO maybe harder + for i=#items,1,-1 do + if isOnItem(x, y, items[i]) and items[i]:isInstanceOf(Deck) then + items[i]:placeCardsUnder(holding:getCards()) + holding = false + break + end + end + if holding then --if we didn't just get rid of it... + holding:shuffleCards() + end end elseif button == "r" then if holding then @@ -208,6 +222,10 @@ function love.keypressed(key) if key == "escape" then love.event.quit() end + + if key == "m" then + insert(items, makeDeck(true)) + end end -- ♣ ♦ ♥ ♠ A 2 3 4 5 6 7 8 9 10 J Q K Joker