Hallo again friends,
I am almost done with the basics of a new board game,written for my little daughter.
Where I am stuck:
The scenario is that every player has three Cards from the beginning.
Every round,if he still has his 3 cards,he gets no more.
If he has less than three,then he gets the number he needs to have 3.
So I have class Player,who has an array of 3 Cards.
I also use a class Deck,with an array of 20 Cards.
At the beginning the player gets 3 Cards from the Deck and these array places are set to null.
So I am writing a method that when a round ends,give the Player the Cards he needs:
Instead of returning the next Card,it returns the next to the one it should, 4 instead of 3,6 instead of 5 etc.
Is there something wrong with my code?
Thanks.
I am almost done with the basics of a new board game,written for my little daughter.
Where I am stuck:
The scenario is that every player has three Cards from the beginning.
Every round,if he still has his 3 cards,he gets no more.
If he has less than three,then he gets the number he needs to have 3.
So I have class Player,who has an array of 3 Cards.
I also use a class Deck,with an array of 20 Cards.
At the beginning the player gets 3 Cards from the Deck and these array places are set to null.
So I am writing a method that when a round ends,give the Player the Cards he needs:
for(int i=0;i<3;i++){
if (p1.getCard(i)==null){ //p1 Player
for(int j=0;j<20;j++){
if(deck1.getCard(j)==null) {j++;} //deck1 Deck
else
{
System.out.println("I returned from deck card "+ j); //Trying to trap the error
p1.setCard(deck1.getCard(j), i); //method to set the Card drawn to the specific place
deck1.set_A_Card_null(j); //method to set the drawn Deck Card to null
break;}
}
}
}
Instead of returning the next Card,it returns the next to the one it should, 4 instead of 3,6 instead of 5 etc.
Is there something wrong with my code?
Thanks.