I need to fix the code. Once a war event takes place, no points are assigned however in the next deal whoever wins (be it the player or computer) should get double points. One point for the war and the second point for the next deal that was won as well.
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = 1;
War war = new War();
while(count == 1){
System.out.println("Score: "+war.playerScore+"-"+war.compScore);
war.playerCard();
Card playerCard = new Card(war.playerNum, war.playerFace);
war.compCard();
Card compCard = new Card(war.compNum, war.compFace);
System.out.println("Player: "+playerCard.toString());
System.out.println("Computer: "+compCard.toString());
System.out.println(war.compare());
System.out.println("Play next round? 1 - yes, 0 - no");
count=sc.nextInt();
}
}
}
public class Card {
private String _suit;
private int _value;
private String _face;
public Card(int value, int suit) {
_value = value;
switch(value) {
case 14:
_face = "Ace";
break;
case 11:
_face = "Jack";
break;
case 12:
_face = "Queen";
break;
case 13:
_face = "King";
break;
default:
_face = String.valueOf(value);
}
switch(suit){
case 0:
_suit="spades";break;
case 1:
_suit="hearts";break;
case 2:
_suit="diamonds";break;
case 3:
_suit="clubs";break;
}
}
public String getSuit() {
return _suit;
}
public int getValue() {
return _value;
}
public String getFace() {
return _face;
}
public String toString(){
return this._face+" of "+this._suit;
}
} // Card
public class Deck2 {
private final int DECKSIZE = 52;
private Card[] deck = new Card[DECKSIZE];
private int _index;
public Deck2() {
} // constructor
public Card dealCard() {
return deck[_index++];
}
public boolean isEmpty() {
return _index == DECKSIZE;
}
public int getDeckSize() {
return DECKSIZE;
}
public void shuffle() {
for (int i = 0; i < 10000; i++) {
int card1 = (int) (Math.random() * DECKSIZE);
int card2 = (int) (Math.random() * DECKSIZE);
Card temp;
temp = deck[card1];
deck[card1] = deck[card2];
deck[card2] = temp;
} // for
} // shuffle
} // Deck
import java.util.Random;
public class War
{
public final int END_LIMIT = 8;
public static int playerScore = 0;
public static int compScore = 0;
public int playerNum = 0;
public int playerFace = 0;
public int compNum = 0;
public int compFace = 0;
private Deck2 warDeck;
private Random r = new Random();
public String compare()
{
if(playerNum > compNum){
playerScore++;
}else if(compNum > playerNum){
compScore++;
}else{
return "war! and no points awarded so far";
}
return "Score: "+this.playerScore+" - "+this.compScore;
}
public void playerCard(){
playerNum=r.nextInt(12)+1;
if(playerNum==1){
playerNum=14;
}
playerFace=r.nextInt(3);
}
public void compCard(){
compNum=r.nextInt(13)+1;
if(compNum==1){
compNum=14;
}
compFace=r.nextInt(4);
}
}