Hi I am writing a program for a car cricket game. I can get the innings and players name ok, but when the program needs to randomly choose vehicles and colours, nothing appears in output. I think my program is not entering in this loop. Could I please get some suggestions? My code so far:
[hightlight=java]
import java.util.*;
import java.util.Random;
public class AssigOne112
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
Random generator;
//Set seed value
final int SEED = 400;
//Final var
final int CARS = 4;
//Colour variable for vehicles
final int BLACK = 0;
final int BLUE = 1;
final int CYAN = 2;
final int DARK_GREY = 3;
final int GREY = 4;
final int GREEN = 5;
final int LIGHT_GREY = 6;
final int MAGENTA = 7;
final int ORANGE = 8;
final int PINK = 9;
final int RED = 10;
final int WHITE = 11;
final int YELLOW = 12;
//Value of coloured cars
final int BLACK_CAR_VALUE = 1;
final int WHITE_CAR_VALUE = 1;
final int GREEN_CAR_VALUE = 2;
final int YELLOW_CAR_VALUE = 3;
final int BLUE_CAR_VALUE = 4;
final int ORANGE_CAR_VALUE = 5;
final int CYAN_CAR_VALUE = 0;
final int DARK_GREY_CAR_VALUE = 0;
final int GREY_CAR_VALUE = 0;
final int LIGHT_GREY_CAR_VALUE = 0;
final int MAGENTA_CAR_VALUE = 0;
final int PINK_CAR_VALUE = 0;
//Calculated players average
double avgScore1;
double avgScore2;
//Variables
// players name input
String name1;
String name2;
String playerOne;
String playerTwo;
String name;
//Players sequence
boolean playerSequence;
int currentPlayer;
int player;
//Variables for players scoring
int player1Total;
int player2Total;
int scoreInning = 0;
//Final score
int score =0;
int won = 0;
int playGame = 0;
String getColour;
int innings = 0; //starts count for innings
int colourNum = -1;
String colour;
int getScoreByColour;
int vehicleType = -1;
boolean isCar = (vehicleType !=0);
//Game Rules
System.out.println("Car Cricket Game");
System.out.println("================");
System.out.println("Scoring: non white/black/red/green/yellow/blue/orange car: 0 runs.");
System.out.println("White/black car: 1 run.");
System.out.println("Non-red van/truck/bus/SUV: 1 run.");
System.out.println("Green car: 2 runs.");
System.out.println("Yellow car: 3 runs.");
System.out.println("Blue car: 4 runs.");
System.out.println("Orange car: 5 runs.");
System.out.println("Red van/truck/bus/SUV: 6 runs.");
System.out.println("Red car: OUT!");
System.out.println();
System.out.println("Time to play!");
System.out.println();
//Ask user to input names and innings wanting to play.
System.out.print("Two players are required to play this game. Please enter the name of one of the players: ");
playerOne = sc.next();
System.out.print("Please enter the name of the other player: ");
playerTwo = sc.next();
System.out.print("Answering either true or false, is " + playerOne + " going to bat first? ");
playerSequence = sc.nextBoolean();
System.out.print("How many innings do you want to play in this game? ");
playGame = sc.nextInt();
//installation of Random function
generator = new Random(SEED);
for(innings=1; innings<=playGame; innings ++)
{
System.out.println("Innings # " + innings);
do
{
while(currentPlayer = 1 && currentPlayer <=2 && currentPlayer ++)
{
if(playerSequence)
{
name1 = playerOne;
name2 = playerTwo;
}
else
{
name1 = playerTwo;
name2 = playerOne;
}
System.out.print("Player #" + currentPlayer + " ");
// determine current player's name
if (currentPlayer == 1)
{
name = name1;
}
else
{
name = name2;
}
System.out.println("(" + name + ")");
System.out.println();
if (vehicleType != 0)
{
isCar = true;
colourNum = generator.nextInt(13);
score = colourNum;
vehicleType = generator.nextInt(10) + 1;
return vehicleType >= 1 && vehicleType <= 9;
// add score by given colour to inning's score
scoreInning += score;
// add score to a global scoring of given player
if (currentPlayer == 1)
{
player1Total +=score;
}
else
{
player2Total +=score;
}
System.out.print(" car...");
if(colourNum == RED)
{
System.out.println("OUT!");
System.out.println("Total was " + scoreInning);
System.out.println("Current scores: ");
System.out.println(name1 + ": " + player1Total);
System.out.println(name2 + ": " + player2Total);
}
colour = "";
switch (colourNum)
{
case BLACK:
colour = "Black";
score = BLACK_CAR_VALUE;
break;
case BLUE:
colour = "Blue";
score = BLUE_CAR_VALUE;
break;
case CYAN:
colour = "Cyan";
score = CYAN_CAR_VALUE;
break;
case DARK_GREY:
colour = "Dark Grey";
score = DARK_GREY_CAR_VALUE;
break;
case GREY:
colour = "Grey";
score = GREY_CAR_VALUE;
break;
case GREEN:
colour = "Green";
score = GREEN_CAR_VALUE;
break;
case LIGHT_GREY:
colour = "Light Grey";
score = LIGHT_GREY_CAR_VALUE;
break;
case MAGENTA:
colour = "Magenta";
score = MAGENTA_CAR_VALUE;
break;
case ORANGE:
colour = "Orange";
score = ORANGE_CAR_VALUE;
break;
case PINK:
colour = "Pink";
score = PINK_CAR_VALUE;
break;
case RED:
colour = "Red";
//score = score + RED_CAR_VALUE;
break;
case WHITE:
colour = "White";
score = WHITE_CAR_VALUE;
break;
case YELLOW:
colour = "Yellow";
score = YELLOW_CAR_VALUE;
break;
}
return;
}
else
{
if (colourNum == RED)
{
isCar = false;
System.out.print(" van/truck/bus/SUV...");
scoreInning += 6;
if (currentPlayer == 1)
{
player1Total += 6;
}
else
{
player2Total += 6;
}
System.out.println("6");
}
else
{
scoreInning += 1;
if (currentPlayer == 1)
{
player1Total += 1;
}
else
{
player2Total += 1;
}
System.out.println("1");
}
}
//player1Total = sc.nextInt();
//player2Total = sc.nextInt();
//Find the winner.
if (player1Total == player2Total)
{
System.out.println("Draw!");
}
else
if (player1Total > player2Total)
{
avgScore1 = player1Total/playGame;
System.out.println(name1 + " (with avg " + avgScore1 + ") won");
}
else
if (player1Total < player2Total)
{
avgScore2 = player2Total/playGame;
System.out.println(name2 + " (with avg " + avgScore2 + ") won");
}
}
}
}
}
}
[/highlight]