shows wrong cards i guess
This commit is contained in:
@@ -17,7 +17,7 @@ function LoadBlackjack()
|
||||
Deck = Karten:createDeck()
|
||||
Karten:shuffleDeck(Deck)
|
||||
DealInitialCards()
|
||||
Cards = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
|
||||
Cards = love.graphics.newImage("/cards_asset_pack/JustNormalCards.png")
|
||||
end
|
||||
|
||||
function UpdateBlackjack(dt)
|
||||
@@ -25,38 +25,70 @@ function UpdateBlackjack(dt)
|
||||
end
|
||||
|
||||
function DrawBlackjack()
|
||||
for i, card in ipairs(PlayerHand) do
|
||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||
local tileWidth = Cards:getWidth() / 15
|
||||
local tileHeight = Cards:getHeight() / 4
|
||||
local tileX = suits[card.suit]
|
||||
local tileY = math.min(card.value - 2, 9)
|
||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||
local tileWidth = Cards:getWidth() / 13
|
||||
local tileHeight = Cards:getHeight() / 4
|
||||
|
||||
for _, card in pairs(PlayerHand) do
|
||||
local tileX = card.value - 2
|
||||
local tileY = suits[card.suit]
|
||||
love.graphics.draw(
|
||||
Cards,
|
||||
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
||||
PlayerHandPosition.x - tileWidth / 4,
|
||||
PlayerHandPosition.y,
|
||||
0,
|
||||
0.5
|
||||
PlayerHandPosition.x - tileWidth / 4,
|
||||
PlayerHandPosition.y,
|
||||
0,
|
||||
0.5
|
||||
)
|
||||
end
|
||||
for i, card in ipairs(DealerHand) do
|
||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||
local tileWidth = Cards:getWidth() / 15
|
||||
local tileHeight = Cards:getHeight() / 4
|
||||
local tileX = suits[card.suit]
|
||||
local tileY = math.min(card.value - 2, 9)
|
||||
|
||||
love.graphics.print(GetHandValue(PlayerHand), PlayerHandPosition.x, PlayerHandPosition.y + tileHeight + 5)
|
||||
|
||||
for _, card in pairs(DealerHand) do
|
||||
suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||
tileWidth = Cards:getWidth() / 13
|
||||
tileHeight = Cards:getHeight() / 4
|
||||
local tileX = math.min(card.value - 2, 9)
|
||||
local tileY = suits[card.suit]
|
||||
love.graphics.draw(
|
||||
Cards,
|
||||
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
||||
DealerHandPosition.x - tileWidth / 4,
|
||||
DealerHandPosition.y,
|
||||
0,
|
||||
0.5
|
||||
DealerHandPosition.x - tileWidth / 4,
|
||||
DealerHandPosition.y,
|
||||
0,
|
||||
0.5
|
||||
)
|
||||
end
|
||||
|
||||
love.graphics.print(GetHandValue(DealerHand), DealerHandPosition.x, DealerHandPosition.y + tileHeight + 5)
|
||||
end
|
||||
|
||||
function GetHandValue(hand)
|
||||
local count = 0
|
||||
local aces = 0
|
||||
|
||||
for _, card in pairs(hand) do
|
||||
if card.value < 10 then
|
||||
count = count + card.value
|
||||
elseif card.value < 14 then
|
||||
count = count + 10
|
||||
else
|
||||
count = count + 11
|
||||
aces = aces + 1
|
||||
end
|
||||
end
|
||||
|
||||
::aceloop::
|
||||
if count > 21 and aces > 0 then
|
||||
for _ = 1, aces do
|
||||
count = count - 10
|
||||
aces = aces - 1
|
||||
goto aceloop
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
function HandleBlackjackInput(key)
|
||||
if key == "h" then
|
||||
@@ -66,7 +98,7 @@ function HandleBlackjackInput(key)
|
||||
end
|
||||
elseif key == "s" then
|
||||
-- while Karten:handValue(DealerHand) < 17 do
|
||||
Karten:hit(DealerHand)
|
||||
Karten:hit(DealerHand)
|
||||
-- end
|
||||
-- if Karten:handValue(DealerHand) > 21 then
|
||||
-- print("Dealer hat verloren!", 50, 200)
|
||||
|
||||
Reference in New Issue
Block a user