commit 4ccfa4b12e8fd5a9c19771e6f20fe8cc9c4f6a99 Author: Nico Date: Thu Jul 31 19:56:08 2025 +0200 init diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..abcdd00 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,6 @@ +{ + "diagnostics.globals": [ + "currentScreen", + "drawMenu" + ] +} \ No newline at end of file diff --git a/blackjack.lua b/blackjack.lua new file mode 100644 index 0000000..7c32112 --- /dev/null +++ b/blackjack.lua @@ -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 + diff --git a/conf.lua b/conf.lua new file mode 100644 index 0000000..d734ad5 --- /dev/null +++ b/conf.lua @@ -0,0 +1,3 @@ +function love.conf(t) + t.window.width = 350 +end diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7e9d064 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6b117fa --- /dev/null +++ b/flake.nix @@ -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 + ''; + }; + }); +} + + diff --git a/karten.lua b/karten.lua new file mode 100644 index 0000000..ac22bf2 --- /dev/null +++ b/karten.lua @@ -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 + diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..80c058e --- /dev/null +++ b/main.lua @@ -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 + diff --git a/menu.lua b/menu.lua new file mode 100644 index 0000000..2fe669d --- /dev/null +++ b/menu.lua @@ -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 +