Posted 31 March 2011 - 02:06 AM
Posted 31 March 2011 - 02:26 AM
Posted 20 December 2012 - 09:35 AM
//Early chapter 6 updated class to function with new arrayLists
import java.util.ArrayList;
public class SimpleDotComGame
{
public static void main(String[] args)
{
int numOfGuesses = 0;
GameHelper helper = new GameHelper();
SimpleDotCom theDotCom = new SimpleDotCom();
//Get a start position, as the object is length 3 and the max position is 5, the range is 0-7
int randomNum = (int) (Math.random() * 5);
[b]ArrayList<String> locations = new ArrayList<String>();
//Create object locations
locations.add(String.valueOf(randomNum));
locations.add(String.valueOf(randomNum+1));
locations.add(String.valueOf(randomNum+2));
theDotCom.setLocationCells(locations);[/b]
boolean isAlive = true;
//Begin the game loop
while (isAlive)
{
String guess = helper.getUserInput("enter a number: ");
String result = theDotCom.checkYourself(guess);
numOfGuesses++;
if (result == "kill")
{
isAlive = false;
System.out.format("You took %d guesses", numOfGuesses);
}
}
}
}
Posted 08 January 2013 - 08:28 AM
This post has been edited by jugo: 08 January 2013 - 08:43 AM
Posted 09 January 2013 - 08:23 AM
Posted 17 January 2013 - 09:01 AM