Commit 7732ec50 authored by 9731301's avatar 9731301

change act and isAvailableToPut methods in some subClasses

parent b9897eb4
......@@ -62,6 +62,7 @@
<workItem from="1586800273922" duration="8352000" />
<workItem from="1586853542539" duration="15929000" />
<workItem from="1586930969911" duration="22987000" />
<workItem from="1587047428683" duration="14253000" />
</task>
<servers />
</component>
......@@ -69,10 +70,10 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="522" y="245" width="665" height="579" key="#com.intellij.ide.util.MemberChooser" timestamp="1586954939488">
<state x="522" y="245" width="665" height="579" key="#com.intellij.ide.util.MemberChooser" timestamp="1587047531267">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="522" y="245" width="665" height="579" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1586954939488" />
<state x="522" y="245" width="665" height="579" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1587047531267" />
<state width="1493" height="261" key="GridCell.Tab.0.bottom" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -105,10 +106,10 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="261" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1586930975674">
<state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1587047466355">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="107" y="217" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586930975674" />
<state x="107" y="217" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1587047466355" />
<state x="425" y="187" key="run.anything.popup" timestamp="1586862725471">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
......@@ -18,37 +18,30 @@ public class Draw2Card extends MotiveCard {
}
@Override
public void act(User chosenUser, ArrayList<User> users , ArrayList<Card> remainingCards , Card upperCard ) {
int numChoice;
chosenUser = users.get(users.indexOf(chosenUser) + 1);
chosenUser.printCards();
numChoice = scanner.nextInt() - 1;
if (numChoice == chosenUser.getUserCards().size() - 1){
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users , ArrayList<Card> remainingCards , Card upperCard ) {
int flag = 0;
upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
for (Card card : chosenUser.getUserCards()){
if (card instanceof Draw2Card){
flag = 1;
}
}
if (flag == 0){
givingCard.give_n_Cards(chosenUser , remainingCards, addTwo , upperCard);
chosenUser = users.get(users.indexOf(chosenUser) + 1);
System.out.println("you draw "+addTwo+" cards");
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
return;
}
else if (isAvailableToPut(numChoice , chosenUser)){
upperCard = chosenUser.getUserCards().get(numChoice);
chosenUser.getUserCards().remove(chosenUser.getUserCards().get(numChoice));
remainingCards.add(chosenUser.getUserCards().get(numChoice));
addTwo += 2;// because when we use recursive function we needs that addTwo not be 2
act(chosenUser , users , remainingCards , upperCard);
}
else {
}
}
@Override
public boolean isAvailableToPut(int numOfChosenCard , User chosenUser ) {
if (chosenUser.getUserCards().get(numOfChosenCard) instanceof Draw2Card){
return true;
addTwo += 2;// because when we use recursive function we needs that addTwo not be 2
chosenUser.printCards();
numOfChosenCard = scanner.nextInt() - 1;
act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard);
}
else return false;
}
}
......@@ -15,6 +15,7 @@ public class GivingCard {
remainingCards.remove(randomNum);
cardNam++;
}
System.out.println(chosenUser.getName() + " draw " + n +" cards");
}
public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards ){
......
......@@ -81,7 +81,7 @@ public class Uno {
System.out.println("plz enter your name");
String name = scanner.next();
User user = new User(name);
givingCard.give_n_Cards(user , remainingCards , 7);
// givingCard.give_n_Cards(user , remainingCards , 7);
users.add(user);
}
chosenUser = users.get(0);
......@@ -108,7 +108,7 @@ public class Uno {
}
else {
if (chosenUser.getUserCards().get(userChosenCardNum).isAvailableToPut(userChosenCardNum,chosenUser,upperCard)){
chosenUser.getUserCards().get(userChosenCardNum).act(chosenUser , users ,remainingCards ,upperCard);
// chosenUser.getUserCards().get(userChosenCardNum).act(chosenUser , users ,remainingCards ,upperCard);
}
......
......@@ -69,7 +69,6 @@ public class User {
card.print();
counter++;
}
System.out.println(counter+"\n+drawCard");
}
@Override
public boolean equals(Object o) {
......
import java.util.ArrayList;
public class Wild4 extends WildCard {
GivingCard givingCard = new GivingCard();
int addFour = 4;
public Wild4(int score) {
super(score);
name = "| +4 |\n";
......@@ -9,13 +9,36 @@ public class Wild4 extends WildCard {
@Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
System.out.println("is it a bluff؟");
int flag = 0;
upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
for (Card card : chosenUser.getUserCards()){
if (card instanceof Wild4){
flag = 1;
}
}
if (flag == 0){
givingCard.give_n_Cards(chosenUser , remainingCards, addFour , upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
addFour =4;//we need if another time in game we had this card this method start giving card with 2 cards
return;
}
else {
addFour += 4;// because when we use recursive function we needs that addTwo not be 2
chosenUser.printCards();
numOfChosenCard = scanner.nextInt() - 1;
act(chosenUser ,numOfChosenCard , users , remainingCards , upperCard);
}
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);
//if (.equals("yes"))
//User nextUser = new User()
givingCard.give_n_Cards(chosenUser , cards , 4);
givingCard.give_n_Cards(chosenUser , cards , 6);
givingCard.give_n_Cards(chosenUser , cards , 4);
}
}
import java.util.ArrayList;
import java.util.Scanner;
public abstract class WildCard extends Card {
/**
*
*/
String nextColor;
Scanner scanner = new Scanner(System.in);
GivingCard givingCard = new GivingCard();
public WildCard(int score) {
super(score);
}
......@@ -39,6 +44,49 @@ public abstract class WildCard extends Card {
}
}
public void putChosenColor(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard){
while (true) {
int flag = 0;
System.out.println("next card color should be" + nextColor);
System.out.println("TURN IS FOR " + chosenUser.getName() + "YOUR CARDS ARE");
chosenUser.printCards();
numOfChosenCard = scanner.nextInt() - 1;
for (Card card : chosenUser.getUserCards()){
if (card.isAvailableToPut(numOfChosenCard ,chosenUser,upperCard)){
flag = 1;// there is another card to put
}
}
if (flag == 0) {//if there is not any card to put user should chose draw card
givingCard.give_n_Cards(chosenUser, remainingCards, 1, upperCard);
if (chosenUser.getUserCards().get(chosenUser.getUserCards().size() - 1).isAvailableToPut(numOfChosenCard, chosenUser, upperCard)) {
continue;
} else {
System.out.println("pass");
chosenUser = chosenUser.pass(users, chosenUser);
continue;
}
} else {
if (chosenUser.getUserCards().get(numOfChosenCard) instanceof WildCard) {
System.out.println("you can not choose it");
continue;
} else {
ColoredCard coloredCard = (ColoredCard) chosenUser.getUserCards().get(numOfChosenCard);
if (coloredCard.getColor().equals(nextColor)) {
upperCard = chosenUser.getUserCards().get(numOfChosenCard);
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users, chosenUser);
return;
} else {
System.out.println("you can not choose it");
continue;
}
}
}
}
}
public void setNextColor(String nextColor) {
this.nextColor = nextColor;
}
......@@ -62,14 +110,14 @@ public abstract class WildCard extends Card {
System.out.println(toString());
}
public boolean isAvailableToPutAWildCard(int numOfChosenCard, User chosenUser, Card upperCard) {//if there is another card to choose you can not choose wild card
if (upperCard instanceof WildCard) // you can not put a wild card if upper card is wild
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 (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 false;
return true;
}
}
......@@ -3,7 +3,6 @@ import java.util.Scanner;
public class WildColor extends WildCard {
Scanner scanner = new Scanner(System.in);
String color ;
public WildColor(int score) {
super(score);
name = "| setColor |\n";
......@@ -11,16 +10,12 @@ public class WildColor extends WildCard {
@Override
public void act(User chosenUser, int numOfChosenCard, ArrayList<User> users, ArrayList<Card> remainingCards, Card upperCard) {
chooseColor();
upperCard = chosenUser.getUserCards().get(numOfChosenCard);
upperCard.print();
chooseColor();
chosenUser.getUserCards().remove(numOfChosenCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
putChosenColor(chosenUser, numOfChosenCard, users, remainingCards, upperCard);//we need this kind of putting card just for wild cards
}
public void setColor(String color) {
this.color = color;
}
}
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