daviswplc416
2007-10-08 23:10
Decks part 4:

/** cardToString - get printable form of indicated card held by nominated player

@param boolean -- check player's hand?

@param int -- card number to investigate (numbered from 1)

@return String -- printable form of requested card

Obtain String formatted description of particular card held by player/computer

*/

public String cardToString(boolean playersTurn,int cardNumber)

{

int deck;

int card;

trace("cardToString: begins");

if (playersTurn == PLAYERS_TURN)

{

// get player's card's detail

deck=playersCards[cardNumber-1] / (NUM_SUITS*NUM_CARDS);

card=playersCards[cardNumber-1] % (NUM_SUITS*NUM_CARDS);

trace("cardToString: card is " + cards[deck][card] + " (#" + playersCards[cardNumber-1] +

", deck " + deck + ", card " + card +") with a value of " + CARD_VALUES[card%NUM_CARDS]);

}

else

{

// get computer's card's detail

deck=computersCards[cardNumber-1] / (NUM_SUITS*NUM_CARDS);

card=computersCards[cardNumber-1] % (NUM_SUITS*NUM_CARDS);

trace("cardToString: card is " + cards[deck][card] + " (#" + computersCards[cardNumber-1] +

", deck " + deck + ", card " + card +") with a value of " + CARD_VALUES[card%NUM_CARDS]);

}

trace("cardToString: ends");

return cards[deck][card];

}

/** setTracing - used to turn tracing messages on or off

@param boolean -- indicates the required state of messages (true on, false off)

@return none

*/

public void setTracing(boolean traceState)

{

tracing = traceState;

}

/** trace - displays tracing messages

@param String -- the message to be displayed if instance variable tracing is true

@return none

*/

public void trace(String message)

{

if(tracing)

{

System.out.println(message);

}

}

}

daviswplc416
2007-10-08 23:12
/**

Pontoon

@author:

@ID:

@Stage reached:

purpose: KXT101 assignment 2, semester 2, 2007

*/

import java.util.Scanner;

public class Pontoon

{

//final instance variables

final String START = "y";

final String FINISH = "Thanks for playing";

//non-final instance variables

private Decks cards;

private boolean tracing;

private Scanner sc;

private String begin;

/** constructor

@param none

@return none

*/

public Pontoon()

{

sc = new Scanner(System.in);

cards = new Decks();

cards.setTracing(false);

}

/** play -- play a game of Pontoon

@param none

@return none

*/

public void play()

{

trace("PONTOON -- A Game of 21");

expain();

}

/** explain -- give information on the game

@param none

@return none

*/

public void explain()

{

trace("The object of the game is to get as close to 21 as possible or to have 5 cards with a total under 21");

trace("The computer continues to draw cards if under 16");

trace("Would you like to play Pontoon? (y/n)");

begin = sc.next();

if (begin.equals(START) )

{

startPlaying();

}

else{

trace(FINISH);

}

}

public void startPlaying()

{

}

/** setTracing - used to turn tracing messages on or off

@param boolean -- indicates the required state of messages (true on, false off)

@return none

*/

public void setTracing(boolean traceState)

{

tracing=traceState;

}

/** trace - displays tracing messages

@param String -- the message to be displayed if instance variable tracing is true

@return none

*/

public void trace(String message)

{

if(tracing)

{

System.out.println("Pontoon: " + message);

}

}

}

哪位高人能帮忙看看啊。

PS:为什么我在Potoon的public里添加cards = new Decks();编译的时候就会出错啊!

先谢谢啦

daviswplc416
2007-10-08 23:31
[IMG]http://i24.tinypic.com/wb47b8.jpg[/IMG]

猜你喜欢
2Go 上一页 1 2