Advertisement
Guest User

Minesweeper.java

a guest
May 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Minesweeper {
  5.  
  6. public static void main (String[] args) {
  7. int r = 0;
  8. int c = 0;
  9. boolean lost = true;
  10. Scanner scan = new Scanner(System.in);
  11. System.out.println("Welcome to Minesweeper!\nPlease input 1 for easy, 2 for medium, 3 for hard");
  12. MineBoard game = new MineBoard(scan.nextInt());
  13. scan.nextLine();
  14. System.out.print(game.toString());
  15. System.out.println("Please enter the row, then the column.");
  16. r = scan.nextInt();
  17. c = scan.nextInt();
  18. scan.nextLine();
  19. game.fillBoard(r-1,c-1);
  20. game.uncover(r-1,c-1);
  21. while (!game.win()) {
  22. System.out.print(game.toString());
  23. System.out.println("Please enter the row, then the column.");
  24. r = scan.nextInt();
  25. c = scan.nextInt();
  26. scan.nextLine();
  27. lost = !game.uncover(r-1,c-1);
  28. if (lost) {
  29. break;
  30. }
  31. }
  32. if (lost) {
  33. System.out.println("You lost.");
  34. } else {
  35. System.out.println("You won!");
  36. }
  37. System.out.println(game.toString());
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement