shows wrong cards i guess
This commit is contained in:
@@ -17,7 +17,7 @@ function LoadBlackjack()
|
|||||||
Deck = Karten:createDeck()
|
Deck = Karten:createDeck()
|
||||||
Karten:shuffleDeck(Deck)
|
Karten:shuffleDeck(Deck)
|
||||||
DealInitialCards()
|
DealInitialCards()
|
||||||
Cards = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
|
Cards = love.graphics.newImage("/cards_asset_pack/JustNormalCards.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
function UpdateBlackjack(dt)
|
function UpdateBlackjack(dt)
|
||||||
@@ -25,38 +25,70 @@ function UpdateBlackjack(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function DrawBlackjack()
|
function DrawBlackjack()
|
||||||
for i, card in ipairs(PlayerHand) do
|
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
local tileWidth = Cards:getWidth() / 13
|
||||||
local tileWidth = Cards:getWidth() / 15
|
local tileHeight = Cards:getHeight() / 4
|
||||||
local tileHeight = Cards:getHeight() / 4
|
|
||||||
local tileX = suits[card.suit]
|
for _, card in pairs(PlayerHand) do
|
||||||
local tileY = math.min(card.value - 2, 9)
|
local tileX = card.value - 2
|
||||||
|
local tileY = suits[card.suit]
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
Cards,
|
Cards,
|
||||||
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
||||||
PlayerHandPosition.x - tileWidth / 4,
|
PlayerHandPosition.x - tileWidth / 4,
|
||||||
PlayerHandPosition.y,
|
PlayerHandPosition.y,
|
||||||
0,
|
0,
|
||||||
0.5
|
0.5
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
for i, card in ipairs(DealerHand) do
|
|
||||||
local suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
love.graphics.print(GetHandValue(PlayerHand), PlayerHandPosition.x, PlayerHandPosition.y + tileHeight + 5)
|
||||||
local tileWidth = Cards:getWidth() / 15
|
|
||||||
local tileHeight = Cards:getHeight() / 4
|
for _, card in pairs(DealerHand) do
|
||||||
local tileX = suits[card.suit]
|
suits = { ["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3 }
|
||||||
local tileY = math.min(card.value - 2, 9)
|
tileWidth = Cards:getWidth() / 13
|
||||||
|
tileHeight = Cards:getHeight() / 4
|
||||||
|
local tileX = math.min(card.value - 2, 9)
|
||||||
|
local tileY = suits[card.suit]
|
||||||
love.graphics.draw(
|
love.graphics.draw(
|
||||||
Cards,
|
Cards,
|
||||||
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, Cards:getDimensions()),
|
||||||
DealerHandPosition.x - tileWidth / 4,
|
DealerHandPosition.x - tileWidth / 4,
|
||||||
DealerHandPosition.y,
|
DealerHandPosition.y,
|
||||||
0,
|
0,
|
||||||
0.5
|
0.5
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.graphics.print(GetHandValue(DealerHand), DealerHandPosition.x, DealerHandPosition.y + tileHeight + 5)
|
||||||
end
|
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)
|
function HandleBlackjackInput(key)
|
||||||
if key == "h" then
|
if key == "h" then
|
||||||
@@ -66,7 +98,7 @@ function HandleBlackjackInput(key)
|
|||||||
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
|
||||||
-- print("Dealer hat verloren!", 50, 200)
|
-- print("Dealer hat verloren!", 50, 200)
|
||||||
|
|||||||
74
flake.lock
generated
74
flake.lock
generated
@@ -1,9 +1,47 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"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": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"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": {
|
"locked": {
|
||||||
"lastModified": 1731533236,
|
"lastModified": 1731533236,
|
||||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
@@ -19,6 +57,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"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": {
|
"locked": {
|
||||||
"lastModified": 1753694789,
|
"lastModified": 1753694789,
|
||||||
"narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=",
|
"narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=",
|
||||||
@@ -36,8 +90,9 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"cursor": "cursor",
|
||||||
"nixpkgs": "nixpkgs"
|
"flake-utils": "flake-utils_2",
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
@@ -54,6 +109,21 @@
|
|||||||
"repo": "default",
|
"repo": "default",
|
||||||
"type": "github"
|
"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",
|
"root": "root",
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
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:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
with pkgs; mkShell rec {
|
with pkgs; mkShell rec {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
love
|
love
|
||||||
|
cursor.packages.${pkgs.system}.default
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Karten = {}
|
|||||||
function Karten:createDeck()
|
function Karten:createDeck()
|
||||||
local deck = {}
|
local deck = {}
|
||||||
local suits = { "Clubs", "Diamonds", "Spades", "Hearts" }
|
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 _, suit in ipairs(suits) do
|
||||||
for _, value in ipairs(values) do
|
for _, value in ipairs(values) do
|
||||||
table.insert(deck, { suit = suit, value = value })
|
table.insert(deck, { suit = suit, value = value })
|
||||||
|
|||||||
Reference in New Issue
Block a user