Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class e15 {
- public static void main(String [] args) {
- Scanner input = new Scanner(System.in);
- // pelikentän koko
- System.out.println("Give the table size: ");
- int size = input.nextInt();
- String[] table = new String[size];
- int bombs = size / 3;
- boolean lost = false;
- // kentän tulostus
- for (int i=0; i<size; i++) {
- table[i] = "[ ]";
- System.out.print(table[i]);
- }
- // pommien paikat
- while (bombs>0) {
- int i = MyMath.getRandom(0, size-1);
- if (!table[i].equals("[B]")) {
- table[i] = "[B]";
- bombs--;
- }
- }
- // paikan syöte
- System.out.println("\nChoose your spot >:)");
- int spot = input.nextInt()-1;
- for (int i=0; i<size; i++) {
- if (i==spot) {
- System.out.print("[P]");
- } else {
- System.out.print("[ ]");
- }
- }
- }
- }
- class MyMath {
- public static int getRandom(int min, int max) {
- return (int) (Math.random()*((max-min)+1))+min;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement