This commit is contained in:
2022-09-15 22:36:02 +02:00
parent 3993342453
commit fef09ea000
9 changed files with 103 additions and 2 deletions

View File

View File

View File

@@ -11,12 +11,21 @@ public class Bot extends Player {
public Bot(Dealer dealer) { public Bot(Dealer dealer) {
super(dealer); super(dealer);
this.hand = super.getHand();
} }
@Override @Override
public Card getPlay(Card currentCard) { public Card getPlay(Card currentCard) {
new Scanner(System.in).nextLine(); new Scanner(System.in).nextLine();
List<Card> hand = super.getHand();
if (hand.size() == 1 && Referee.isValidEndCard(hand.get(0))) {
return hand.get(0);
} else if (hand.size() == 1) {
hand.add(drawCard());
System.out.println("Bot drew a card");
System.out.println("Bot now has " + hand.size() + " cards");
return null;
}
for(Card card : hand) { for(Card card : hand) {
TYPENUM cardType = card.getType(); TYPENUM cardType = card.getType();

View File

@@ -13,7 +13,6 @@ public class Human extends Player {
public Human(Dealer dealer) { public Human(Dealer dealer) {
super(dealer); super(dealer);
this.hand = super.getHand();
} }
@Override @Override
@@ -22,6 +21,7 @@ public class Human extends Player {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
List<Card> hand = super.getHand();
while (true){ while (true){
String input = scanner.nextLine(); String input = scanner.nextLine();
if(input.equals("quit")){ if(input.equals("quit")){
@@ -53,6 +53,7 @@ public class Human extends Player {
} }
private void printHand(){ private void printHand(){
List<Card> hand = super.getHand();
for (int i = 0; i < hand.size(); i++) { for (int i = 0; i < hand.size(); i++) {
System.out.println("(" + i + ") " + hand.get(i).getType() + " " + hand.get(i).getValue()); System.out.println("(" + i + ") " + hand.get(i).getType() + " " + hand.get(i).getValue());
} }

View File

@@ -0,0 +1,2 @@
package mau.mau;public class CardTest {
}

View File

@@ -0,0 +1,2 @@
package mau.mau;public class DealerTest {
}

View File

@@ -0,0 +1,2 @@
package mau.mau;public class DeckTest {
}

View File

@@ -0,0 +1,85 @@
package mau.mau;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class RefereeTest {
@Test
public void isSameCardTypeValidMoveTest(){
//Assign
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
Card testCardTwo = new Card(TYPENUM.HEARTS, VALUENUM.EIGHT);
//Act
boolean result = Referee.isValidMove(testCardOne, testCardTwo);
//Assert
assertTrue(result);
}
@Test
public void isSameCardValueValidMoveTest(){
//Assign
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
Card testCardTwo = new Card(TYPENUM.DIAMOND, VALUENUM.ACE);
//Act
boolean result = Referee.isValidMove(testCardOne, testCardTwo);
//Assert
assertTrue(result);
}
@Test
public void isJokerOnAnyCardValidMoveTest() {
//Assign
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
Card testCardTwo = new Card(TYPENUM.JOKER, VALUENUM.THREE);
//Act
boolean results = Referee.isValidMove(testCardOne, testCardTwo);
//Assert
assertTrue(results);
}
@Test
public void isAnyCardOnJokerValidMoveTest(){
//Assign
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.ACE);
Card testCardTwo = new Card(TYPENUM.JOKER, VALUENUM.THREE);
//Act
boolean results = Referee.isValidMove(testCardTwo, testCardOne);
//Assert
assertTrue(results);
}
@Test
public void isAceOfSpadesValidEndcardTest(){
//Assign
Card testCardOne = new Card(TYPENUM.SPADES, VALUENUM.ACE);
//Act
boolean results = Referee.isValidEndCard(testCardOne);
//Assert
assertFalse(results);
}
@Test
public void isThreeOfHeartsValidEndcardTest(){
//Assign
Card testCardOne = new Card(TYPENUM.HEARTS, VALUENUM.THREE);
//Act
boolean results = Referee.isValidEndCard(testCardOne);
//Assert
assertTrue(results);
}
}

0
src/test/java/tested.md Normal file
View File