Inside the play game method, each player should take a series of turns. Here is where you should right the logic to compare whether player1 or player2 won each turn. After turns have been taken, return the winner of the game. Since you now know loops, you can add logic into playGame() that makes a game involve multiple turns.
Code that I have:
WarPlayer class:
import java.util.Scanner;
import java.util.Random;
public class WarPlayer
{
private boolean user; //True if player is not a computer.
public WarPlayer(boolean isComputer)
{
user = ! isComputer;
}
public boolean takeTurn()
{
if(! user)
{
Random r = new Random();
int A = 0;
int J = 10;
int Q = 11;
int K = 12;
r.nextInt(12);
}
else
{
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
}
return true;
}
}
WarGame class
public class WarGame
{
private WarPlayer player1;
private WarPlayer player2;
public WarGame(boolean player1, boolean player2)
{
this.player1 = new WarPlayer(player1);
this.player2 = new WarPlayer(player2);
}
public void playGame()
{
player1.takeTurn();
player2.takeTurn();
}
}
public class GameTesterClass
{
public static void main(String[] args)
{
WarPlayer player1 = new WarPlayer(true);
WarPlayer player2 = new WarPlayer(true);
}
}
I just want to know a little bit of code for the play game method that tells whoever has the highest card (A, 2-9, J, Q, K) wins. Thanks

New Topic/Question
Reply



MultiQuote



|