mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Reformatted
This commit is contained in:
@@ -5,27 +5,40 @@ import java.util.Scanner;
|
|||||||
import static java.lang.System.in;
|
import static java.lang.System.in;
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core algorithm copied from amazing.py
|
||||||
|
*/
|
||||||
public class Amazing {
|
public class Amazing {
|
||||||
|
|
||||||
|
final static int FIRST_COL = 0;
|
||||||
|
final static int FIRST_ROW = 0;
|
||||||
|
final static int EXIT_UNSET = 0;
|
||||||
|
final static int EXIT_DOWN = 1;
|
||||||
|
final static int EXIT_RIGHT = 2;
|
||||||
private final Scanner kbScanner;
|
private final Scanner kbScanner;
|
||||||
|
|
||||||
public Amazing() {
|
public Amazing() {
|
||||||
kbScanner = new Scanner(in);
|
kbScanner = new Scanner(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Direction {
|
private static int getDelimitedValue(String text, int pos) {
|
||||||
GO_LEFT,
|
String[] tokens = text.split(",");
|
||||||
GO_UP,
|
try {
|
||||||
GO_RIGHT,
|
return Integer.parseInt(tokens[pos]);
|
||||||
GO_DOWN,
|
} catch (Exception ex) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final static int FIRST_COL = 0;
|
private static String tab(int spaces) {
|
||||||
final static int FIRST_ROW = 0;
|
char[] spacesTemp = new char[spaces];
|
||||||
|
Arrays.fill(spacesTemp, ' ');
|
||||||
|
return new String(spacesTemp);
|
||||||
|
}
|
||||||
|
|
||||||
final static int EXIT_UNSET = 0;
|
public static int random(int min, int max) {
|
||||||
final static int EXIT_DOWN = 1;
|
Random random = new Random();
|
||||||
final static int EXIT_RIGHT = 2;
|
return random.nextInt(max - min) + min;
|
||||||
|
}
|
||||||
|
|
||||||
public void play() {
|
public void play() {
|
||||||
out.println(tab(28) + "AMAZING PROGRAM");
|
out.println(tab(28) + "AMAZING PROGRAM");
|
||||||
@@ -138,24 +151,11 @@ public class Amazing {
|
|||||||
return kbScanner.next();
|
return kbScanner.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getDelimitedValue(String text, int pos) {
|
enum Direction {
|
||||||
String[] tokens = text.split(",");
|
GO_LEFT,
|
||||||
try {
|
GO_UP,
|
||||||
return Integer.parseInt(tokens[pos]);
|
GO_RIGHT,
|
||||||
} catch (Exception ex) {
|
GO_DOWN,
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String tab(int spaces) {
|
|
||||||
char[] spacesTemp = new char[spaces];
|
|
||||||
Arrays.fill(spacesTemp, ' ');
|
|
||||||
return new String(spacesTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int random(int min, int max) {
|
|
||||||
Random random = new Random();
|
|
||||||
return random.nextInt(max - min) + min;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Cell {
|
public static class Cell {
|
||||||
@@ -228,12 +228,15 @@ public class Amazing {
|
|||||||
public Cell getPrevCol(Cell cell) {
|
public Cell getPrevCol(Cell cell) {
|
||||||
return cells[cell.row][cell.col - 1];
|
return cells[cell.row][cell.col - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getPrevRow(Cell cell) {
|
public Cell getPrevRow(Cell cell) {
|
||||||
return cells[cell.row - 1][cell.col];
|
return cells[cell.row - 1][cell.col];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getNextCol(Cell cell) {
|
public Cell getNextCol(Cell cell) {
|
||||||
return cells[cell.row][cell.col + 1];
|
return cells[cell.row][cell.col + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getNextRow(Cell cell) {
|
public Cell getNextRow(Cell cell) {
|
||||||
return cells[cell.row + 1][cell.col];
|
return cells[cell.row + 1][cell.col];
|
||||||
}
|
}
|
||||||
@@ -257,4 +260,3 @@ public class Amazing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user