lot of things ig. Lastly made function also show the card on passed coordinates. Coordinates are not getting passed over yet in blackjack.lua. It isnt testet also lol

This commit is contained in:
Nico
2025-08-08 00:10:21 +02:00
parent b9cf171776
commit 686f6d8962
11 changed files with 56 additions and 139 deletions

View File

@@ -1,30 +1,28 @@
karten = {}
local love = require "love"
Karten = {}
function createDeck()
function Karten:createDeck()
local deck = {}
local suits = {"Herz", "Karo", "Pik", "Kreuz"}
local suits = {"Clubs", "Diamonds", "Spades", "Hearts"}
local values = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11} -- 10, J, Q, K sind alle 10, A ist 11
for _, suit in ipairs(suits) do
for _, value in ipairs(values) do
table.insert(deck, {suit = suit, value = value})
end
end
TileMap = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
return deck
end
function shuffleDeck(deck)
function Karten:shuffleDeck(deck)
for i = #deck, 2, -1 do
local j = love.math.random(i)
deck[i], deck[j] = deck[j], deck[i]
end
end
function hit(hand)
local card = table.remove(deck)
table.insert(hand, card)
end
function handValue(hand)
function Karten:handValue(hand)
local value = 0
local aces = 0
for _, card in ipairs(hand) do
@@ -40,5 +38,19 @@ function handValue(hand)
return value
end
return karten
function Karten:hit(x, y, hand)
if #Deck > 0 then
local card = table.remove(Deck)
table.insert(hand, card)
local suits = {["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3}
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
return Karten