Current location: Hot Scripts Forums » Programming Languages » Everything Java » Little Help please

Little Help please

Reply
  #1 (permalink)  
Old 05-04-04, 09:26 PM
bmw2213 bmw2213 is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Kirksville, MO
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Little Help please

this is my method to playRound. I get an error because for some reason, the method won't just draw one card from the deck, but rather continually goes until the deck runs out, giving an ArrayIndexOutOfBoundsException. Any ideas on why its looping?

Code:
private void playRound(String playerTurn) {
	Card topCard = playedDeck.getTopCard();
	Card drawnCard;
        Card cardToPlay;
        int newSuit;
	boolean draw = false;
	for (int i = 0; i < numPlayers; i++) {
		if (player[i].getName() == playerTurn){
			draw = player[i].playTurn(topCard);
			if (!draw) {
                            	drawnCard = deck.getCard();
                                player[i].insertCardInHand(drawnCard);
			}
                        else {
                            cardToPlay = player[i].selectCard(topCard);
                            if (cardToPlay.getRank() == 8) {
                                newSuit = player[i].chooseSuit();
                                topCard = new Card(newSuit, 8);
                                System.out.println(topCard.getSuit());
                            }
                            playedDeck.playCard(cardToPlay);
                        }
                        if (player[i].getHand().getNumCards() == 0) {
                            win = true;
                        }
                        else {
                            if (i + 1 < numPlayers) 
                            playerTurn = player[i+1].getName();
                            topCard = playedDeck.getTopCard();
                        }
		}
	}
        
        
}


Code:
public Card getCard() {
// 'Deals' one card from the top of the deck, card is not deleted
//pre: deck is not empty
return deck[top--];
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-08-04, 10:51 PM
Iron_Cross Iron_Cross is offline
Newbie Coder
 
Join Date: May 2004
Location: Texas, USA
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
First, it'd be nice to see the rest of that class, not just the method. Also, could you show the error exactly? That would help too....but I'm pretty sure I know what's happening. I just want to make sure.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:38 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.