Isu Help Crazy Eights!!!
Author |
Message |
djshady
|
Posted: Tue Jan 13, 2009 8:34 am Post subject: Isu Help Crazy Eights!!! |
|
|
hey guys... any1 noe how to make a crazy 8 game on turing...
should consist of 4 classes.. Card/Hand/Deck/game
and im LOST.. help please |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Tue Jan 13, 2009 10:41 am Post subject: RE:Isu Help Crazy Eights!!! |
|
|
How did you decide that it should consist of Card/Hand/Deck/game?
Think about how crazy 8's is played:
You have several players, though at most about six (you will need to keep track of 6 separate players, each of whom has a name and 1-20 cards, for example). You will therefore need a Player class or type to hold that information. Your game will need an array of Player objects to represent all of the players.
Whenever a card is played, either the suit must match, or the card's number must match. A simple way to treat cards might be like this: treat each card as an integer, with hundreds digit representing the suit, and the tens/ones representing the value. Assuming 0=clubs, 1=hearts, 2=diamonds, 3=spades (whatever), you have card 312 = Queen of Spades, card 7 = 7 of Clubs. Then, you can make a pretty simple comparison: either the hundreds digit of the new card matches, or the remainder after dividing away the hundreds does, or the card can't be played.
Some cards, when played, have a special effect. These effects would be hand-coded. I'm not sure what rules you play by, but this is what I recall:
2 - next player draws two cards and loses their turn: just tell the next player to draw two cards, then skip ahead two in play instead of one.
4 - play reverses direction: have a "direction" variable telling you whether your play is going 1..2..3..4..5 or 5..4..3..2..1. Using +1 for forwards and -1 for backwards works well, since you can just multiply "direction" by "amount" to get "amount and direction together".
7 - next player loses their turn: just skip ahead 2 instead of 1.
8 - player may declare the next suit. For this, I recommend playing another "ghost" card on top of the 8 the player actually played. If I play the 8 of spades, but choose hearts, have the game place an magical new 8 of hearts on top. Be careful not to shuffle in extra 8s when you have to recycle the played-cards pile.
Good luck. |
|
|
|
|
|
djshady
|
Posted: Fri Jan 16, 2009 6:00 pm Post subject: RE:Isu Help Crazy Eights!!! |
|
|
the teacher gave us some input on how the game should be played... i have gotten all of my classes.. however in my card class.. the variable card :string.. gives no value in the procedure getCard aka returnCard... here is what i have so far.. can u try and help me out THANKS
Turing: | class Card
export setCard, returnSuit, returnValue, returnCard,
pointValue, toString, setSuit, printCard, Selected, getSelected
var value : int := 0
var card : string
var selected : boolean := false
procedure setCard (c : string)
card := c
end setCard
%-------------------------------------------------------------------
procedure Selected
selected := true
end Selected
function getSelected : boolean
result selected
end getSelected
%-------------------------------------------------------------------
function returnSuit : int
var suit : int
if index (card, "d") = 2 then
suit := 1
elsif index (card, "c") = 2 then
suit := 2
elsif index (card, "h") = 2 then
suit := 3
elsif index (card, "s") = 2 then
suit := 4
end if
result suit
end returnSuit
%-------------------------------------------------------------------
function returnValue : int
var cardValue : int
cardValue := (value mod 13) + 1
result cardValue
end returnValue
%-------------------------------------------------------------------
function pointValue : int
var number : int
var cardPoints : int
number := returnValue
if number = 1 then
cardPoints := 11
elsif number >= 11 and number <= 13 then
cardPoints := 10
else
cardPoints := number
end if
result cardPoints
end pointValue
%-------------------------------------------------------------------
function toString : string
var suit : char
var number : int
number := returnValue
suit := chr (returnSuit )
if number = 1 then
result "A " + suit
elsif number = 11 then
result "J " + suit
elsif number = 12 then
result "Q " + suit
elsif number = 13 then
result "K " + suit
else
result intstr (number ) + " " + suit
end if
end toString
function setSuit : int
var newSuit : string (1) := 'x'
var rank : string
var suit : int := 0
var card : string
put
"Choose a suit (d = diamonds, c = clubs, h = hearts, s = spades): "
..
loop
if hasch then
getch (newSuit )
case newSuit of
label 'd' :
card := card (1) + "d"
suit := returnSuit
label 'c' :
card := card (1) + "c"
suit := returnSuit
label 'h' :
card := card (1) + "h"
suit := returnSuit
label 's' :
card := card (1) + "s"
suit := returnSuit
label :
put ""
put "Invalid suit"
suit := 0
end case
end if
exit when suit not= 0
end loop
result suit
end setSuit
function returnCard : string
result card
end returnCard
%------------------------------------------------------------------------------------
procedure printCard (x, y : int, front : boolean)
var cardPic : int
if front then
case card of
label 'ad' :
Pic.ScreenLoad ("ad.bmp", 150, 0, picCopy)
label 'ac' :
Pic.ScreenLoad ("ac.bmp", 150, 0, picCopy)
label 'ah' :
Pic.ScreenLoad ("ah.bmp", 150, 0, picCopy)
label 'as' :
Pic.ScreenLoad ("as.bmp", 150, 0, picCopy)
label '2d' :
Pic.ScreenLoad ("2d.bmp", 150, 0, picCopy)
label '2c' :
Pic.ScreenLoad ("2c.bmp", 150, 0, picCopy)
label '2h' :
Pic.ScreenLoad ("2h.bmp", 150, 0, picCopy)
label '2s' :
Pic.ScreenLoad ("2s.bmp", 150, 0, picCopy)
label '3d' :
Pic.ScreenLoad ("3d.bmp", 150, 0, picCopy)
label '3c' :
Pic.ScreenLoad ("3c.bmp", 150, 0, picCopy)
label '3h' :
Pic.ScreenLoad ("3h.bmp", 150, 0, picCopy)
label '3s' :
Pic.ScreenLoad ("3s.bmp", 150, 0, picCopy)
label '4d' :
Pic.ScreenLoad ("4d.bmp", 150, 0, picCopy)
label '4c' :
Pic.ScreenLoad ("4c.bmp", 150, 0, picCopy)
label '4h' :
Pic.ScreenLoad ("4h.bmp", 150, 0, picCopy)
label '4s' :
Pic.ScreenLoad ("4s.bmp", 150, 0, picCopy)
label '5d' :
Pic.ScreenLoad ("5d.bmp", 150, 0, picCopy)
label '5c' :
Pic.ScreenLoad ("5c.bmp", 150, 0, picCopy)
label '5h' :
Pic.ScreenLoad ("5h.bmp", 150, 0, picCopy)
label '5s' :
Pic.ScreenLoad ("5s.bmp", 150, 0, picCopy)
label '6d' :
Pic.ScreenLoad ("6d.bmp", 150, 0, picCopy)
label '6c' :
Pic.ScreenLoad ("6c.bmp", 150, 0, picCopy)
label '6h' :
Pic.ScreenLoad ("6h.bmp", 150, 0, picCopy)
label '6s' :
Pic.ScreenLoad ("6s.bmp", 150, 0, picCopy)
label '7d' :
Pic.ScreenLoad ("7d.bmp", 150, 0, picCopy)
label '7c' :
Pic.ScreenLoad ("7c.bmp", 150, 0, picCopy)
label '7h' :
Pic.ScreenLoad ("7h.bmp", 150, 0, picCopy)
label '7s' :
Pic.ScreenLoad ("7s.bmp", 150, 0, picCopy)
label '8d' :
Pic.ScreenLoad ("8d.bmp", 150, 0, picCopy)
label '8c' :
Pic.ScreenLoad ("8c.bmp", 150, 0, picCopy)
label '8h' :
Pic.ScreenLoad ("8h.bmp", 150, 0, picCopy)
label '8s' :
Pic.ScreenLoad ("8s.bmp", 150, 0, picCopy)
label '9d' :
Pic.ScreenLoad ("9d.bmp", 150, 0, picCopy)
label '9c' :
Pic.ScreenLoad ("9c.bmp", 150, 0, picCopy)
label '9h' :
Pic.ScreenLoad ("9h.bmp", 150, 0, picCopy)
label '9s' :
Pic.ScreenLoad ("9s.bmp", 150, 0, picCopy)
label 'td' :
Pic.ScreenLoad ("10d.bmp", 150, 0, picCopy)
label 'tc' :
Pic.ScreenLoad ("10c.bmp", 150, 0, picCopy)
label 'th' :
Pic.ScreenLoad ("10h.bmp", 150, 0, picCopy)
label 'ts' :
Pic.ScreenLoad ("10s.bmp", 150, 0, picCopy)
label 'jd' :
Pic.ScreenLoad ("jd.bmp", 150, 0, picCopy)
label 'jc' :
Pic.ScreenLoad ("jc.bmp", 150, 0, picCopy)
label 'jh' :
Pic.ScreenLoad ("jh.bmp", 150, 0, picCopy)
label 'js' :
Pic.ScreenLoad ("js.bmp", 150, 0, picCopy)
label 'qd' :
Pic.ScreenLoad ("qd.bmp", 150, 0, picCopy)
label 'qc' :
Pic.ScreenLoad ("qc.bmp", 150, 0, picCopy)
label 'qh' :
Pic.ScreenLoad ("qh.bmp", 150, 0, picCopy)
label 'qs' :
Pic.ScreenLoad ("qs.bmp", 150, 0, picCopy)
label 'kd' :
Pic.ScreenLoad ("kd.bmp", 150, 0, picCopy)
label 'kc' :
Pic.ScreenLoad ("kc.bmp", 150, 0, picCopy)
label 'kh' :
Pic.ScreenLoad ("kh.bmp", 150, 0, picCopy)
label 'ks' :
Pic.ScreenLoad ("ks.bmp", 150, 0, picCopy)
end case
else
Pic.ScreenLoad ("b.bmp", 150, 0, picCopy)
end if
Pic.Draw (cardPic, x, y, picCopy)
Pic.Free (cardPic )
end printCard
end Card
%-----------------------------------------------------------------
class Deck
import Card
export emptyDeck, shuffleDeck, TopCard, initialize
var cards : array 1 .. 52 of ^Card
var size : int
var topCard : string
var p : int := 1
for i : 1 .. 52
new cards (i )
end for
procedure initialize
cards (1) -> setCard ('ad')
cards (2) -> setCard ('ac')
cards (3) -> setCard ('ah')
cards (4) -> setCard ('as')
cards (5) -> setCard ('2d')
cards (6) -> setCard ('2c')
cards (7) -> setCard ('2h')
cards (8) -> setCard ('2s')
cards (9) -> setCard ('3d')
cards (10) -> setCard ('3c')
cards (11) -> setCard ('3h')
cards (12) -> setCard ('3s')
cards (13) -> setCard ('4d')
cards (14) -> setCard ('4c')
cards (15) -> setCard ('4h')
cards (16) -> setCard ('4s')
cards (17) -> setCard ('5d')
cards (18) -> setCard ('5c')
cards (19) -> setCard ('5h')
cards (20) -> setCard ('5s')
cards (21) -> setCard ('6d')
cards (22) -> setCard ('6c')
cards (23) -> setCard ('6h')
cards (24) -> setCard ('6s')
cards (25) -> setCard ('7d')
cards (26) -> setCard ('7c')
cards (27) -> setCard ('7h')
cards (28) -> setCard ('7s')
cards (29) -> setCard ('8d')
cards (30) -> setCard ('8c')
cards (31) -> setCard ('8h')
cards (32) -> setCard ('8s')
cards (33) -> setCard ('9d')
cards (34) -> setCard ('9c')
cards (35) -> setCard ('9h')
cards (36) -> setCard ('9s')
cards (37) -> setCard ('td')
cards (38) -> setCard ('tc')
cards (39) -> setCard ('th')
cards (40) -> setCard ('ts')
cards (41) -> setCard ('jd')
cards (42) -> setCard ('jc')
cards (43) -> setCard ('jh')
cards (44) -> setCard ('js')
cards (45) -> setCard ('qd')
cards (46) -> setCard ('qc')
cards (47) -> setCard ('qh')
cards (48) -> setCard ('qs')
cards (49) -> setCard ('kd')
cards (50) -> setCard ('kc')
cards (51) -> setCard ('kh')
cards (52) -> setCard ('ks')
size := 52
end initialize
function emptyDeck : boolean
var numOfSelected : int := 0
var emptyD : boolean := false
for i : 1 .. 52
if cards (i ) -> getSelected = true then
numOfSelected := numOfSelected + 1
end if
end for
if numOfSelected = 52 then
emptyD := true
end if
result emptyD
end emptyDeck
procedure shuffleDeck
var a, b : int
var temp : ^Card
initialize
new temp
for i : 1 .. 52
randint (a, 1, 52)
randint (b, 1, 52)
temp -> setCard (cards (a ) -> returnCard )
cards (a ) -> setCard (cards (b ) -> returnCard )
cards (b ) -> setCard (temp -> returnCard )
end for
end shuffleDeck
function TopCard : ^Card
p := p + 1
if cards (p ) -> getSelected = false then
cards (p ) -> Selected
end if
result cards (p )
end TopCard
end Deck
%----------------------------------------------------------------------
class Hand
import Card, Mouse, Deck
export sort, print, setY, setHuman, add, useMouse, whatToPlay, remove,
emptyHand
var hand : array 1 .. 20 of ^Card
var size : int := 0
var x : int
var y : int := 20
var human : boolean := false
for i : 1 .. 20
new hand (i )
end for
procedure sort
var x : ^Card
for n : 1 .. size - 1
for a : 1 .. size
for b : 1 .. size
if hand (a ) -> pointValue > hand (b ) -> pointValue then
x -> setCard (hand (a ) -> returnCard )
hand (a ) -> setCard (hand (b ) -> returnCard )
hand (b ) -> setCard (x -> returnCard )
end if
end for
end for
end for
end sort
procedure add (newCard : ^Card )
var l : int
var n : string := newCard -> returnCard
size := size + 1
for decreasing i : size .. 1
hand (i ) -> setCard (n )
end for
hand (size ) -> setCard (n )
sort
end add
procedure remove (card : ^Card )
for i : 1 .. size
if hand (i ) -> returnCard = card -> returnCard then
hand (i ) := hand (i + 1)
end if
end for
size := size - 1
end remove
function emptyHand () : boolean
if size = 0 then
result true
else
result false
end if
end emptyHand
function whatToPlay (pileCard : ^Card ) : ^Card
var topC : ^Card
var tCd : ^Deck
var count : int := 1
var done : boolean := false
loop
if pileCard -> returnSuit = hand (count ) -> returnSuit then
done := true
result (hand (count ))
elsif pileCard -> pointValue = hand (count ) -> pointValue then
done := true
result (hand (count ))
elsif count > size then
done := true
result pileCard
end if
count := count + 1
exit when done = true
end loop
end whatToPlay
function okayToPlay (pile : ^Card, card : ^Card ) : boolean
if card -> pointValue = pile -> pointValue or card -> returnSuit =
pile -> returnSuit
then
result true
else
result false
end if
end okayToPlay
procedure setY (num : int)
y := num
end setY
procedure print
x := 0
hand (1) -> printCard (x, y, human )
for i : 2 .. size
x := x + 20
hand (i ) -> printCard (x, y, human )
end for
end print
procedure setHuman (h : boolean)
human := h
end setHuman
function useMouse (pile : ^Card ) : ^Card
var buttonnumber, buttonupdown, i : int
var temp : ^Card
var tc : string
loop
if whatToPlay (pile ) = pile then
result pile
else
Mouse.ButtonWait ("down", x, y, buttonnumber,
buttonupdown )
if y > 100 and x < 20 then
i := 1
elsif y > 100 and 20 <= x and x < 40 then
i := 2
end if
if (okayToPlay (pile, hand (i ))) then
temp -> setCard (hand (i ) -> returnCard )
remove (hand (i ))
result temp
else
result pile
end if
end if
end loop
end useMouse
end Hand
%-----------------------------------------------------------------------------------------
class Game
import Deck, Card, Hand
export play1
var player : array 1 .. 4 of ^Hand
var playerName : array 1 .. 4 of string
var deck : ^Deck
var pile : ^Card
new deck
for i : 1 .. 4
new player (i )
end for
player (1) -> setY (20)
player (2) -> setY (100)
player (3) -> setY (180)
player (4) -> setY (260)
player (1) -> setHuman (true)
playerName (1) := "player 1"
playerName (2) := "Bob"
playerName (3) := "Sam"
playerName (4) := "Jen"
new pile
procedure reDraw ()
cls
for i : 1 .. 4
if i = 1 then
player (i ) -> print
else
end if
end for
pile -> printCard (150, 20, true)
end reDraw
procedure deal ()
for i : 1 .. 4
for j : 1 .. 8
player (i ) -> add (deck -> TopCard )
player (i ) -> print
end for
end for
deck -> shuffleDeck
end deal
procedure play1 ()
var playr : int := 1
var card : ^Card
new card
deal
loop
if playr = 1 then
card := player (playr ) -> useMouse (pile )
else
card := player (playr ) -> whatToPlay (pile )
end if
if card = pile then
player (playr ) -> add (deck -> TopCard )
else
player (playr ) -> remove (card )
pile := card
end if
exit when player (playr ) -> emptyHand ()
playr := playr mod 4 + 1
end loop
end play1
end Game
var w : int
var eD : boolean
var C : ^Card
var D : ^Deck
var H : ^Hand
var G : ^Game
new C
new D
new H
new G
w := Window.Open ("position:center, graphics:600;600")
G -> play1 |
Mod Edit: Remember to use syntax tags! Thanks code: | [syntax="turing"]Code Here[/syntax] |
|
|
|
|
|
|
syntax_error
|
Posted: Fri Jan 16, 2009 6:11 pm Post subject: RE:Isu Help Crazy Eights!!! |
|
|
please look up for loops and arrays |
|
|
|
|
|
Saad
|
Posted: Fri Jan 16, 2009 7:33 pm Post subject: Re: RE:Isu Help Crazy Eights!!! |
|
|
@djshady: To find the error, you need to debug the code more thoroughly. I suggest outputting messages that help you find where exactly is that function being called.
To help you along, the main problem is in the following code segment:
Turing: | procedure deal ()
for i : 1 .. 4
for j : 1 .. 8
% The error is here, Hint: what does TopCard return for the deck right now?
player (i) -> add (deck -> TopCard)
player (i) -> print
end for
end for
deck -> shuffleDeck
end deal |
Trace through the code at the line and use the hint and your error should become apparent.
syntax_error @ Fri Jan 16, 2009 6:11 pm wrote: please look up for loops and arrays
@syntax_error: Your reply is completely useless. Have you seen his code? Also you do not even say how using that will help which is the same as not being helpful at all. Please if you want to make a reply make it a more thoughtful reply. |
|
|
|
|
|
djshady
|
Posted: Sat Jan 17, 2009 10:07 pm Post subject: RE:Isu Help Crazy Eights!!! |
|
|
thnkz for ur help guys..
im still stuck.. I set my card
var card: string := ' '
this got rid of the variable has no value.. but now im geting an error in printcard saying that the label 'ks' is out of range :S
Please help me out Thanks
This is due soontyme
i cant fail this shyt |
|
|
|
|
|
Saad
|
Posted: Sat Jan 17, 2009 11:35 pm Post subject: RE:Isu Help Crazy Eights!!! |
|
|
Assuming this was in the cases, this means that the none of the cases were true. Your problem is still in the previously posted code, so consequently you have not initialized the deck and as a result what your adding is empty cards. Initialize the deck first |
|
|
|
|
|
|
|