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)
|
||||
|
||||
74
flake.lock
generated
74
flake.lock
generated
@@ -1,9 +1,47 @@
|
||||
{
|
||||
"nodes": {
|
||||
"cursor": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1747112672,
|
||||
"narHash": "sha256-kUkbIQwb65KiMaxWVTtLmSdgpE/ANFquJ1OLKlZNjZs=",
|
||||
"owner": "omarcresp",
|
||||
"repo": "cursor-flake",
|
||||
"rev": "52061a31dd7fcdfc04e8c4abfeaadf67039324c9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "omarcresp",
|
||||
"ref": "main",
|
||||
"repo": "cursor-flake",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
@@ -19,6 +57,22 @@
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725103162,
|
||||
"narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1753694789,
|
||||
"narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=",
|
||||
@@ -36,8 +90,9 @@
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"cursor": "cursor",
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
@@ -54,6 +109,21 @@
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
cursor.url = "github:omarcresp/cursor-flake/main";
|
||||
};
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
outputs = { self, nixpkgs, flake-utils, cursor }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
@@ -17,6 +18,7 @@
|
||||
with pkgs; mkShell rec {
|
||||
buildInputs = [
|
||||
love
|
||||
cursor.packages.${pkgs.system}.default
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
|
||||
@@ -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, 10, 10, 10, 11 } -- 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 } -- 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 })
|
||||
|
||||
Reference in New Issue
Block a user