It looks like you're new here. If you want to get involved, click one of these buttons!
Card geme : Acey-Ducey, stuck on line 153, repeat is wrong word,
Can anyone help ? Heres the code below
--Acey-Deucy
function showIntro()
print --[[
ACEY-DUCEY IS PLAYED IN THE FOLLOWING MANNER
THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP
YOU HAVE AN OPTION TO BET OR NOT BET DEPENDING
ON WHETHER OR NOT YOU FEEL THE CARD WILL HAVE
A VALUE BETWEEN THE FIRST TWO.
IF YOU DO NOT WANT TO BET, ENTER A $0 BET
]]--
end
-- Initialises the Global BankBalance and Random Number Generator
function initGame()
bankBalance = 100
math.randomseed( os.time() )
end
-- shows the card type
function showCard(val)
local cards={ nil, 2, 3, 4, 5, 6, 7, 8, 9, 10, "JACK", "QUEEN", "KING", "ACE"}
return cards[val]
end
-- Displays the current bank balance (global)
function showBalance()
print("You Now Have "..bankBalance.." Dollars.")
end
-- Adjusts the global balance
function adjustBalance( amount )
bankBalance = bankBalance + amount
showBalance()
end
-- Generates a random card
function dealCard()
local nextCardValue = math.random(2,14)
return nextCardValue
end
-- Deals cards returns a collection of two
function dealCards()
print("HERE ARE THE NEXT TWO CARDS:")
local cardValues = {first=dealCard(),second=dealCard()}
print( "First Card:" .. showCard(cardValues.first) )
print( "Second Card:" .. showCard(cardValues.second) )
return cardValues
end
-- Inputs a bet value
function getBet()
betOK = false
local betAmount = 0
-- Loop to get a valid bet or a zero bet
repeat
io.write("What is Your Bet ? :");
local amount = io.read();
betAmount = tonumber(amount)
if betAmount==0 then
print("Chicken!!")
betOK = true
end
if betAmount <= bankBalance then
betOK = true
else
print("Sorry, but you bet too much.")
print("You have only " .. bankBalance .. " Dollars to bet.")
end
until betOK
return betAmount
end
-- Deals another card and compares values
function playRound( cardValues )
local playerCard = dealCard()
local firstCard = cardValues.first
local secondCard = cardValues.second
print( "Dealer Card" .. showCard(playerCard) )
local minValue = math.min( firstCard, secondCard )
local maxValue = math.max( firstCard, secondCard )
if playerCard>=minValue and playerCard <=maxValue then
print("You Win!!!")
return true
end
print("You Lose!!")
return false
end
function endGameReplay()
print ("Sorry, but you blue your wad.")
io.write("Try Again (Y/N)")
response = io.read()
if repsonse == "Y" then
return true
else
print("O.K., Hope you had fun !")
return false
end
end
-- Main Loop ; Here's when the action happens
showIntro()
done = false -- when true the game loop ends
initGame()
-- Game Loop
repeat
local cardValues = dealCards()
local betAmount = getBet()
if betAmount == 0 then
done=true -- user said they don't want to play anymore
else
if playRound(cardValues) then
adjustBalance( betAmount )
else
adjustBalance( -betAmount )
-- if no more money then ask to start again
if bankBalance <= 0 then
if endGameReplay()==true then
-- Start again
initGame() -- reset variables
end
done=true
end
end
end
Comments
"repeat" isn't a Lua keyword. You can use
while(condition) .... end
for a loop loop. If condition is false, it will skip running the loop and move on. If condition is always true, it will run until it his abreak
.@kendog400 Anytime you post code, put 3 ~'s on a line before and after the code so it shows correctly.
...
...
@kendog400 Where did you get the code from. It looks like you copied it from somewhere and you think it's going to work in Codea. There's a lot of things in the above code that isn't going to work.
@syntonica repeat is valid. Try this code.
Ack! Sorry about that to the OP. Repeat/until will run at least once while a while may never run.
I never use repeat/until since I never need it.
Yes, I copied it from a site on-line, I would like to program Card Games, so it is part of a study until I get my roll on...
The card Game was written LUA, but I see now that, it doesent mean it would work in Codea....In any event Thanks for the Help !
@kendog400 Do a forum search for cards games. You might come up with some interesting things.
@kendog400 If you want to play with card games, maybe this would help some.
It looks like this was designed for a Lua compiler running on windows platform and was not programed for Codea.
Ok, first off, i looked at the original page you got this code from. You're missing this line
until done
at the end of the script. happened to me when i copied it too.second, it still won't run - not toally sure why, but i think (just a theory) that Codea won't allow you to run a script if there's a repeat or while loop that hasn't finished running. when you do try, it disables the play button and the extra features on the keynoard as well, so maybe a bug there
so replace the repeat, until with
function draw() if not done then --[[ the code already there ]] else return end end
ok, so i did that, now im having issues adapting the io read write etc. the real trick is going to be getting io.read to work.
local amount = io.read();
See, what i want is for io.read to bring up the keyboard, but the repeat loop keeps going. so... ill need to rewritr everything >:(
edit: i give up. this is too hard to convert into codea
I would like to see more youtube type tutorials for codea. Programming isn't for the faint at heart and it takes a lot of brain power.. 3d max, cinema 4d, zbrush, photoshop all have large followings, and a large amount of youtube tutorials. I would like to see codea with this type of enviorment.
@kendog400 I never liked video tutorials myself. for something like photoshop or krita i can see why it is useful, but when programming i really prefer to have a reference guide in another phone or book while i code. Actually,learning it myself, I still have't gone into the new Craft stuff yet or even figured ot physics - busy learning everything else.
Hm.. Checklist of what you know? This stuff is lua that I think would be nice to know
t={a=false,b=false}
, set every false value to true using a for loopwhile condition ... do
looprepeat .. until
loop >! Will always run at least once, it runs first, then checks if condition is true or false, whereas a while loop checks condition first, and so might never run.function f(x) return x<10 and f(x+1) or x end
print(f(1));
x=1; x = x==2 and 3 or 0;
So this is the same asif x==2 then x = 3; else x = 0; end
but easier to write. if you didn't include the 'or 0' then it would be by default false', because the or part only runs if the 'condition' is untruelocal a,b,c = 1,2; print(a,b,c)
>! 1,2,nil...
@kendog400 Here’s my above code with a few modifications to shuffle a deck of cards. My suggestion is to look over this code and try to understand what’s happening. That’s an easy way to learn.
Thank You for the help..
...
I have here a program again, it dident go through last time. It prints the hand to the screen vertically, i'm trying to figure out i can get this printed horizontally, then use the "\n" to print the suit on the next line, after that i would use the vec2's to put a rectangle under it to make it look like a card.
Can anyone take a peek to help me find the spot where i could take control and make the print out horizontal(straight across) ?
I've been trying to figure this out, buy changing every spot, but I havent figured it out as of yet.
This looks like a good game here, and a good starting point.
Change the function show with this.
Thanks a Million !!!
...
@kendog400 You only need to swap 2 numbers and reduce the value of a third number then change it from portrait to landscape mode.
Thanks again !...I'LL be getting back to the drawing board. Next I would like to put in some shuffle sounds and such...I dont know which is the third number to reduce, but I'LL try to figure it out...
@kendog400 Once you run the code in landscape mode with the 2 values swapped, you’ll know what number to reduce.
@kendog400 You might like this code.