Documente Academic
Documente Profesional
Documente Cultură
//Main Method
public static void main (String [] args) throws IOException
{// start main method
//Welcoming Screen
/*
This while loop makes the board for the player to visualize what the
game looks like, it uses a counter to increment or decrement by 1.
It will also subtract by 9 or 10 when necessary to create a board
exactly like the one given.
*/
while (counter > 0){// start while
if (counter%10 == 0 && counter != 200){// checks if the counter is at a
90, or 80...
if(iteration==-1)
{
// subtract 9 from the counter
// and sets it to start adding by one
counter-=9;
iteration=1;
}
else
{
System.out.print(counter+"\t");
counter-=10;
iteration=-1; // set the counter to start subtract by ones
}
if(counter!=0)
System.out.print("\n" + counter + "\t"); // just prints out the
counter with a line breck
}
else
System.out.print(counter + "\t"); // just prints out the counter
counter+=iteration; // sets counter to add by iteration
}// end while
System.out.println();
System.out.println
("---------------------------------------------------------------------------------
-------------------------------------------------");
String sGame = "y"; // decare variable used to ask user if he wants to play
//-------------------------------------------------------------------startGame
Method-----------------------------------------------------------------------------
-
/*
startGame method:
This method is responsible for organizing the game, asking the user to continue
playing,
and setting the important varibales. It will also return a vaule to the main
method, which
will reset the game so the user can play again.
*/
public static String startGame (String start) throws IOException // Recieves
data from the main method
{// start startGame method
System.out.println("---------------------------------------------------------------
------------------------------------------------------------");
System.out.println
("\t\t\t\t\t------------------------------------------");
System.out.println ("\t\t\t\t\t|\tYou Rolled a " + userRoll + "\t\t|");
// print the roll the user got
System.out.println ("\t\t\t\t\t|\tThe Computer Rolled a " + compRoll +
"\t|"); // print the roll the computer got
System.out.println
("\t\t\t\t\t------------------------------------------");
// hold the user's last position for switching back if current position
was greater than 100
userPosition = userPosition + userRoll;
System.out.println("\t\t\t*********************************************************
****************");
System.out.println ("\t\t\t*\t\tYou are currently on square " +
userPosition + "\t\t\t*"); // print out the user's current location
System.out.println ("\t\t\t*\t\tThe Computer is currently on square " +
compPosition + "\t\t*"); // print out the computer's current location
System.out.println("\t\t\t*********************************************************
****************");
//-------------------------------------------------------------------geDice
Method-----------------------------------------------------------------------------
-
/*
getDice method:
//-------------------------------------------------------------------getP
Method-----------------------------------------------------------------------------
-
/*
getP method:
}
else if (userPosition == snakesLaddersArray[2]) //if position equals snake
3
{
userPosition = 77; // set new position
System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got Bit By A Snake, GO
DOWN!!!~~~~~~~~~~~~~");
}
else if (userPosition == snakesLaddersArray[3]) //if position equals ladder
1
{
userPosition = 34; // set new position
System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got A Ladder!! GO UP!!!
~~~~~~~~~~~~~");
}
else if (userPosition == snakesLaddersArray[4]) //if position equals ladder
2
{
userPosition = 64; // set new position
System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got A Ladder!! GO UP!!!
~~~~~~~~~~~~~");
}
else if (userPosition == snakesLaddersArray[5]) //if position equals ladder
3
{
}
else if (userPosition == 100)
{
System.out.println ("YOU WON, GOOD JOB!!!"); // print out that the user
won
//-------------------------------------------------------------------compgetP
Method-----------------------------------------------------------------------------
-
/*
compgetP method:
This method is responsible for checking if the COMPUTER is on
top of a snake, or at the bottom of a ladder, and then
adjusting the compuer's position to mathch the snakes or
ladders value.
*/
// NOTE: this method is similar to getP, so the comments are the same for
both!!
// Look at getP's commments if you need help
if(compPosition == snakesLaddersArray[0])
{
compPosition = 19;
System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake,
HE WENT GO DOWN!!!~~~~~~~~~~~~~");
}
else if (compPosition == snakesLaddersArray[1])
{
compPosition = 48;
System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake,
HE WENT GO DOWN!!!~~~~~~~~~~~~~");
}
else if (compPosition == snakesLaddersArray[2])
{
compPosition = 77;
System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake,
HE WENT GO DOWN!!!~~~~~~~~~~~~~");
}
else if (compPosition == snakesLaddersArray[3])
{
compPosition = 34;
System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
}
else if (compPosition == snakesLaddersArray[4])
{
compPosition = 64;
System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
}
else if (compPosition == snakesLaddersArray[5])
{
compPosition = 86;
System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
}
}
else if (compPosition == 200 && userPosition != 200)
{
System.out.println ("THE COMPUTER WON, YOU FAILED!!!"); // print out
that the computer won