This commit is contained in:
Nico
2025-07-31 19:56:08 +02:00
commit 4ccfa4b12e
8 changed files with 242 additions and 0 deletions

6
.luarc.json Normal file
View File

@@ -0,0 +1,6 @@
{
"diagnostics.globals": [
"currentScreen",
"drawMenu"
]
}

49
blackjack.lua Normal file
View File

@@ -0,0 +1,49 @@
require "karten"
spielerHand = {}
dealerHand = {}
deck = {}
function loadBlackjack()
deck = createDeck()
shuffleDeck(deck)
dealInitialCards()
end
function updateBlackjack(dt)
-- Hier können zukünftige Updates für Blackjack hinzugefügt werden
end
function drawBlackjack()
love.graphics.print("Spieler Hand: " .. handValue(spielerHand), 50, 50)
love.graphics.print("Dealer Hand: " .. handValue(dealerHand), 50, 100)
love.graphics.print("Drücke 'H' für Hit oder 'S' für Stand", 50, 150)
end
function handleBlackjackInput(key)
if key == 'h' then
hit(spielerHand)
if handValue(spielerHand) > 21 then
love.graphics.print("Spieler hat verloren!", 50, 200)
end
elseif key == 's' then
while handValue(dealerHand) < 17 do
hit(dealerHand)
end
if handValue(dealerHand) > 21 then
love.graphics.print("Dealer hat verloren!", 50, 200)
elseif handValue(spielerHand) > handValue(dealerHand) then
love.graphics.print("Spieler gewinnt!", 50, 200)
else
love.graphics.print("Dealer gewinnt!", 50, 200)
end
end
end
function dealInitialCards()
for i = 1, 2 do
hit(spielerHand)
hit(dealerHand)
end
end

3
conf.lua Normal file
View File

@@ -0,0 +1,3 @@
function love.conf(t)
t.window.width = 350
end

61
flake.lock generated Normal file
View File

@@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1753694789,
"narHash": "sha256-cKgvtz6fKuK1Xr5LQW/zOUiAC0oSQoA9nOISB0pJZqM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dc9637876d0dcc8c9e5e22986b857632effeb727",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"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",
"version": 7
}

30
flake.nix Normal file
View File

@@ -0,0 +1,30 @@
{
description = "Love you";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShell =
with pkgs; mkShell rec {
buildInputs = [
love
];
shellHook = ''
zsh
exit
'';
};
});
}

44
karten.lua Normal file
View File

@@ -0,0 +1,44 @@
karten = {}
function createDeck()
local deck = {}
local suits = {"Herz", "Karo", "Pik", "Kreuz"}
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
return deck
end
function 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)
local value = 0
local aces = 0
for _, card in ipairs(hand) do
value = value + card.value
if card.value == 11 then
aces = aces + 1
end
end
while value > 21 and aces > 0 do
value = value - 10
aces = aces - 1
end
return value
end
return karten

35
main.lua Normal file
View File

@@ -0,0 +1,35 @@
local love = require "love"
require "menu"
require "blackjack"
function love.load()
love.window.setTitle("Spiele Auswahl")
currentScreen = "menu"
end
function love.update(dt)
if currentScreen == "blackjack" then
updateBlackjack(dt)
end
end
function love.draw()
if currentScreen == "menu" then
drawMenu()
elseif currentScreen == "blackjack" then
drawBlackjack()
end
end
function love.keypressed(key)
if currentScreen == "menu" then
if key == '1' then
currentScreen = "blackjack"
loadBlackjack()
end
elseif currentScreen == "blackjack" then
handleBlackjackInput(key)
end
end

14
menu.lua Normal file
View File

@@ -0,0 +1,14 @@
local love = require "love"
function drawMenu()
love.graphics.print("Willkommen im Spiele Auswahl!", 50, 50)
love.graphics.print("Drücke '1' für Blackjack", 50, 100)
love.graphics.print("Drücke 'ESC', um zu beenden", 50, 150)
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
end