black jack card help
Author |
Message |
misc-13
|
Posted: Wed Jan 09, 2013 9:41 am Post subject: black jack card help |
|
|
What is it you are trying to achieve?
What is the problem you are having?
Describe what you have tried to solve this problem
<I'm new to programming so I've just tried changing the code but my teacher says I should use a case statement, but I've never really succeeded writing one>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
this is the code right now
yes I have been to this site for help on buttons and the deck.
Turing: |
import GUI
var letter_font : int := Font.New ("Arial:9:bold")
var letter_font2 : int := Font.New ("Arial:70:bold")
var deck : array 1 .. 52 of int
%var store :array 52..1
var card, total, comptotal : int
var suit, cardNo : string
comptotal := 0
total := 0
setscreen ("graphics:520,520")
procedure cardlist %creating the cards
randint (card, 1, 52)
if deck (card ) not= - 1 then
if deck (card ) mod 13 = 0 then
cardNo := "Ace"
deck (card ):= 11
elsif deck (card ) mod 13 = 1 then
cardNo := "2"
deck (card ) := 2
elsif deck (card ) mod 13 = 2 then
cardNo := "3"
deck (card ) := 3
elsif deck (card ) mod 13 = 3 then
cardNo := "4"
deck (card ) := 4
elsif deck (card ) mod 13 = 4 then
cardNo := "5"
deck (card ) := 5
elsif deck (card ) mod 13 = 5 then
cardNo := "6"
deck (card ) := 6
elsif deck (card ) mod 13 = 6 then
cardNo := "7"
deck (card ) := 7
elsif deck (card ) mod 13 = 7 then
cardNo := "8"
deck (card ) := 8
elsif deck (card ) mod 13 = 8 then
cardNo := "9"
deck (card ) := 9
elsif deck (card ) mod 13 = 9 then
cardNo := "10"
deck (card ) := 10
elsif deck (card ) mod 13 = 10 then
cardNo := "Jack"
deck (card ) := 10
elsif deck (card ) mod 13 = 11 then
cardNo := "Queen"
deck (card ) := 10
elsif deck (card ) mod 13 = 12 then
cardNo := "King"
deck (card ) := 10
end if
if deck (card ) mod 4 = 0 then
suit := "Diamond"
elsif deck (card ) mod 4 = 1 then
suit := "Hearts"
elsif deck (card ) mod 4 = 2 then
suit := "Spades"
elsif deck (card ) mod 4 = 3 then
suit := "Clubs"
end if
end if
end cardlist
proc background %creating the background
%table
drawfillbox (0, 0, 520, 520, red)
drawfillbox (20, 20, 500, 500, green)
drawfillbox (200, 200, 320, 320, white)
drawbox (200, 200, 310, 320, black)
drawbox (200, 200, 315, 320, black)
drawbox (200, 200, 320, 320, black)
%player cards
drawfillbox (150, 150, 50, 35, white)
drawbox (150, 150, 50, 35, black)
drawfillbox (100, 150, 200, 35, white)
drawbox (100, 150, 200, 35, black)
%computer cards
drawfillbox (150, 480, 50, 365, white)
drawbox (150, 480, 50, 365, black)
drawfillbox (100, 480, 200, 365, white)
drawbox (100, 480, 200, 365, black)
%deck design
drawfillmapleleaf (205, 205, 305, 305, red)
Font.Draw ("Deck of Cards", 215, 250, letter_font, green)
%your total
Font.Draw ("your total is: ", 370, 122, letter_font, red)
%comptotal
Font.Draw ("Dealer total is: ", 370, 460, letter_font, red)
end background
for i : 1 .. 52
deck (i ) := i
end for
proc card1 %players first card
cardlist
Font.Draw (cardNo, 53, 130, letter_font, red)
Font.Draw (suit, 53, 110, letter_font, red)
total := total + deck (card )
end card1
proc card2 %players second card
cardlist
Font.Draw (cardNo, 106, 130, letter_font, red)
Font.Draw (suit, 106, 110, letter_font, red)
total := total + deck (card )
end card2
procedure showCardstart %card graphics + player total
card1
card2
locatexy (450, 122)
put total ..
end showCardstart
proc comp1 %computers first card
cardlist
Font.Draw (cardNo, 53, 460, letter_font, red)
Font.Draw (suit, 53, 440, letter_font, red)
comptotal := comptotal + deck (card )
end comp1
proc comp2 %computers second card
cardlist
Font.Draw (cardNo, 106, 460, letter_font, red)
Font.Draw (suit, 106, 440, letter_font, red)
comptotal := comptotal + deck (card )
end comp2
proc computer %computer card graphics + computer total
comp1
comp2
locatexy (460, 460)
put comptotal ..
end computer
proc winscreen %win screen
Font.Draw ("YOU WIN!", 40, 325, letter_font2, brightred)
% var button3 : int := GUI.CreateButton (230, 250, 0, "Restart?", restart)
drawfillbox (400, 250, 450, 300, green)
drawfillbox (50, 250, 150, 300, green)
end winscreen
proc losescreen %loseing screen
Font.Draw ("YOU LOSE!", 10, 325, letter_font2, brightred)
%var button3 : int := GUI.CreateButton (230, 250, 0, "Restart?", restart)
drawfillbox (400, 250, 450, 300, green)
drawfillbox (50, 250, 150, 300, green)
end losescreen
proc card21comp %if comp get 21 they win
if comptotal = 21 then
losescreen
end if
end card21comp
proc card21 %if player gets 21 they win
if total = 21 then
winscreen
end if
end card21
%proc call %start the game
background
showCardstart
computer
card21comp
card21
%end call
%call
%proc samecard
% if card1 = card2 then
% showCardstart
%end if
% if (comp1 = comp2) or (card1 = comp1) or (card1 = comp2) or (card2 = comp1) or (card2 = comp2) then
%computer
% end if
%end samecard
%samecard
%proc restart %currently still not working
% cls
% call
%end restart
proc ifstate %check card total for player
if total = 21 then
winscreen
elsif (total > 21) then
losescreen
end if
end ifstate
proc ifstatecomp %check card total for computer
locatexy (450, 122)
put total ..
if (total > comptotal ) and (total <= 21) then
winscreen
elsif (comptotal > total ) and (comptotal <= 21) then
losescreen
elsif (comptotal ) > 21 then
winscreen
elsif (total = comptotal ) then
losescreen
end if
end ifstatecomp
%proc startscreen
%colourback (green)
%Font.Draw ("WELCOME TO", 20, 325, letter_font2, brightred)
%Font.Draw ("BLACK JACK!", 20, 200, letter_font2, brightred)
%var button4 : int := GUI.CreateButton (200, 250, 0, "start", start)
%end startscreen
procedure hitcomp (var x, x2, x3 : int) %gives computer new card graphics
drawfillbox (x, 480, x2, 365, white)
drawbox (x, 480, x2, 365, black)
cardlist
Font.Draw (cardNo, x3, 460, letter_font, red)
Font.Draw (suit, x3, 440, letter_font, red)
comptotal := comptotal + deck (card )
locatexy (460, 460)
put comptotal ..
ifstatecomp
if (comptotal ) < (total ) then
end if
end hitcomp
procedure hitplayer (var x, x2, x3 : int) %gives player new card graphics
drawfillbox (x, 150, x2, 35, white)
drawbox (x, 150, x2, 35, black)
cardlist
Font.Draw (cardNo, x3, 130, letter_font, red)
Font.Draw (suit, x3, 110, letter_font, red)
total := total + deck (card )
end hitplayer
procedure hit %button procedure top give player new card
var x, x2, x3 : int
x := 150
x2 := 250
x3 := 156
hitplayer (x, x2, x3 )
locatexy (450, 122)
put total ..
ifstate
end hit
procedure stand %ends players turn and starts compyuter turn
var x, x2, x3 : int
x := 150
x2 := 250
x3 := 156
loop
if comptotal = 17 then
ifstatecomp
end if
exit when comptotal >= 17
hitcomp (x, x2, x3 )
x := x + 50
x2 := x2 + 50
x3 := x3 + 50
end loop
ifstatecomp
end stand
proc ace
if (deck (card )= 11) then
total := total- 10
%elsif total < 11 then
% total := total
end if
end ace
var button1 : int := GUI.CreateButton (400, 250, 0, "Hit", hit ) %hit button
var button2 : int := GUI.CreateButton (50, 250, 0, "Stand", stand ) %stand button
%var button3 : int := GUI.CreateButton (225,150, 0, "Ace", ace) %change ace to 1 or 11
loop %allows game to play while buttons work
exit when GUI.ProcessEvent
end loop
|
Please specify what version of Turing you are using
I am using Turing ver 4.1.1 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: Wed Jan 09, 2013 10:57 am Post subject: RE:black jack card help |
|
|
Turing: | if deck (card) mod 13 = 0 then
cardNo := "Ace"
deck(card):=11
elsif deck (card) mod 13 = 1 then
cardNo := "2"
deck (card) := 2
elsif deck (card) mod 13 = 2 then
cardNo := "3"
deck (card) := 3
elsif deck (card) mod 13 = 3 then
cardNo := "4"
deck (card) := 4
elsif deck (card) mod 13 = 4 then
cardNo := "5"
deck (card) := 5
elsif deck (card) mod 13 = 5 then
cardNo := "6"
deck (card) := 6
elsif deck (card) mod 13 = 6 then
cardNo := "7"
deck (card) := 7
elsif deck (card) mod 13 = 7 then
cardNo := "8"
deck (card) := 8
elsif deck (card) mod 13 = 8 then
cardNo := "9"
deck (card) := 9
elsif deck (card) mod 13 = 9 then
cardNo := "10"
deck (card) := 10
elsif deck (card) mod 13 = 10 then
cardNo := "Jack"
deck (card) := 10
elsif deck (card) mod 13 = 11 then
cardNo := "Queen"
deck (card) := 10
elsif deck (card) mod 13 = 12 then
cardNo := "King"
deck (card) := 10
end if |
Most of this can be moved to a for loop. Can you figure out how? I'll give you a hint: You'll need the intstr() command. |
|
|
|
|
 |
|
|