Saturday, November 20, 2010

So im in a java class in highschool and were assigned to make a game. How do i change the color of the dice?

This is my code, but i haven't learned how to change color can any give me some help? btw its only of the dice, not the whole game








import java.io.*;


import java.util.*;


import java.awt.font.*;


import java.text.*;





public class DiceGame





{


public static void main(String args[])


{


Scanner kbReader = new Scanner(System.in);


System.out.println(';Do you want to play the Lucky Dice game? (yes or no) ';);


String play = kbReader.next();


int cash = 300;


int numRoll = 0;


do


{





System.out.println(';\n\n\n\n\nWelcome to the Lucky Dice Game\n';);





Random r1 = new Random();


int rand1 = r1.nextInt(6) + 1;








Random r2 = new Random();


int rand2 = r2.nextInt(6) + 1;








System.out.println(';Roll 1 = '; + rand1 + '; Roll = '; + rand2 + ';\n';);








String roll1 = ';\n|-------|\n| |\n| * |\n| |\n|-------|';;


String roll2 = ';\n|-------|\n| * |\n| |\n| * |\n|-------|';;


String roll3 = ';\n|-------|\n| * |\n| * |\n| * |\n|-------|';;


String roll4 = ';\n|-------|\n| * * |\n| |\n| * * |\n|-------|';;


String roll5 = ';\n|-------|\n| * * |\n| * |\n| * * |\n|-------|';;


String roll6 = ';\n|-------|\n| * * |\n| * * |\n| * * |\n|-------|';;








int total = rand1 + rand2;











{


if(rand1 == 1)


System.out.println(roll1);


else if (rand1 == 2)


System.out.println(roll2);


else if (rand1 == 3)


System.out.println(roll3);


else if (rand1 == 4)


System.out.println(roll4);


else if (rand1 == 5)


System.out.println(roll5);


else if (rand1 == 6)


System.out.println(roll6);


}





{


if(rand2 == 1)


System.out.println(roll1);


else if (rand2 == 2)


System.out.println(roll2);


else if (rand2 == 3)


System.out.println(roll3);


else if (rand2 == 4)


System.out.println(roll4);


else if (rand2 == 5)


System.out.println(roll5);


else if (rand2 == 6)


System.out.println(roll6);


}











if(total == 7 || total == 11)


{


numRoll = (numRoll + 1);


cash = (cash + 40);


System.out.println(';You have $'; + cash + ';.00 left';);


System.out.println(';';);// Spacer


System.out.println( ';You rolled a - Lucky '; + total + '; - You've Won $40.00 ';);





}


else if (cash == 0)


{


break;


}


else {


numRoll = (numRoll + 1);


System.out.println(';';);


System.out.println(';You rolled a - '; + total + '; - Sorry you loose $20.00';);


cash = (cash - 20);


System.out.println(';You have $'; + cash + ';.00 left';);


}

















for(;;)


{


System.out.print(';Would you like to try again?(yes for yes no for no) ';);


play = kbReader.next();





if (play.equalsIgnoreCase(';no';)||play.equal鈥?br>

{





break;


}


else if (play.equalsIgnoreCase(';yes';) || play.equalsIgnoreCase(';yes';))


{


break;


}





else


{


System.out.println(';Please type only 'yes' or 'no'.';);


continue;


}


}// end for loop


}//end do loop


while(play.equalsIgnoreCase(';y';) || play.equalsIgnoreCase(';yes';));


System.out.println(';\n\n\n\n\n\n\n\n\n\n鈥?have lost all of your money! Thank you for Playing!!';);


System.out.println(';\n\n You have $';+ cash + ';.00 in cash \n\n You have rolled '; + numRoll + '; times';);


}





}So im in a java class in highschool and were assigned to make a game. How do i change the color of the dice?
You can't change the color of the font that is printed to the console (System.out.print). Once you progress in Java, you'll learn how to create graphical user interfaces (GUIs), which will allow you those options. But for all practical purposes, the console that you are printing to is specifically used for debugging code and learning to program.So im in a java class in highschool and were assigned to make a game. How do i change the color of the dice?
You'll need a graphical interface to manipulate the color of any output. Any interactions you have with the console don't allow changing the color.
  • wwe myspace
  • myspace pictures
  • No comments:

    Post a Comment