mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Initial Commit
Added Instructions, Random mine placement, and the general layout
This commit is contained in:
80
30_Cube/java/src/Cube.java
Normal file
80
30_Cube/java/src/Cube.java
Normal file
@@ -0,0 +1,80 @@
|
||||
import java.io.PrintStream;
|
||||
import java.util.Random;
|
||||
|
||||
public class Cube {
|
||||
|
||||
private Location playerLocation;
|
||||
private Location[] mines;
|
||||
private PrintStream out;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Cube().play();
|
||||
}
|
||||
|
||||
public Cube() {
|
||||
out = System.out;
|
||||
}
|
||||
|
||||
private void placeMines() {
|
||||
mines = new Location[5];
|
||||
Random random = new Random();
|
||||
for(int i = 0; i < mines.length; i++) {
|
||||
int x = random.nextInt(1,4);
|
||||
int y = random.nextInt(1,4);
|
||||
int z = random.nextInt(1,4);
|
||||
mines[i] = new Location(x,y,z);
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
|
||||
}
|
||||
|
||||
public void printInstructions() {
|
||||
out.println("THIS IS A GAME IN WHICH YOU WILL BE PLAYING AGAINST THE");
|
||||
out.println("RANDOM DECISION OF THE COMPUTER. THE FIELD OF PLAY IS A");
|
||||
out.println("CUBE OF SIDE 3. ANY OF THE 27 LOCATIONS CAN BE DESIGNATED");
|
||||
out.println("CUBE OF SIDE 3. ANY OF THE 27 LOCATIONS CAN BE DESIGNATED");
|
||||
out.println("BY INPUTTING THREE NUMBERS SUCH AS 2,3,1. AT THE START");
|
||||
out.println("YOU ARE AUTOMATICALLY AT LOCATION 1,1,1. THE OBJECT OF");
|
||||
out.println("THE GAME IS TO GET TO LOCATION 3,3,3. ONE MINOR DETAIL:");
|
||||
out.println("THE COMPUTER WILL PICK, AT RANDOM, 5 LOCATIONS AT WHICH");
|
||||
out.println("IT WILL PLANT LAND MINES. IF YOU HIT ONE OF THESE LOCATIONS");
|
||||
out.println("YOU LOSE. ONE OTHER DETAIL: YOU MAY MOVE ONLY ONE SPACE");
|
||||
out.println("IN ONE DIRECTION EACH MOVE. FOR EXAMPLE: FROM 1,1,2 YOU");
|
||||
out.println("MAY MOVE TO 2,1,2 OR 1,1,3. YOU MAY NOT CHANGE");
|
||||
out.println("TWO OF THE NUMBERS ON THE SAME MOVE. IF YOU MAKE AN ILLEGAL");
|
||||
out.println("MOVE, YOU LOSE AND THE COMPUTER TAKES THE MONEY YOU MAY");
|
||||
}
|
||||
|
||||
public class Location {
|
||||
int x,y,z;
|
||||
|
||||
public Location(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Location location = (Location) o;
|
||||
|
||||
if (x != location.x) return false;
|
||||
if (y != location.y) return false;
|
||||
return z == location.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = x;
|
||||
result = 31 * result + y;
|
||||
result = 31 * result + z;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user