87 lines
2.2 KiB
Lua
87 lines
2.2 KiB
Lua
local love = require("love")
|
|
require("karten")
|
|
|
|
PlayerHand = {}
|
|
DealerHand = {}
|
|
|
|
function LoadBlackjack()
|
|
DealerHandPosition = {
|
|
x = love.graphics.getWidth() / 2,
|
|
y = love.graphics.getHeight() / 4,
|
|
}
|
|
PlayerHandPosition = {
|
|
x = love.graphics.getWidth() / 2,
|
|
y = love.graphics.getHeight() / 4 * 2.5,
|
|
}
|
|
|
|
Deck = Karten:createDeck()
|
|
Karten:shuffleDeck(Deck)
|
|
DealInitialCards()
|
|
Cards = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
|
|
end
|
|
|
|
function UpdateBlackjack(dt)
|
|
dt = dt * 1
|
|
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)
|
|
love.graphics.draw(
|
|
Cards,
|
|
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
|
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.draw(
|
|
Cards,
|
|
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
|
DealerHandPosition.x - tileWidth / 4,
|
|
DealerHandPosition.y,
|
|
0,
|
|
0.5
|
|
)
|
|
end
|
|
end
|
|
|
|
|
|
function HandleBlackjackInput(key)
|
|
if key == "h" then
|
|
Karten:hit(PlayerHand)
|
|
if Karten:handValue(PlayerHand) > 21 then
|
|
love.graphics.print("Spieler hat verloren!", 50, 200)
|
|
end
|
|
elseif key == "s" then
|
|
-- while Karten:handValue(DealerHand) < 17 do
|
|
Karten:hit(DealerHand)
|
|
-- end
|
|
-- if Karten:handValue(DealerHand) > 21 then
|
|
-- print("Dealer hat verloren!", 50, 200)
|
|
-- elseif Karten:handValue(PlayerHand) > Karten:handValue(DealerHand) then
|
|
-- print("Spieler gewinnt!", 50, 200)
|
|
-- else
|
|
-- print("Dealer gewinnt!", 50, 200)
|
|
-- end
|
|
end
|
|
end
|
|
|
|
function DealInitialCards()
|
|
for i = 1, 2 do
|
|
Karten:hit(PlayerHand)
|
|
Karten:hit(DealerHand)
|
|
end
|
|
end
|