drawing works sometimes

This commit is contained in:
Nico
2025-08-08 13:57:05 +02:00
parent 686f6d8962
commit 1c2e6e5ca2
3 changed files with 104 additions and 77 deletions

View File

@@ -1,11 +1,19 @@
local love = require "love" local love = require("love")
require "karten" require("karten")
spielerHand = {} PlayerHand = {}
DealerHand = {} DealerHand = {}
Deck = {}
function LoadBlackjack() 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() Deck = Karten:createDeck()
Karten:shuffleDeck(Deck) Karten:shuffleDeck(Deck)
DealInitialCards() DealInitialCards()
@@ -13,41 +21,66 @@ function LoadBlackjack()
end end
function UpdateBlackjack(dt) function UpdateBlackjack(dt)
-- Hier können zukünftige Updates für Blackjack hinzugefügt werden dt = dt * 1
end end
function DrawBlackjack() function DrawBlackjack()
print(love.graphics:getWidth()) for i, card in ipairs(PlayerHand) do
love.graphics.draw(Cards, love.graphics.getWidth() / 2 - 90 , 50, 0, 0.2) local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
-- love.graphics.print("Spieler Hand: " .. Karten:handValue(spielerHand), 50, 50) local tileWidth = Cards:getWidth() / 15
-- love.graphics.print("Dealer Hand: " .. Karten:handValue(DealerHand), 50, 100) local tileHeight = Cards:getHeight() / 4
-- love.graphics.print("Drücke 'H' für Hit oder 'S' für Stand", 50, 150) 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 end
function HandleBlackjackInput(key) function HandleBlackjackInput(key)
if key == 'h' then if key == "h" then
Karten:hit(spielerHand) Karten:hit(PlayerHand)
if Karten:handValue(spielerHand) > 21 then if Karten:handValue(PlayerHand) > 21 then
love.graphics.print("Spieler hat verloren!", 50, 200) love.graphics.print("Spieler hat verloren!", 50, 200)
end end
elseif key == 's' then elseif key == "s" then
while Karten:handValue(DealerHand) < 17 do -- while Karten:handValue(DealerHand) < 17 do
Karten:hit(DealerHand) Karten:hit(DealerHand)
end -- end
if Karten:handValue(DealerHand) > 21 then -- if Karten:handValue(DealerHand) > 21 then
love.graphics.print("Dealer hat verloren!", 50, 200) -- print("Dealer hat verloren!", 50, 200)
elseif Karten:handValue(spielerHand) > Karten:handValue(DealerHand) then -- elseif Karten:handValue(PlayerHand) > Karten:handValue(DealerHand) then
love.graphics.print("Spieler gewinnt!", 50, 200) -- print("Spieler gewinnt!", 50, 200)
else -- else
love.graphics.print("Dealer gewinnt!", 50, 200) -- print("Dealer gewinnt!", 50, 200)
end -- end
end end
end end
function DealInitialCards() function DealInitialCards()
for i = 1, 2 do for i = 1, 2 do
Karten:hit(spielerHand) Karten:hit(PlayerHand)
Karten:hit(DealerHand) Karten:hit(DealerHand)
end end
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -1,4 +1,5 @@
local love = require "love" local love = require("love")
Karten = {} Karten = {}
function Karten:createDeck() function Karten:createDeck()
@@ -11,7 +12,7 @@ function Karten:createDeck()
end end
end end
TileMap = love.graphics.newImage("/cards_asset_pack/CuteCards.png") TileMap = love.graphics.newImage("/cards_asset_pack/JustNormalCards.png")
return deck return deck
end end
@@ -38,19 +39,12 @@ function Karten:handValue(hand)
return value return value
end end
function Karten:hit(x, y, hand) function Karten:hit(hand)
if #Deck > 0 then if #Deck > 0 then
local card = table.remove(Deck) local card = table.remove(Deck)
table.insert(hand, card) table.insert(hand, card)
local suits = {["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3} return card
local tileWidth = TileMap:getWidth() / 4
local tileHeight = TileMap:getHeight() / 13
local tileX = suits[card.suit]
local tileY = math.min(card.value - 2, 9)
love.graphics.draw(TileMap, love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, TileMap:getDimensions()), x, y)
end end
end end
return Karten return Karten