Skip to content

Instantly share code, notes, and snippets.

@KristerV
Last active October 31, 2015 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save KristerV/e1a5198c0b0938a926f6 to your computer and use it in GitHub Desktop.
Save KristerV/e1a5198c0b0938a926f6 to your computer and use it in GitHub Desktop.
package teema2;
import java.util.Arrays;
import java.util.Scanner;
public class LaevadGrid {
static int[][] laud;
static int lauaLaius = 4;
static int lauaKorgus = 3;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
genereeriLaud();
paigutaLaevad();
int[] xy = kysiKasutajalt();
kontrolliTabamust(xy);
// kasOnLaevuAlles();
// gameover();
}
private static void kontrolliTabamust(int[] xy) {
int tabamus = laud[xy[0]][xy[1]];
if (tabamus == 0) {
System.out.println("läks mööda");
} else if (tabamus == 1) {
System.out.println("pihjta");
laud[xy[0]][xy[1]] = 2;
}
}
private static int[] kysiKasutajalt() {
System.out.println("Sisesta x ja y kordinaadid (tühik vahel)");
String sisestus = sc.nextLine(); // 5 6
System.out.println();
int x = Integer.parseInt( sisestus.substring(0, 1) );
int y = Integer.parseInt(sisestus.substring(2, 3));
System.out.println("Kasutaja sisestas: x " + x + " y " + y);
int[] xy = new int[]{x, y};
return xy;
}
private static void paigutaLaevad() {
for (int i = 0; i < lauaKorgus; i++) {
for (int j = 0; j < lauaLaius; j++) {
laud[i][j] = (int) Math.round( Math.random() * 0.7 );
}
System.out.println(Arrays.toString(laud[i]));
}
}
public static void genereeriLaud() {
laud = new int[lauaKorgus][lauaLaius];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment