Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project Implement the entire game in Java using console I/O. You will implement

ID: 3573496 • Letter: P

Question

Project

Implement the entire game in Java using console I/O.

You will implement a simplified game of Scrimish, a strategy card game, with 2 players: a human (i.e., the user) and the computer. Scrimish is a card game that was funded using kickstarter.com with the objective that luck is not a component of the game. Watch a video demonstration of the game at scrimish.com

Both players have a set of cards composed of the following cards and numbers:

#1 Dagger Cards (x5 per player)

#2 Sword Cards (x5 per player)

#3 Morning Star Cards (x3 per player)

#4 War Axe Cards (x3 per player)

#5 Halberd Cards (x2 per player)

#6 Longsword Cards (x2 per player)

'A' Archer Cards (x2 per player)

'S' Shield Cards (x2 per player)

'C' Crown Card (x1 per player)

Setup: The user player places 5 Piles of 5 Cards each face down in front of him. The Crown Card should be hidden on the bottom of one of the 5 Piles. The rest of the Cards may be arranged however you like. The computer does the same thing: the crown card is placed on the bottom of a random pile, while the rest of the card are distributed into 5 piles (such that we have 5 cards in each pile).

Game Play: The players take turns attacking (starting with the user first) by selecting the top card from one of their piles and laying that card face up in front of one of their opponent's piles. The defending player must then reveal the top card of the pile that was attacked. The card with the lowest number value loses and is discarded. The winning card must be returned face down to the top of the original pile it was drawn from. If the two cards have the same number value, both cards are discarded. The play continues until one of the players attacks their opponent's Crown Card, winning the game.

Archer Card: If you attack with an Archer Card, it always wins. If your Archer Card is attacked, it always loses.

Shield Card: Shield Cards cannot be used to attack. If your Shield Card is attacked, both your Shield Card and your opponent's attacking Card are discarded (except for Archer Cards: If a Shield Card is attacked by an Archer Card, neither Card is discarded, and both are returned face down to their original Piles).

Crown Card: You can attack with your Crown Card. If you attack your opponent's Crown Card, you win. Otherwise, you lose the game.

Instead of attacking, you may intentionally discard one Card on your turn. You do not have to reveal that Card to your opponent. You cannot intentionally discard your Crown Card.

Implement the entire game in Java using console I/O.

The number of points possible for the project are 30 points:

game setup: let the human user select the cards in each pile = 10 points

play one turn started by the human user = 10 points

play one turn started by the computer = 10 points

Explanation / Answer

I'm posting an automated vserion of the game where both the players are automated. This will be Version 1. Version 2 will have the functionality for human player to interact. What i would suggest you is to have a look at this automated part and see of it suits your requirement.

Pile.java

package scrimish;

import java.util.Stack;

public class Pile {

  

   private int numOfCards;

   private int pileNumber;

   private Stack<Character> cards;

   boolean hasCrown = false;

  

   public Pile(int pileNumber) {

   numOfCards = 5;

   this.pileNumber = pileNumber;

   cards = new Stack<Character>();

   }

   public Stack<Character> getCards() {

   return cards;

   }

   public void setCards(Stack<Character> cards) {

   this.cards = cards;

   }

   public int getNumOfCards() {

   return numOfCards;

   }

   public void setNumOfCards(int numOfCards) {

   this.numOfCards = numOfCards;

   }

   public int getPileNumber() {

   return pileNumber;

   }

   public void setPileNumber(int pileNumber) {

   this.pileNumber = pileNumber;

   }

  

   public boolean isEmpty()

   {

   if(numOfCards ==0)

   return true;

   else return false;

   }

  

   public boolean isHasCrown() {

   return hasCrown;

   }

  

   public void setHasCrown(boolean hasCrown) {

       this.hasCrown = hasCrown;

       numOfCards++;

   }

   public boolean removeACard()

   {

   if(numOfCards >0)

   {

       cards.pop();

       numOfCards--;

       return true;

   }

   else return false;

   }

   public char getCardValue()

   {

   if(numOfCards > 0)

   return cards.peek();

   else

       return ' ';

   }

}

Player.java

package scrimish;

import java.util.ArrayList;

import java.util.Stack;

public class Player {

  

   private String name;

   private String cardColor;

   private ArrayList<Pile> Piles;

   ArrayList<Character> deckOfCards;

   private RandomSelect selector;

   private int currentPileNum;

   private boolean intentionalRemovalDone;

   private int numberOfPiles;

   public Player(String name, String color) {

   this.name = name;

   this.cardColor = color;

   selector = new RandomSelect();

   currentPileNum = -1;

   numberOfPiles = 5;

   intentionalRemovalDone = false;

   deckOfCards = new ArrayList<>();

   for(int i=0; i<Scrimish.cardTypes.length; i++)

   {

       deckOfCards.add(Scrimish.cardTypes[i]);

   }

   setUpPiles();

   }

   public String getName() {

   return name;

   }

   public void setName(String name) {

   this.name = name;

   }

   public String getCardColor() {

   return cardColor;

   }

   public void setCardColor(String cardColor) {

   this.cardColor = cardColor;

   }

   public ArrayList<Pile> getPiles() {

   return Piles;

   }

   public void setPiles(ArrayList<Pile> piles) {

   Piles = piles;

   }

  

   private void setUpPiles()

   {

  

   int cardPosition;

   Stack<Character> cards;

   Piles = new ArrayList<Pile>();

   int cardCount = deckOfCards.size()-1; // 24 because we are counting from 0 to 24 - total : 25 cards

   int crownPos = selector.pickANum(0, 4);

   for(int i=0; i<5; i++)

   {

   Pile pile = new Pile(i+1);

   cards = new Stack<Character>();

   int cardsInPile = 5;

   if(i == crownPos)

   {

       pile.setHasCrown(true);

       cards.push(deckOfCards.get(cardCount)); //pushing the crown into bottom position

       deckOfCards.remove(cardCount);

       cardCount--;

       cardsInPile = 4;

   }

   for(int j=0; j<cardsInPile; j++)

   {

   cardPosition = selector.pickANum(0, cardCount);

   cards.push(deckOfCards.get(cardPosition));

   deckOfCards.remove(cardPosition);

       cardCount--;

   }

   pile.setCards(cards);

   Piles.add(pile);

   }

   }

  

   public char getCard()

   {

   selector = new RandomSelect();

   Pile pile;

   if(this.name.equals("Computer"))

   {

       currentPileNum = selector.pickANum(numberOfPiles);

       /*while(Piles.get(currentPileNum).isEmpty())

           currentPileNum = selector.pickANum(0, numberOfPiles);*/

       pile = Piles.get(currentPileNum);

   }

   else

   {

     

       currentPileNum = selector.pickANum(numberOfPiles);

       pile = Piles.get(currentPileNum);

   }

   return pile.getCardValue();

   }

  

  

   public void removeAPile(int pileNumber)

   {

   /*for(int i=0; i<Piles.size(); i++)

   {

   if(Piles.get(i).getPileNumber() == pileNumber)

   {

   Piles.remove(i);

   numberOfPiles--;

   break;

   }

   }*/

   Piles.remove(pileNumber);

   numberOfPiles--;

   }

   public void removeCardFromCurrentPile()

   {

   Piles.get(currentPileNum).removeACard();

      if(Piles.get(currentPileNum).getNumOfCards() <= 0)

           removeAPile(currentPileNum); //currentPileNum is the array index value in the piles

   }

   public boolean removeCardIntentionally()

   {

   boolean isDone = false;

   int num = selector.pickANum(0, 1);

   if(!intentionalRemovalDone && num == 1)

   {

           if(Piles.get(currentPileNum).getCardValue() != 'C')

           {

               Piles.get(currentPileNum).removeACard();

               if(Piles.get(currentPileNum).getNumOfCards() <= 0)

                   removeAPile(currentPileNum);

               intentionalRemovalDone = true;

               isDone = true;

           }

   }

   return isDone;

   }

   public boolean arePilesOver()

   {

   if(Piles.size() == 0)

       return true;

   else return false;

   }

   public void printAvailablePiles()

   {

   for(int i=0; i<Piles.size(); i++)

   {

       System.out.print(" P" + Piles.get(i).getPileNumber() + " ");

   }

   System.out.println("");

   }

   public void printAvailableCards()

   {

   for(int i=0; i<Piles.size(); i++)

   {

       System.out.print( " " + Piles.get(i).getCards().toString() + " ");

   }

   System.out.println("");

   }

}

RandomSelect.java

package scrimish;

import java.util.Random;

public class RandomSelect {

   public int pickANum(int min, int max)

   {

   int random = min + (int)(Math.random() * (max+1))%(max+1);

   //System.out.println("Random: " + random);

   return random;

   }

  

   public int pickANum(int max)

   {

   Random r = new Random();

   int Low = 0;

   int Result = r.nextInt(max-Low) + Low;

   //System.out.println("Random: " + Result);

   return Result;

   }

}

Scrimish.java

package scrimish;

import java.util.ArrayList;

import java.util.Scanner;

public class Scrimish {

  

   static final char cardTypes[] = {'1','1','1','1','1', //#1 Dagger Cards (x5 per player)

   '2','2','2','2','2', //#2 Sword Cards (x5 per player)

   '3','3','3', //#3 Morning Star Cards (x3 per player)

   '4','4','4', //#4 War Axe Cards (x3 per player)

   '5','5', //#5 Halberd Cards (x2 per player)

   '6','6', //#6 Longsword Cards (x2 per player)

   'A','A', //'A' Archer Cards (x2 per player)

   'S','S', //'S' Shield Cards (x2 per player)

   'C' //'C' Crown Card (x1 per player)

   };

   static final String Colors[] = {"RED", "BLUE"};

   static final int numberOfPlayers = 2;

   private RandomSelect selector;

   private boolean gameOver = false;

   private String winner = "";

   Player human;

   Player computer;

   public String cardName(char cardType)

   {

      String cardName = "";

   switch(cardType)

   {

   case '1': cardName = "#1 Dagger Card";

              break;

   case '2': cardName = "#2 Sword Card";

               break;

   case '3': cardName = "#3 Morning Sar Card";

               break;

   case '4': cardName = "#4 War Axe Card";

               break;

   case '5': cardName = "#5 Holberd Card";

               break;

   case '6': cardName = "#6 Longsword Card";

               break;

   case 'A': cardName = "Archer Card";

               break;

   case 'S': cardName = "Shield Card";

               break;

   case 'C': cardName = "Crown Card";

               break;

   }

     

   return cardName;

   }

   public Scrimish() {

   selector = new RandomSelect();

   }

  

public void updatePlayers(Player attacker, Player opponent)

{

      if(attacker.getName().equals("Computer"))

      {

          computer = attacker;

          human = opponent;

      }else

      {

          computer = opponent;

          human = attacker;

      }

}

   public boolean isGameOver()

   {

   return gameOver;

   }

   public void setPlayers(Player comp, Player human)

   {

   this.human = human;

   this.computer = comp;

   }

   //playing the game

   public boolean play()

   {

   Player attacker, opponent, dummy;

   attacker = human;

   opponent = computer;

   boolean isPlayDone = false;

   char attackerCard = ' ', opponentCard = ' ';

  

   while(!isGameOver())

   {

       System.out.println("Attacker is " + attacker.getName());

       attacker.printAvailablePiles();

          // attacker.printAvailableCards(); //for debugging

       System.out.println("Opponent is " + opponent.getName());

       opponent.printAvailablePiles();

       // opponent.printAvailableCards(); //for debugging

       attackerCard = attacker.getCard();

   opponentCard = opponent.getCard();

   if(attackerCard == ' ' || opponentCard == ' ')

       return isPlayDone;

       if(!attacker.removeCardIntentionally())

       {

           System.out.println(attacker.getName() + " attacks " + opponent.getName() + " with " + cardName(attackerCard));

           System.out.println(opponent.getName() + "'s card is " + cardName(opponentCard));

           switch(attacking(attackerCard, opponentCard))

           {

           case -1 : System.out.println("Putting cards back to the pile !");

                      break;

           case 0: attacker.removeCardFromCurrentPile();

                      opponent.removeCardFromCurrentPile();

                      System.out.println("Its a Draw !");

                      break;

           case 1: opponent.removeCardFromCurrentPile();

                      System.out.println(attacker.getName() + " wins !");

                      break;

           case 2: attacker.removeCardFromCurrentPile();

                      System.out.println(opponent.getName() + " wins !");

                      break;

           case 3: System.out.println((winner.equals("attacker")? attacker.getName() : opponent.getName()) + " wins the game !");

                      isPlayDone = true;

                      break;

           case 4: System.out.println("Removing shield card from top of the pile.");

           attacker.removeCardFromCurrentPile();

           break;

           }

       }

       else

       {

           System.out.println(attacker.getName() + " discarded a card");

       }

       System.out.println("----------------------------------- ");

       updatePlayers(attacker, opponent);

       dummy = attacker;

       attacker = opponent;

       opponent = dummy;

       attackerCard = ' ';

       opponentCard = ' ';

       //System.out.println("Game continues.. ");

   }

   System.out.println("Thanks for Playing.. Goodbye !");

   return isPlayDone;

   }

   public int attacking(char attackerCardValue, char opponentCardValue)

   {

   // 0 - draw, -1 - nothing done to the cards, 1 - attacker wins, 2 - opponent wins, 3 - game won, 4 - shield card

   int result = -1;

   if(attackerCardValue == 'A' || attackerCardValue == 'S' || attackerCardValue == 'C' || opponentCardValue == 'A'

           || opponentCardValue == 'S' || opponentCardValue == 'C')

   {

       if(attackerCardValue == 'A' && opponentCardValue == 'S')

           return result;

       if(attackerCardValue == 'A' || opponentCardValue == 'A')

       {

           result = 1;

           return result;

       }

       if(attackerCardValue == 'S')

       {

           result = 4;

           return result;

       }

       if(opponentCardValue == 'S')

       {

           result = 0;

           return result;

       }

       if(opponentCardValue == 'C' || attackerCardValue == 'C')

       {

           result = 3;

           if(opponentCardValue == 'C')

               winner = "attacker";

           else

               winner = "opponent";

           gameOver = true;

           return result;

       }

   }

     

   int attackValue = Integer.valueOf(attackerCardValue);

   int opponentValue = Integer.valueOf(opponentCardValue);

      if(attackValue < opponentValue)

          result = 2;

      else if(attackValue > opponentValue)

          result = 1;

      else

          result = 0;

   return result;

   }

  

}

ScrimishApplication.java

package scrimish;

import java.util.Scanner;

public class ScrimishApplication {

   public static void main(String[] args) {

       Scrimish scrimish = new Scrimish();

       int colorchoice = 0, flip = 0;

   //getting the name of the human player

       System.out.println("Welcome to Scrimish Game !");

       System.out.println("I hope you are aware of the rules. In our version, a human player will play with the computer.");

   System.out.println("For each turn of the game, the available piles are printed");

       System.out.print(" Enter the player name: ");

   Scanner scan = new Scanner(System.in);

   String name = scan.nextLine();

   System.out.print("Pick a Color 1. RED 2. BLUE Choice: ");

      colorchoice = scan.nextInt();

      System.out.println(" ");

      //creating the players - Human and Computer with colors for each

   Player human = new Player(name, Scrimish.Colors[colorchoice-1]);

   Player computer = new Player("Computer", Scrimish.Colors[colorchoice-1 == 0? 1:0]);

   scrimish.setPlayers(computer, human);

     

   scrimish.play();

   }

}

OUTPUT:

Welcome to Scrimish Game !

I hope you are aware of the rules. In our version, a human player will play with the computer.

For each turn of the game, the available piles are printed

Enter the player name: Kaju

Pick a Color

1. RED

2. BLUE

Choice: 1

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #5 Holberd Card

Computer's card is #2 Sword Card

Kaju wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with Archer Card

Kaju's card is Crown Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju discarded a card

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer discarded a card

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #5 Holberd Card

Computer's card is #5 Holberd Card

Its a Draw !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #2 Sword Card

Kaju's card is #1 Dagger Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #2 Sword Card

Computer's card is Archer Card

Kaju wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #2 Sword Card

Kaju's card is #2 Sword Card

Its a Draw !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #1 Dagger Card

Computer's card is #3 Morning Sar Card

Computer wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #4 War Axe Card

Kaju's card is #2 Sword Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #5 Holberd Card

Computer's card is #4 War Axe Card

Kaju wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #3 Morning Sar Card

Kaju's card is Shield Card

Its a Draw !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #2 Sword Card

Computer's card is #1 Dagger Card

Kaju wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #6 Longsword Card

Kaju's card is #4 War Axe Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #1 Dagger Card

Computer's card is #2 Sword Card

Computer wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #5 Holberd Card

Kaju's card is #2 Sword Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #6 Longsword Card

Computer's card is #2 Sword Card

Kaju wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P3 P4 P5

Computer attacks Kaju with #5 Holberd Card

Kaju's card is #5 Holberd Card

Its a Draw !

-----------------------------------

Attacker is Kaju

P1 P2 P3 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with Shield Card

Computer's card is #6 Longsword Card

Removing shield card from top of the pile.

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P4 P5

Computer attacks Kaju with #4 War Axe Card

Kaju's card is #1 Dagger Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #3 Morning Sar Card

Computer's card is #6 Longsword Card

Computer wins !

-----------------------------------

Attacker is Computer

P1 P2 P3 P4 P5

Opponent is Kaju

P1 P2 P4 P5

Computer attacks Kaju with #6 Longsword Card

Kaju's card is #4 War Axe Card

Computer wins !

-----------------------------------

Attacker is Kaju

P1 P2 P4 P5

Opponent is Computer

P1 P2 P3 P4 P5

Kaju attacks Computer with #1 Dagger Card

Computer's card is Crown Card

Kaju wins the game !

-----------------------------------

Thanks for Playing.. Goodbye !