Lee EunA

Greenhorn
+ Follow
since Apr 29, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lee EunA

hello
I am a Korean.
I can not speak English...
sorry..
but i have a question ..
chapter 6. GameHelper Source.
=Head First Java=

------------

// Tiger version

import java.io.*;
import java.util.*;

class GameHelper {

private static final String alphabet = "abcdefg";
private int gridLength = 7;
private int gridSize = 49;
private int [] grid = new int[gridSize];
private int comCount = 0;


public String getUserInput(String prompt) {
String inputLine = null;
System.out.print(prompt + " ");
try {
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0 ) return null;
} catch (IOException e) {
System.out.println("IOException: " + e);
}
return inputLine.toLowerCase();
}



public ArrayList<String> placeDotCom(int comSize) { // line 19
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize]; // holds 'f6' type coords
String temp = null; // temporary String for concat
int [] coords = new int[comSize]; // current candidate coords
int attempts = 0; // current attempts counter
boolean success = false; // flag = found a good location ?
int location = 0; // current starting location

comCount++; // nth dot com to place
int incr = 1; // set horizontal increment
if ((comCount % 2) == 1) { // if odd dot com (place vertically)
incr = gridLength; // set vertical increment
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~here!!!
// Number 200!!!
//Why 200???
while ( !success & attempts++ < 200 ) { // main searchloop (32)
//////////////////////////////////


location = (int) (Math.random() * gridSize); // get random starting point
System.out.print(" try " + location);
int x = 0; // nth position in dotcom to place
success = true; // assume success
while (success && x < comSize) { // look for adjacent unused spots
if (grid[location] == 0) { // if not already used
coords[x++] = location; // save location
location += incr; // try 'next' adjacent
if (location >= gridSize){ // out of bounds - 'bottom'
success = false; // failure
}
if (x>0 & (location % gridLength == 0)) { // out of bounds - right edge
success = false; // failure
}
} else { // found already used location
System.out.print(" used " + location);
success = false; // failure
}
}
System.out.println("\n");
System.out.println(attempts);
} // end while


int x = 0; // turn good location into alpha coords
int row = 0;
int column = 0;
System.out.println("\n");
while (x < comSize) {
grid[coords[x]] = 1; // mark master grid pts. as 'used'
row = (int) (coords[x] / gridLength); // get row value
column = coords[x] % gridLength; // get numeric column value
temp = String.valueOf(alphabet.charAt(column)); // convert to alpha

alphaCells.add(temp.concat(Integer.toString(row)));
x++;

System.out.print(" coord "+x+" = " + alphaCells.get(x-1));

}

System.out.println("\n");

return alphaCells;
}
}
-------------
I wondered

The meaning of 200............

It's just a big number of our actions?





[ April 29, 2008: Message edited by: Lee EunA ]

[edited to make subject meaningful - was "important question !!!please~~~"]
[ April 29, 2008: Message edited by: Jeanne Boyarsky ]
15 years ago