everything fixed. next step is to implement a function that checks if somebody lost
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/JustNormalCards.png")
|
||||
Cards = love.graphics.newImage("/cards_asset_pack/JustNormalCardsSwitched.png")
|
||||
end
|
||||
|
||||
function UpdateBlackjack(dt)
|
||||
@@ -28,39 +28,61 @@ function DrawBlackjack()
|
||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||
local tileWidth = Cards:getWidth() / 13
|
||||
local tileHeight = Cards:getHeight() / 4
|
||||
local scale = 0.5
|
||||
local drawW, drawH = tileWidth * scale, tileHeight * scale
|
||||
local spacingX, spacingY = 1, 1
|
||||
|
||||
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
|
||||
)
|
||||
local function drawHandGrid(hand, basePos)
|
||||
if #hand == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local cols = 3
|
||||
local rows = math.ceil(#hand / cols)
|
||||
|
||||
for row = 0, rows - 1 do
|
||||
local startIdx = row * cols + 1
|
||||
local endIdx = math.min(startIdx + cols - 1, #hand)
|
||||
local cardsInRow = endIdx - startIdx + 1
|
||||
|
||||
local rowWidth = cardsInRow * drawW + (cardsInRow - 1) * spacingX
|
||||
local startX = basePos.x - rowWidth / 2
|
||||
|
||||
for j = 0, cardsInRow - 1 do
|
||||
local i = startIdx + j
|
||||
local card = hand[i]
|
||||
|
||||
local tileX = math.min(card.value - 2, 12)
|
||||
local tileY = suits[card.suit] or 0
|
||||
local quad = love.graphics.newQuad(
|
||||
tileX * tileWidth,
|
||||
tileY * tileHeight,
|
||||
tileWidth,
|
||||
tileHeight,
|
||||
Cards:getDimensions()
|
||||
)
|
||||
|
||||
local x = startX + j * (drawW + spacingX)
|
||||
local y = basePos.y + row * (drawH + spacingY)
|
||||
|
||||
love.graphics.draw(Cards, quad, x, y, 0, scale, scale)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.print(GetHandValue(PlayerHand), PlayerHandPosition.x, PlayerHandPosition.y + tileHeight + 5)
|
||||
drawHandGrid(PlayerHand, PlayerHandPosition)
|
||||
love.graphics.print(
|
||||
GetHandValue(PlayerHand),
|
||||
PlayerHandPosition.x,
|
||||
PlayerHandPosition.y + (math.ceil(#PlayerHand / 3) * drawH) + 15
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
end
|
||||
|
||||
love.graphics.print(GetHandValue(DealerHand), DealerHandPosition.x, DealerHandPosition.y + tileHeight + 5)
|
||||
drawHandGrid(DealerHand, DealerHandPosition)
|
||||
love.graphics.print(
|
||||
GetHandValue(DealerHand),
|
||||
DealerHandPosition.x,
|
||||
DealerHandPosition.y + (math.ceil(#DealerHand / 3) * drawH) + 15
|
||||
)
|
||||
end
|
||||
|
||||
function GetHandValue(hand)
|
||||
@@ -70,11 +92,15 @@ function GetHandValue(hand)
|
||||
for _, card in pairs(hand) do
|
||||
if card.value < 10 then
|
||||
count = count + card.value
|
||||
print("+" .. card.value)
|
||||
elseif card.value < 14 then
|
||||
count = count + 10
|
||||
print("+" .. card.value)
|
||||
else
|
||||
count = count + 11
|
||||
print("+" .. 11)
|
||||
aces = aces + 1
|
||||
print("+ 1 ace = " .. aces)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,6 +112,7 @@ function GetHandValue(hand)
|
||||
goto aceloop
|
||||
end
|
||||
end
|
||||
print("end------------")
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
BIN
cards_asset_pack/JustNormalCardsSwitched.png
Normal file
BIN
cards_asset_pack/JustNormalCardsSwitched.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@@ -5,7 +5,7 @@ Karten = {}
|
||||
function Karten:createDeck()
|
||||
local deck = {}
|
||||
local suits = { "Clubs", "Diamonds", "Spades", "Hearts" }
|
||||
local values = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 } -- 10, J, Q, K sind alle 10, A ist 11
|
||||
local values = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }
|
||||
for _, suit in ipairs(suits) do
|
||||
for _, value in ipairs(values) do
|
||||
table.insert(deck, { suit = suit, value = value })
|
||||
|
||||
Reference in New Issue
Block a user