Commit ed2b30de authored by amir's avatar amir

Another error :((

parent 640d7eb1
......@@ -9,7 +9,7 @@ public class Comp extends Player {
@Override
public Card chooseCardToThrow(ArrayList<Card> cards, Card card) {
Card c = null;
if (possibleCards.size() > 0) {
if ((getCounter() == 0 && possibleCards.size() > 0) || (getCounter() > 0 && possibleCards.size() > 1)) {
int number = r.nextInt(getPossibleCards().size());
c = possibleCards.get(number);
possibleCards = null;
......@@ -51,4 +51,25 @@ public class Comp extends Player {
}
return s;
}
@Override
public Card chooseColorToThrow(ArrayList<Card> cards, String Color) {
Card c = null;
if ((getCounter() == 0 && possibleCards.size() > 0) || (getCounter() > 0 && possibleCards.size() > 1)) {
int number = r.nextInt(getPossibleCards().size());
c = possibleCards.get(number);
possibleCards = null;
getPlayerCards().remove(c);
}
else {
c = randomPunishmentCard(cards);
getPlayerCards().add(c);
if (c instanceof Colored) {
if (!c.cardColor.equals(Color)) {
c = null;
}
}
}
return c;
}
}
......@@ -5,30 +5,34 @@ import java.util.Scanner;
public class Human extends Player {
Scanner scanner = new Scanner(System.in);
int counter = 0;
@Override
public Card chooseCardToThrow(ArrayList<Card> cards, Card c) {
Card card = null;
if (possibleCards.size() > 0) {
if (((getCounter() == 0 && possibleCards.size() > 0) || (getCounter() > 0 && possibleCards.size() > 1))) {
System.out.println("Enter number of the card you wanna throw it!");
int number = scanner.nextInt();
if (number > 0 && number <= getPlayerCards().size() &&
possibleCards.contains(getPlayerCards().get(number - 1))) {
//possibleCards = null;
System.out.println("kire khar!");
card = getPlayerCards().get(number - 1);
getPlayerCards().remove(number - 1);
return card;
} else {
while (number <= 0 || number > getPlayerCards().size() ||
!possibleCards.contains(getPlayerCards().get(number - 1))) {
System.out.println("Invalid input");
chooseCardToThrow(cards, c);
System.out.println("Enter number of the card you wanna throw it!");
number = scanner.nextInt();
}
System.out.println("gaav!");
}
card = getPlayerCards().get(number - 1);
getPlayerCards().remove(number - 1);
return card;
} else {
card = randomPunishmentCard(cards);
System.out.println(card.toString());
getPlayerCards().add(card);
cards.remove(card);
if (card instanceof Colored) {
if (c instanceof Colored) {
if (!((Colored) c).checkEquality((Colored) card))
......@@ -48,4 +52,42 @@ public class Human extends Player {
}
return s;
}
@Override
public Card chooseColorToThrow(ArrayList<Card> cards, String Color) {
Card card = null;
if ((getCounter() == 0 && possibleCards.size() > 0) || (getCounter() > 0 && possibleCards.size() > 1)) {
System.out.println("Enter number of the card you wanna throw it!");
int number = scanner.nextInt();
if (number > 0 && number <= getPlayerCards().size() &&
possibleCards.contains(getPlayerCards().get(number - 1))) {
//possibleCards = null;
System.out.println("kire khar!");
card = getPlayerCards().get(number - 1);
getPlayerCards().remove(number - 1);
return card;
} else {
while (number <= 0 || number > getPlayerCards().size() ||
!possibleCards.contains(getPlayerCards().get(number - 1))) {
System.out.println("Invalid input");
System.out.println("Enter number of the card you wanna throw it!");
number = scanner.nextInt();
}
System.out.println("gaav!");
card = getPlayerCards().get(number - 1);
cards.remove(card);
getPlayerCards().remove(number - 1);
return card;
}
} else {
card = randomPunishmentCard(cards);
getPlayerCards().add(card);
if (card instanceof Colored) {
if (!card.cardColor.equals(Color)) {
card = null;
}
}
}
return card;
}
}
......@@ -111,7 +111,7 @@ public class Main {
System.out.println("Player" + (nextPlayerNumber + 1) + " starts the game");
int move = 1;
Player p = null;
int turns = nextPlayerNumber; int c = 0; String nextColor = null;
int turns = nextPlayerNumber; int c = 0; String nextColor = null; Card card = null;
// starts a round
while (c < 9) {
turns %= 4;
......@@ -136,17 +136,23 @@ public class Main {
System.out.println();
players.get(turns).printAllCards(turns + 1);
System.out.println();
Card card = players.get(turns).chooseCardToThrow(cards, nextCard);
if (nextCard != null)
card = players.get(turns).chooseCardToThrow(cards, nextCard);
else
card = players.get(turns).chooseColorToThrow(cards, nextColor);
if (card != null) {
System.out.println(card.toString());
nextColor = players.get(turns).chooseColorIfBlack(card);
if (nextColor == null)
nextCard = card;
}
if (nextCard != null)
System.out.println(nextCard.toString());
else
System.out.println(nextColor);
turns += move;
}
// sort players by each player's point (Acsending sort)
// sort players by each player's point (Ascending sort)
/*Iterator<Player> players1 = players.iterator(); int min = 350;
while (players1.hasNext()){
p = players1.next();
......
......@@ -37,6 +37,10 @@ public class Player {
}
}
public int getCounter() {
return counter;
}
public ArrayList<Card> getPossibleCards() {
return possibleCards;
}
......@@ -51,7 +55,9 @@ public class Player {
public void checkAllCards(Card card){
boolean isColored = false;
if (possibleCards != null){
if (possibleCards == null)
possibleCards = new ArrayList<>();
if (possibleCards.size() > 1){
for (int i = 1; i < possibleCards.size(); i++){
possibleCards.remove(i);
i--;
......@@ -86,10 +92,10 @@ public class Player {
public void printAllPossibleCards(int playerNumber){
System.out.println("Player" + playerNumber + ": (Possible cards)");
Iterator<Card> cardIterator = possibleCards.iterator();
if (counter != 0){
if (counter != 0) {
cardIterator.next();
}
while (cardIterator.hasNext()){
while (cardIterator.hasNext()) {
Card c = cardIterator.next();
System.out.println(c.toString());
}
......@@ -131,7 +137,9 @@ public class Player {
" }";
}
public void checkColors(String color){
if (possibleCards != null){
if (possibleCards == null)
possibleCards = new ArrayList<>();
if (possibleCards.size() > 1){
for (int i = 1; i < possibleCards.size(); i++){
possibleCards.remove(i);
i--;
......@@ -146,4 +154,8 @@ public class Player {
}
}
public Card chooseColorToThrow(ArrayList<Card> cards, String Color){
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment