lot of things ig. Lastly made function also show the card on passed coordinates. Coordinates are not getting passed over yet in blackjack.lua. It isnt testet also lol
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"diagnostics.globals": [
|
"diagnostics.globals": [
|
||||||
"currentScreen",
|
"currentScreen",
|
||||||
"drawMenu"
|
"drawMenu",
|
||||||
|
"spielerHand"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,42 @@
|
|||||||
|
local love = require "love"
|
||||||
require "karten"
|
require "karten"
|
||||||
|
|
||||||
spielerHand = {}
|
spielerHand = {}
|
||||||
dealerHand = {}
|
DealerHand = {}
|
||||||
deck = {}
|
Deck = {}
|
||||||
|
|
||||||
function loadBlackjack()
|
function LoadBlackjack()
|
||||||
deck = createDeck()
|
Deck = Karten:createDeck()
|
||||||
shuffleDeck(deck)
|
Karten:shuffleDeck(Deck)
|
||||||
dealInitialCards()
|
DealInitialCards()
|
||||||
|
Cards = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateBlackjack(dt)
|
function UpdateBlackjack(dt)
|
||||||
-- Hier können zukünftige Updates für Blackjack hinzugefügt werden
|
-- Hier können zukünftige Updates für Blackjack hinzugefügt werden
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawBlackjack()
|
function DrawBlackjack()
|
||||||
love.graphics.print("Spieler Hand: " .. handValue(spielerHand), 50, 50)
|
print(love.graphics:getWidth())
|
||||||
love.graphics.print("Dealer Hand: " .. handValue(dealerHand), 50, 100)
|
love.graphics.draw(Cards, love.graphics.getWidth() / 2 - 90 , 50, 0, 0.2)
|
||||||
love.graphics.print("Drücke 'H' für Hit oder 'S' für Stand", 50, 150)
|
-- love.graphics.print("Spieler Hand: " .. Karten:handValue(spielerHand), 50, 50)
|
||||||
|
-- love.graphics.print("Dealer Hand: " .. Karten:handValue(DealerHand), 50, 100)
|
||||||
|
-- love.graphics.print("Drücke 'H' für Hit oder 'S' für Stand", 50, 150)
|
||||||
end
|
end
|
||||||
|
|
||||||
function handleBlackjackInput(key)
|
function HandleBlackjackInput(key)
|
||||||
if key == 'h' then
|
if key == 'h' then
|
||||||
hit(spielerHand)
|
Karten:hit(spielerHand)
|
||||||
if handValue(spielerHand) > 21 then
|
if Karten:handValue(spielerHand) > 21 then
|
||||||
love.graphics.print("Spieler hat verloren!", 50, 200)
|
love.graphics.print("Spieler hat verloren!", 50, 200)
|
||||||
end
|
end
|
||||||
elseif key == 's' then
|
elseif key == 's' then
|
||||||
while handValue(dealerHand) < 17 do
|
while Karten:handValue(DealerHand) < 17 do
|
||||||
hit(dealerHand)
|
Karten:hit(DealerHand)
|
||||||
end
|
end
|
||||||
if handValue(dealerHand) > 21 then
|
if Karten:handValue(DealerHand) > 21 then
|
||||||
love.graphics.print("Dealer hat verloren!", 50, 200)
|
love.graphics.print("Dealer hat verloren!", 50, 200)
|
||||||
elseif handValue(spielerHand) > handValue(dealerHand) then
|
elseif Karten:handValue(spielerHand) > Karten:handValue(DealerHand) then
|
||||||
love.graphics.print("Spieler gewinnt!", 50, 200)
|
love.graphics.print("Spieler gewinnt!", 50, 200)
|
||||||
else
|
else
|
||||||
love.graphics.print("Dealer gewinnt!", 50, 200)
|
love.graphics.print("Dealer gewinnt!", 50, 200)
|
||||||
@@ -40,10 +44,10 @@ function handleBlackjackInput(key)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function dealInitialCards()
|
function DealInitialCards()
|
||||||
for i = 1, 2 do
|
for i = 1, 2 do
|
||||||
hit(spielerHand)
|
Karten:hit(spielerHand)
|
||||||
hit(dealerHand)
|
Karten:hit(DealerHand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1,34 +0,0 @@
|
|||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="CompressedTexture2D"
|
|
||||||
uid="uid://bmhicnjvqrotx"
|
|
||||||
path="res://.godot/imported/CuteCardsPixel.png-bbdbd180a598bcdd28e9cc85e1935838.ctex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://assets/CuteCards - asset pack/pixelCards/CuteCardsPixel.png"
|
|
||||||
dest_files=["res://.godot/imported/CuteCardsPixel.png-bbdbd180a598bcdd28e9cc85e1935838.ctex"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/high_quality=false
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_compression=1
|
|
||||||
compress/normal_map=0
|
|
||||||
compress/channel_pack=0
|
|
||||||
mipmaps/generate=false
|
|
||||||
mipmaps/limit=-1
|
|
||||||
roughness/mode=0
|
|
||||||
roughness/src_normal=""
|
|
||||||
process/fix_alpha_border=true
|
|
||||||
process/premult_alpha=false
|
|
||||||
process/normal_map_invert_y=false
|
|
||||||
process/hdr_as_srgb=false
|
|
||||||
process/hdr_clamp_exposure=false
|
|
||||||
process/size_limit=0
|
|
||||||
detect_3d/compress_to=1
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1,34 +0,0 @@
|
|||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="CompressedTexture2D"
|
|
||||||
uid="uid://dm33tyrs31h6b"
|
|
||||||
path="res://.godot/imported/CuteCardsPixel_outline.png-a6e98435eaee73056b7affa8bbf5e1e2.ctex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://assets/CuteCards - asset pack/pixelCards/CuteCardsPixel_outline.png"
|
|
||||||
dest_files=["res://.godot/imported/CuteCardsPixel_outline.png-a6e98435eaee73056b7affa8bbf5e1e2.ctex"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/high_quality=false
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_compression=1
|
|
||||||
compress/normal_map=0
|
|
||||||
compress/channel_pack=0
|
|
||||||
mipmaps/generate=false
|
|
||||||
mipmaps/limit=-1
|
|
||||||
roughness/mode=0
|
|
||||||
roughness/src_normal=""
|
|
||||||
process/fix_alpha_border=true
|
|
||||||
process/premult_alpha=false
|
|
||||||
process/normal_map_invert_y=false
|
|
||||||
process/hdr_as_srgb=false
|
|
||||||
process/hdr_clamp_exposure=false
|
|
||||||
process/size_limit=0
|
|
||||||
detect_3d/compress_to=1
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
@@ -1,34 +0,0 @@
|
|||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="CompressedTexture2D"
|
|
||||||
uid="uid://d4lvd2ngebob7"
|
|
||||||
path="res://.godot/imported/PokerChipsPixel.png-c94cf11a09e7c8bc77d14bdf4442ee7e.ctex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://assets/CuteCards - asset pack/pixelCards/PokerChipsPixel.png"
|
|
||||||
dest_files=["res://.godot/imported/PokerChipsPixel.png-c94cf11a09e7c8bc77d14bdf4442ee7e.ctex"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/high_quality=false
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_compression=1
|
|
||||||
compress/normal_map=0
|
|
||||||
compress/channel_pack=0
|
|
||||||
mipmaps/generate=false
|
|
||||||
mipmaps/limit=-1
|
|
||||||
roughness/mode=0
|
|
||||||
roughness/src_normal=""
|
|
||||||
process/fix_alpha_border=true
|
|
||||||
process/premult_alpha=false
|
|
||||||
process/normal_map_invert_y=false
|
|
||||||
process/hdr_as_srgb=false
|
|
||||||
process/hdr_clamp_exposure=false
|
|
||||||
process/size_limit=0
|
|
||||||
detect_3d/compress_to=1
|
|
||||||
1
conf.lua
1
conf.lua
@@ -1,3 +1,4 @@
|
|||||||
|
local love = require "love"
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
t.window.width = 350
|
t.window.width = 350
|
||||||
end
|
end
|
||||||
|
|||||||
34
karten.lua
34
karten.lua
@@ -1,30 +1,28 @@
|
|||||||
karten = {}
|
local love = require "love"
|
||||||
|
Karten = {}
|
||||||
|
|
||||||
function createDeck()
|
function Karten:createDeck()
|
||||||
local deck = {}
|
local deck = {}
|
||||||
local suits = {"Herz", "Karo", "Pik", "Kreuz"}
|
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, 10, 10, 10, 11} -- 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})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TileMap = love.graphics.newImage("/cards_asset_pack/CuteCards.png")
|
||||||
return deck
|
return deck
|
||||||
end
|
end
|
||||||
|
|
||||||
function shuffleDeck(deck)
|
function Karten:shuffleDeck(deck)
|
||||||
for i = #deck, 2, -1 do
|
for i = #deck, 2, -1 do
|
||||||
local j = love.math.random(i)
|
local j = love.math.random(i)
|
||||||
deck[i], deck[j] = deck[j], deck[i]
|
deck[i], deck[j] = deck[j], deck[i]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function hit(hand)
|
function Karten:handValue(hand)
|
||||||
local card = table.remove(deck)
|
|
||||||
table.insert(hand, card)
|
|
||||||
end
|
|
||||||
|
|
||||||
function handValue(hand)
|
|
||||||
local value = 0
|
local value = 0
|
||||||
local aces = 0
|
local aces = 0
|
||||||
for _, card in ipairs(hand) do
|
for _, card in ipairs(hand) do
|
||||||
@@ -40,5 +38,19 @@ function handValue(hand)
|
|||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
return karten
|
function Karten:hit(x, y, hand)
|
||||||
|
if #Deck > 0 then
|
||||||
|
local card = table.remove(Deck)
|
||||||
|
table.insert(hand, card)
|
||||||
|
local suits = {["Clubs"] = 0, ["Diamonds"] = 1, ["Spades"] = 2, ["Hearts"] = 3}
|
||||||
|
local tileWidth = TileMap:getWidth() / 4
|
||||||
|
local tileHeight = TileMap:getHeight() / 13
|
||||||
|
local tileX = suits[card.suit]
|
||||||
|
local tileY = math.min(card.value - 2, 9)
|
||||||
|
love.graphics.draw(TileMap, love.graphics.newQuad(tileX * tileWidth, tileY * tileHeight, tileWidth, tileHeight, TileMap:getDimensions()), x, y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return Karten
|
||||||
|
|||||||
9
main.lua
9
main.lua
@@ -6,11 +6,12 @@ require "blackjack"
|
|||||||
function love.load()
|
function love.load()
|
||||||
love.window.setTitle("Spiele Auswahl")
|
love.window.setTitle("Spiele Auswahl")
|
||||||
currentScreen = "menu"
|
currentScreen = "menu"
|
||||||
|
love.graphics.setBackgroundColor(0.30 ,0.30 ,0.46, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
if currentScreen == "blackjack" then
|
if currentScreen == "blackjack" then
|
||||||
updateBlackjack(dt)
|
UpdateBlackjack(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ function love.draw()
|
|||||||
if currentScreen == "menu" then
|
if currentScreen == "menu" then
|
||||||
drawMenu()
|
drawMenu()
|
||||||
elseif currentScreen == "blackjack" then
|
elseif currentScreen == "blackjack" then
|
||||||
drawBlackjack()
|
DrawBlackjack()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,10 +27,10 @@ function love.keypressed(key)
|
|||||||
if currentScreen == "menu" then
|
if currentScreen == "menu" then
|
||||||
if key == '1' then
|
if key == '1' then
|
||||||
currentScreen = "blackjack"
|
currentScreen = "blackjack"
|
||||||
loadBlackjack()
|
LoadBlackjack()
|
||||||
end
|
end
|
||||||
elseif currentScreen == "blackjack" then
|
elseif currentScreen == "blackjack" then
|
||||||
handleBlackjackInput(key)
|
HandleBlackjackInput(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user