Commit 640d7eb1 authored by amir's avatar amir

shit!

parent 875d98dd
......@@ -14,6 +14,7 @@ public class Colored extends Card {
return false;
}
@Override
public String toString() {
return "Colored{" +
......
package com.company;
import java.util.ArrayList;
import java.util.Random;
public class Comp extends Player {
Random r = new Random();
@Override
public Card chooseCardToThrow() {
public Card chooseCardToThrow(ArrayList<Card> cards, Card card) {
Card c = null;
if (possibleCards.size() > 0) {
int number = r.nextInt(getPossibleCards().size());
......@@ -14,6 +15,40 @@ public class Comp extends Player {
possibleCards = null;
getPlayerCards().remove(c);
}
else {
c = randomPunishmentCard(cards);
getPlayerCards().add(c);
if (c instanceof Colored) {
if (card instanceof Colored) {
if (!((Colored) c).checkEquality((Colored) card))
c = null;
}
else
c = null;
}
}
return c;
}
public String chooseColorIfBlack(Card card){
String s = null;
if (card instanceof Black){
int color = r.nextInt(4) + 1;
switch (color){
case 1:
s = "red";
break;
case 2:
s = "green";
break;
case 3:
s = "yellow";
break;
case 4:
s = "blue";
break;
}
}
return s;
}
}
......@@ -11,7 +11,7 @@ public class Draw extends Movemention {
public boolean checkEquality(Colored coloredToCompare) {
if (super.checkEquality(coloredToCompare))
return true;
if (!super.checkEquality(coloredToCompare) && coloredToCompare instanceof Draw)
if (coloredToCompare instanceof Draw)
return true;
return false;
}
......
package com.company;
import java.util.ArrayList;
import java.util.Scanner;
public class Human extends Player {
Scanner scanner = new Scanner(System.in);
@Override
public Card chooseCardToThrow() {
public Card chooseCardToThrow(ArrayList<Card> cards, Card c) {
Card card = null;
if (possibleCards.size() > 0) {
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;
//possibleCards = null;
System.out.println("kire khar!");
card = getPlayerCards().get(number - 1);
getPlayerCards().remove(number - 1);
return card;
} else {
while (true){
while (number <= 0 || number > getPlayerCards().size() ||
!possibleCards.contains(getPlayerCards().get(number - 1))) {
System.out.println("Invalid input");
chooseCardToThrow();
chooseCardToThrow(cards, c);
}
}
} else {
card = randomPunishmentCard(cards);
getPlayerCards().add(card);
if (card instanceof Colored) {
if (c instanceof Colored) {
if (!((Colored) c).checkEquality((Colored) card))
card = null;
} else
card = null;
}
}
return card;
}
public String chooseColorIfBlack(Card card){
String s = null;
if (card instanceof Black){
System.out.println("Choose a color: red, green, yellow, blue");
s = scanner.next();
}
return s;
}
}
......@@ -103,15 +103,17 @@ public class Main {
nextCardNumber = r.nextInt(cards.size());
}
}
System.out.println(cards.get(nextCardNumber).toString());
Card nextCard = cards.get(nextCardNumber);
System.out.println(nextCard.toString());
System.out.println();
cards.remove(nextCardNumber);
int nextPlayerNumber = r.nextInt(4);
System.out.println("Player" + (nextPlayerNumber + 1) + " starts the game");
int move = 1;
Player p = null;
int turns = nextPlayerNumber; int c = 0;
int turns = nextPlayerNumber; int c = 0; String nextColor = null;
// starts a round
while (c < 5) {
while (c < 9) {
turns %= 4;
c++;
Iterator<Player> playerIterator = players.iterator();
......@@ -126,8 +128,22 @@ public class Main {
System.out.println("Clockwise");
else
System.out.println("CounterClockwise");
players.get(turns).checkAllCards(cards.get(nextCardNumber));
if (nextColor == null)
players.get(turns).checkAllCards(nextCard);
else
players.get(turns).checkColors(nextColor);
players.get(turns).printAllPossibleCards(turns + 1);
System.out.println();
players.get(turns).printAllCards(turns + 1);
System.out.println();
Card card = players.get(turns).chooseCardToThrow(cards, nextCard);
if (card != null) {
System.out.println(card.toString());
nextColor = players.get(turns).chooseColorIfBlack(card);
if (nextColor == null)
nextCard = card;
}
System.out.println(nextCard.toString());
turns += move;
}
// sort players by each player's point (Acsending sort)
......
......@@ -5,6 +5,7 @@ import com.sun.javafx.scene.control.skin.VirtualFlow;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
public class Player {
// List of player's cards
......@@ -12,7 +13,8 @@ public class Player {
// point of the player
private int playerPoint;
protected ArrayList<Card> possibleCards;
protected ArrayList<Card> possibleCards = new ArrayList<>();
private int counter = 0;
/**
* returns the list of player's cards
......@@ -48,12 +50,15 @@ public class Player {
}
public void checkAllCards(Card card){
possibleCards = new ArrayList<>();
boolean isColored;
boolean isColored = false;
if (possibleCards != null){
for (int i = 1; i < possibleCards.size(); i++){
possibleCards.remove(i);
i--;
}
}
if (card instanceof Colored)
isColored = true;
else
isColored = false;
Iterator<Card> cardIterator = playerCards.iterator();
while (cardIterator.hasNext()) {
Card c = cardIterator.next();
......@@ -72,17 +77,26 @@ public class Player {
}
public Card randomPunishmentCard(ArrayList<Card> cards){
Random r = new Random();
int next = r.nextInt(cards.size());
return cards.get(next);
}
public void printAllPossibleCards(int playerNumber){
System.out.println("Player" + playerNumber + ": (Possible cards)");
Iterator<Card> cardIterator = possibleCards.iterator();
if (counter != 0){
cardIterator.next();
}
while (cardIterator.hasNext()){
Card c = cardIterator.next();
System.out.println(c.toString());
}
counter++;
}
public int searchWildDraws(){
private int searchWildDraws(){
int counterWildDraw = 0;
Iterator<Card> cardIterator = possibleCards.iterator();
while (cardIterator.hasNext()){
......@@ -93,7 +107,7 @@ public class Player {
return counterWildDraw;
}
public void deleteWildDraws(){
private void deleteWildDraws(){
for (int i = 0; i < possibleCards.size(); i++){
if (possibleCards.get(i) instanceof WildDraw){
possibleCards.remove(i);
......@@ -102,13 +116,34 @@ public class Player {
}
}
public Card chooseCardToThrow(){
public Card chooseCardToThrow(ArrayList<Card> cards, Card c){
return null;
}
public String chooseColorIfBlack(Card card){
String s = null;
return s;
}
public String toString(int playerNumber) {
return "Player" + playerNumber +
" {playerPoint=" + playerPoint +
" }";
}
public void checkColors(String color){
if (possibleCards != null){
for (int i = 1; i < possibleCards.size(); i++){
possibleCards.remove(i);
i--;
}
}
Iterator<Card> cardIterator = playerCards.iterator();
while (cardIterator.hasNext()) {
Card c = cardIterator.next();
if (c instanceof Colored)
if(c.cardColor.equals(color))
possibleCards.add(c);
}
}
}
......@@ -16,7 +16,7 @@ public class Reverse extends Movemention {
public boolean checkEquality(Colored coloredToCompare) {
if (super.checkEquality(coloredToCompare))
return true;
if (!super.checkEquality(coloredToCompare) && coloredToCompare instanceof Reverse)
if (coloredToCompare instanceof Reverse)
return true;
return false;
}
......
......@@ -10,7 +10,7 @@ public class Skip extends Movemention {
public boolean checkEquality(Colored coloredToCompare) {
if (super.checkEquality(coloredToCompare))
return true;
if (!super.checkEquality(coloredToCompare) && coloredToCompare instanceof Skip)
if (coloredToCompare instanceof Skip)
return true;
return false;
}
......
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