Commit a567d846 authored by 9731301's avatar 9731301

Add some changes in whole project and debugging

parent 7732ec50
/**
* Card Class represents A class
*/
import java.util.ArrayList; import java.util.ArrayList;
public abstract class Card { public abstract class Card {
protected String name; protected String name;
protected String color;
private int score; private int score;
public static final String set = "\u001B[0m"; public static final String set = "\u001B[0m";
public static final String green = "\u001B[32m"; public static final String green = "\u001B[32m";
...@@ -13,6 +18,14 @@ public abstract class Card { ...@@ -13,6 +18,14 @@ public abstract class Card {
public Card() { public Card() {
} }
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Card(int score) { public Card(int score) {
this.score = score; this.score = score;
} }
...@@ -30,21 +43,42 @@ public abstract class Card { ...@@ -30,21 +43,42 @@ public abstract class Card {
public abstract void print(); public abstract void print();
public abstract void act(User chosenUser, int numOfChosenCard ,ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard); public abstract User act(User chosenUser, int numOfChosenCard ,ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard);
public boolean isAvailableToPut(int numOfChosenCard, User chosenUser, Card upperCard) { public boolean isAvailableToPut( User chosenUser, Card upperCard) {
if (chosenUser.getUserCards().get(numOfChosenCard) instanceof ColoredCard) {
ColoredCard chosenColoredCard = (ColoredCard) chosenUser.getUserCards().get(numOfChosenCard); if (this.getScore() < 10 && upperCard.getScore() < 10){
if (chosenColoredCard.isAvailableToPutAColoredCard(numOfChosenCard, chosenUser, upperCard)) NumericalCard upper = (NumericalCard)upperCard;
NumericalCard chosen = (NumericalCard)this;
if (color.equals(upper.getColor()) || chosen.getNumber() == upper.getNumber()){
return true; return true;
}
else else
return false; return false;
} else { }
WildCard chosenWildCard = (WildCard) chosenUser.getUserCards().get(numOfChosenCard); else if (this.getScore() < 50 && upperCard.getScore() < 50) {
if (chosenWildCard.isAvailableToPutAWildCard(numOfChosenCard, chosenUser, upperCard)) if ((this instanceof SkipCard && upperCard instanceof SkipCard) ||(this instanceof ReverseCard && upperCard instanceof ReverseCard)){
//you can put a reverse card after a reverse card
//you can put a skip card after a skip card
return true;
}
ColoredCard upper = (ColoredCard) upperCard;
if (this.getColor().equals(upper.getColor()))
return true; return true;
else else
return false; return false;
} else {
for (Card card : chosenUser.getUserCards()) {
if (card instanceof WildCard){
continue;
}
else {//if there is another card to choose you can not choose wild card
if (card.isAvailableToPut( chosenUser , upperCard)) {
return false;
}
}
}
return true;
} }
} }
......
public abstract class ColoredCard extends Card { public abstract class ColoredCard extends Card {
private String color;
/** /**
* create a Colored card that according to subClasses create a special kind of colored cards * create a Colored card that according to subClasses create a special kind of colored cards
...@@ -18,14 +17,6 @@ public abstract class ColoredCard extends Card { ...@@ -18,14 +17,6 @@ public abstract class ColoredCard extends Card {
* *
* @return * @return
*/ */
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
@Override @Override
public String toString() { public String toString() {
...@@ -51,33 +42,4 @@ public abstract class ColoredCard extends Card { ...@@ -51,33 +42,4 @@ public abstract class ColoredCard extends Card {
} }
System.out.println(first + toString() + set); System.out.println(first + toString() + set);
} }
public boolean isAvailableToPutAColoredCard(int numOfChosenCard, User chosenUser, Card upperCard) {
ColoredCard chosen = (ColoredCard) chosenUser.getUserCards().get(numOfChosenCard);
if (upperCard instanceof ColoredCard) {
ColoredCard upper = (ColoredCard) upperCard;
if (chosen instanceof NumericalCard && upper instanceof NumericalCard) {
NumericalCard chosenNum = (NumericalCard) chosen;
NumericalCard upperNum = (NumericalCard) upper;
if (upper.getColor().equals(chosen.getColor()) || upperNum.getNumber() == chosenNum.getNumber()) {
return true;
} else {
return false;
}
} else {
if (chosen.getColor().equals(upper.getColor())) {
return true;
} else {
return false;
}
}
}
else {
WildCard upper = (WildCard) upperCard;
if (upper.getNextColor().equals(chosen.getColor()))
return true;
else
return false;
}
}
} }
...@@ -4,7 +4,8 @@ import java.util.Scanner; ...@@ -4,7 +4,8 @@ import java.util.Scanner;
public class Draw2Card extends MotiveCard { public class Draw2Card extends MotiveCard {
GivingCard givingCard = new GivingCard(); GivingCard givingCard = new GivingCard();
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
int addTwo = 2; private int addTwo = 2;
private int flag = 0;
/** /**
* create a Colored card that according to subClasses create a special kind of colored cards * create a Colored card that according to subClasses create a special kind of colored cards
...@@ -18,8 +19,7 @@ public class Draw2Card extends MotiveCard { ...@@ -18,8 +19,7 @@ public class Draw2Card extends MotiveCard {
} }
@Override @Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users , ArrayList<Card> remainingCards , Card upperCard ) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users , ArrayList<Card> remainingCards , Card upperCard ) {
int flag = 0;
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard); remainingCards.add(upperCard);
...@@ -28,20 +28,23 @@ public class Draw2Card extends MotiveCard { ...@@ -28,20 +28,23 @@ public class Draw2Card extends MotiveCard {
for (Card card : chosenUser.getUserCards()){ for (Card card : chosenUser.getUserCards()){
if (card instanceof Draw2Card){ if (card instanceof Draw2Card){
flag = 1; flag = 1;
break;
} }
} }
if (flag == 0){ if (flag == 0){
givingCard.give_n_Cards(chosenUser , remainingCards, addTwo , upperCard); givingCard.give_n_Cards(chosenUser , remainingCards, addTwo , upperCard);
chosenUser = chosenUser.pass(users,chosenUser); chosenUser = chosenUser.pass(users,chosenUser);
addTwo =2;//we need if another time in game we had this card this method start giving card with 2 cards addTwo =2;//we need if another time in game we had this card this method start giving card with 2 cards
return; flag = 0;
return chosenUser;
} }
else { else {
addTwo += 2;// because when we use recursive function we needs that addTwo not be 2 addTwo += 2;// because when we use recursive function we needs that addTwo not be 2
chosenUser.printCards(); chosenUser.printCards(users);
numOfChosenCard = scanner.nextInt() - 1; numOfChosenCard = scanner.nextInt() - 1;
act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard); act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard);
} }
return chosenUser;
} }
} }
...@@ -19,7 +19,11 @@ public class GivingCard { ...@@ -19,7 +19,11 @@ public class GivingCard {
} }
public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards ){ public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards ){
while (true) {
int randomNum = r.nextInt(remainingCards.size()); int randomNum = r.nextInt(remainingCards.size());
if (!(remainingCards.get(randomNum) instanceof WildCard) && !(remainingCards.get(randomNum) instanceof Draw2Card)) {
return remainingCards.get(randomNum); return remainingCards.get(randomNum);
} }
}
}
} }
...@@ -19,11 +19,13 @@ public class NumericalCard extends ColoredCard { ...@@ -19,11 +19,13 @@ public class NumericalCard extends ColoredCard {
} }
@Override @Override
public void act(User chosenUser,int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
System.out.println(chosenUser.getUserCards().size());
remainingCards.add(upperCard); remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser); chosenUser = chosenUser.pass(users,chosenUser);
return chosenUser;
} }
} }
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class ReverseCard extends MotiveCard { public class ReverseCard extends MotiveCard {
...@@ -14,15 +16,13 @@ public class ReverseCard extends MotiveCard { ...@@ -14,15 +16,13 @@ public class ReverseCard extends MotiveCard {
} }
@Override @Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard); remainingCards.add(upperCard);
ArrayList<User> reverseUsers = new ArrayList<>(); Collections.reverse(users);
for (int i = users.size() ; i > -1 ; i++){ System.out.println(" توتابع"+ users.get(0).getName() + users.get(1).getName() + users.get(2).getName());
reverseUsers.add(users.get(i)); chosenUser = chosenUser.pass(users , chosenUser);
} return chosenUser;
users = reverseUsers;
chosenUser = users.get(users.indexOf(chosenUser) - 1);
} }
} }
...@@ -15,10 +15,12 @@ public class SkipCard extends MotiveCard { ...@@ -15,10 +15,12 @@ public class SkipCard extends MotiveCard {
} }
@Override @Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard); remainingCards.add(upperCard);
chosenUser = users.get(users.indexOf(chosenUser) + 2); chosenUser = chosenUser.pass(users , chosenUser);
chosenUser = chosenUser.pass(users , chosenUser);
return chosenUser;
} }
} }
import java.util.ArrayList; import java.util.*;
import java.util.Random;
import java.util.Scanner;
public class Uno { public class Uno {
public static Card upperCard;
public static void main(String [] args){ public static void main(String [] args){
int userChosenCardNum ; int userChosenCardNum ;
int numOfPlayers = 0; int numOfPlayers = 0;
...@@ -72,7 +71,7 @@ public class Uno { ...@@ -72,7 +71,7 @@ public class Uno {
while (numOfPlayers == 0) {//set num of players and their names at first while (numOfPlayers == 0) {//set num of players and their names at first
System.out.println("plz enter number of users"); System.out.println("plz enter number of users");
numOfPlayers = scanner.nextInt(); numOfPlayers = scanner.nextInt();
if (!(numOfPlayers >=3 && numOfPlayers <= 5)) { if (!(numOfPlayers >=2 && numOfPlayers <= 5)) {
numOfPlayers = 0; numOfPlayers = 0;
continue; continue;
} }
...@@ -81,7 +80,7 @@ public class Uno { ...@@ -81,7 +80,7 @@ public class Uno {
System.out.println("plz enter your name"); System.out.println("plz enter your name");
String name = scanner.next(); String name = scanner.next();
User user = new User(name); User user = new User(name);
// givingCard.give_n_Cards(user , remainingCards , 7); givingCard.give_n_Cards(user , remainingCards ,7 , upperCard);
users.add(user); users.add(user);
} }
chosenUser = users.get(0); chosenUser = users.get(0);
...@@ -90,31 +89,47 @@ public class Uno { ...@@ -90,31 +89,47 @@ public class Uno {
while (true){ while (true){
for (int i = 0; i < numOfPlayers ; i++){
System.out.println(users.get(i).getName() + " " + users.get(i).getScore());
if (users.get(i).getUserCards().size() == 0){
for (int j = 0 ; j < numOfPlayers ; j++){
System.out.println(users.get(j).getName() + " " + users.get(j).getScore());
}
System.out.println(users.get(i).getName() + " won\n THE END");
return;
}
}
int flag = 0;
System.out.println("UPPER CARD IS"); System.out.println("UPPER CARD IS");
upperCard.print(); upperCard.print();
System.out.println("TURN IS FOR "+chosenUser.getName() +"YOUR CARDS ARE"); chosenUser.printCards(users);
chosenUser.printCards(); for (Card card : chosenUser.getUserCards()){
userChosenCardNum = scanner.nextInt() -1; if (card.isAvailableToPut( chosenUser , upperCard)) {
if (userChosenCardNum == chosenUser.getUserCards().size()){//if user chose draw card flag = 1;
break;
}
}
if (flag == 0){//if user chose draw card
givingCard.give_n_Cards(chosenUser , remainingCards , 1 ,upperCard); givingCard.give_n_Cards(chosenUser , remainingCards , 1 ,upperCard);
if (chosenUser.getUserCards().get(chosenUser.getUserCards().size() - 1).isAvailableToPut(userChosenCardNum, chosenUser ,upperCard)){ if (chosenUser.getUserCards().get(chosenUser.getUserCards().size() - 1).isAvailableToPut( chosenUser , upperCard)){
continue; continue;// if
} }
else { else {
System.out.println("pass"); chosenUser.printCards(users);
} System.out.println("you can not choose \n pass");
chosenUser = chosenUser.pass(users , chosenUser); chosenUser = chosenUser.pass(users , chosenUser);
continue; continue;
} }
}
else { else {
if (chosenUser.getUserCards().get(userChosenCardNum).isAvailableToPut(userChosenCardNum,chosenUser,upperCard)){ userChosenCardNum = scanner.nextInt() -1;
// chosenUser.getUserCards().get(userChosenCardNum).act(chosenUser , users ,remainingCards ,upperCard); if (chosenUser.getUserCards().get(userChosenCardNum).isAvailableToPut(chosenUser,upperCard)){
chosenUser = chosenUser.getUserCards().get(userChosenCardNum).act(chosenUser , userChosenCardNum , users ,remainingCards ,upperCard);
upperCard = remainingCards.get(remainingCards.size() - 1);
}
else {
System.out.println("you can not choose this card");
} }
chosenUser.removeCard(upperCard);
remainingCards.add(upperCard);
////// chosenUser = chosenUser.pass(users,chosenUser);
} }
} }
} }
......
...@@ -47,6 +47,7 @@ public class User { ...@@ -47,6 +47,7 @@ public class User {
* @return score field * @return score field
*/ */
public int getScore() { public int getScore() {
score = 0;
for (Card card : userCards ){ for (Card card : userCards ){
score += card.getScore(); score += card.getScore();
} }
...@@ -54,6 +55,10 @@ public class User { ...@@ -54,6 +55,10 @@ public class User {
} }
public User pass(ArrayList<User> users , User chosenUser){ public User pass(ArrayList<User> users , User chosenUser){
if (users.indexOf(chosenUser) + 1 == users.size()){
return users.get(0);
}
else
return users.get(users.indexOf(chosenUser) + 1); return users.get(users.indexOf(chosenUser) + 1);
} }
...@@ -61,7 +66,11 @@ public class User { ...@@ -61,7 +66,11 @@ public class User {
return userCards; return userCards;
} }
public void printCards(){ public void printCards(ArrayList<User> users){
for (int i = 0 ; i < users.size() ; i++){
System.out.println(users.get(i).getName()+ "=====>>"+users.get(i).getUserCards().size());
}
System.out.println("TURN IS FOR "+ name +" YOUR CARDS ARE");
System.out.println("enter the number of your card for example : 3"); System.out.println("enter the number of your card for example : 3");
int counter = 1; int counter = 1;
for (Card card : userCards){ for (Card card : userCards){
......
import java.util.ArrayList; import java.util.ArrayList;
public class Wild4 extends WildCard { public class Wild4 extends WildCard {
int addFour = 4; private int addFour = 4;
private int flag = 0;
public Wild4(int score) { public Wild4(int score) {
super(score); super(score);
name = "| +4 |\n"; name = "| +4 |\n";
} }
@Override @Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
int flag = 0;
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard); remainingCards.add(upperCard);
...@@ -21,24 +21,22 @@ public class Wild4 extends WildCard { ...@@ -21,24 +21,22 @@ public class Wild4 extends WildCard {
} }
} }
if (flag == 0){ if (flag == 0){
System.out.println(users.get(users.indexOf(chosenUser)-1).getName()+" choose a color");
chooseColor();
givingCard.give_n_Cards(chosenUser , remainingCards, addFour , upperCard); givingCard.give_n_Cards(chosenUser , remainingCards, addFour , upperCard);
chosenUser = chosenUser.pass(users,chosenUser); chosenUser = chosenUser.pass(users,chosenUser);
putChosenColor(chosenUser, numOfChosenCard, users, remainingCards, upperCard);//we need this kind of putting card just for wild cards
addFour =4;//we need if another time in game we had this card this method start giving card with 2 cards addFour =4;//we need if another time in game we had this card this method start giving card with 2 cards
return; flag = 0 ;
return chosenUser;
} }
else { else {
addFour += 4;// because when we use recursive function we needs that addTwo not be 2 addFour += 4;// because when we use recursive function we needs that addTwo not be 2
chosenUser.printCards(); chosenUser.printCards(users);
numOfChosenCard = scanner.nextInt() - 1; numOfChosenCard = scanner.nextInt() - 1;
act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard); act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard);
} }
return chosenUser;
putChosenColor(chosenUser, numOfChosenCard, users, remainingCards, upperCard);//we need this kind of putting card just for wild cards
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
} }
} }
/**
* this Class represents wild cards
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
public abstract class WildCard extends Card { public abstract class WildCard extends Card {
private String nextColor;
/**
*
*/
String nextColor;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
GivingCard givingCard = new GivingCard(); GivingCard givingCard = new GivingCard();
public WildCard(int score) { public WildCard(int score) {
super(score); super(score);
} }
public void chooseColor() { public void chooseColor() {
int num = 0; int num = 0;
while (num < 1 && num > 4) { do {
System.out.println("plz choose a color (just choose the number)\n1:blue 2:red 3:yellow 4:green"); System.out.println("plz choose a color (just choose the number)\n1:blue 2:red 3:yellow 4:green");
num = scanner.nextInt(); num = scanner.nextInt();
} }while (num < 1 && num > 4);
switch (num) { switch (num) {
case 1: { case 1: {
System.out.println("next:" + blue + "blue" + set); System.out.println("next:" + blue + "blue" + set);
...@@ -44,45 +45,39 @@ public abstract class WildCard extends Card { ...@@ -44,45 +45,39 @@ public abstract class WildCard extends Card {
} }
} }
public void putChosenColor(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard){ public User putChosenColor(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
while (true) { while (true) {
int flag = 0; int flag = 0;
System.out.println("next card color should be" + nextColor); System.out.println("next card color should be " + nextColor);
System.out.println("TURN IS FOR " + chosenUser.getName() + "YOUR CARDS ARE"); chosenUser.printCards(users);
chosenUser.printCards(); for (Card c : chosenUser.getUserCards()){
numOfChosenCard = scanner.nextInt() - 1; if ( c.color.equals(nextColor)){
for (Card card : chosenUser.getUserCards()){ flag = 1;
if (card.isAvailableToPut(numOfChosenCard ,chosenUser,upperCard)){ break;
flag = 1;// there is another card to put
} }
} }
if (flag == 0) {//if there is not any card to put user should chose draw card if (flag == 0){
givingCard.give_n_Cards(chosenUser, remainingCards, 1, upperCard); System.out.println("there is not ant choice for "+ chosenUser.getName()+"\nPASS");
if (chosenUser.getUserCards().get(chosenUser.getUserCards().size() - 1).isAvailableToPut(numOfChosenCard, chosenUser, upperCard)) { chosenUser = chosenUser.pass(users , chosenUser );
continue;
} else {
System.out.println("pass");
chosenUser = chosenUser.pass(users, chosenUser);
continue; continue;
} }
} else { numOfChosenCard = scanner.nextInt() - 1;
if (chosenUser.getUserCards().get(numOfChosenCard) instanceof WildCard) { if (chosenUser.getUserCards().get(numOfChosenCard) instanceof ColoredCard){
System.out.println("you can not choose it");
continue;
} else {
ColoredCard coloredCard = (ColoredCard) chosenUser.getUserCards().get(numOfChosenCard); ColoredCard coloredCard = (ColoredCard) chosenUser.getUserCards().get(numOfChosenCard);
if (coloredCard.getColor().equals(nextColor)) { if (coloredCard.getColor().equals(nextColor)) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard); chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard); remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users, chosenUser); chosenUser = chosenUser.pass(users, chosenUser);
return; return chosenUser;
} else { } else {
System.out.println("you can not choose it"); System.out.println("you can not choose it");
continue; continue;
} }
} }
else {// you can not put a wild card after a wild card
System.out.println("you can not choose it");
continue;
} }
} }
} }
...@@ -91,9 +86,6 @@ public abstract class WildCard extends Card { ...@@ -91,9 +86,6 @@ public abstract class WildCard extends Card {
this.nextColor = nextColor; this.nextColor = nextColor;
} }
public String getNextColor() {
return nextColor;
}
@Override @Override
public String toString() { public String toString() {
...@@ -110,14 +102,4 @@ public abstract class WildCard extends Card { ...@@ -110,14 +102,4 @@ public abstract class WildCard extends Card {
System.out.println(toString()); System.out.println(toString());
} }
public boolean isAvailableToPutAWildCard(int numOfChosenCard, User chosenUser, Card upperCard) {
if ( chosenUser.getUserCards().size() == 1) // you can not put a wild card when the wild card is the last card
return false;
for (Card card : chosenUser.getUserCards()) {
if (card.isAvailableToPut(numOfChosenCard, chosenUser, upperCard) && !card.equals(chosenUser.getUserCards().get(numOfChosenCard))) {//if there is another card to choose you can not choose wild card
return false;
}
}
return true;
}
} }
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
public class WildColor extends WildCard { public class WildColor extends WildCard {
Scanner scanner = new Scanner(System.in);
public WildColor(int score) { public WildColor(int score) {
super(score); super(score);
name = "| setColor |\n"; name = "| setColor |\n";
} }
@Override @Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) { public User act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard); upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard);
upperCard.print(); upperCard.print();
chooseColor(); chooseColor();
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser); chosenUser = chosenUser.pass(users,chosenUser);
putChosenColor(chosenUser, numOfChosenCard, users, remainingCards, upperCard);//we need this kind of putting card just for wild cards chosenUser = putChosenColor(chosenUser, numOfChosenCard, users, remainingCards, upperCard);//we need this kind of putting card just for wild cards
return chosenUser;
} }
} }
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