Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. /**
  2.  * Package containing our java app
  3.  */
  4. package Minesweeper;
  5.  
  6. import java.util.Random;
  7. import java.util.Scanner;
  8.  
  9. /**
  10.  * Minesweeper Class
  11.  *
  12.  * @author Chris Ward
  13.  * @version 20/01/2011
  14.  */
  15. @SuppressWarnings("unused")
  16. public class Minesweeper {
  17.     // Our scanner to read input
  18.     Scanner scan;
  19.     // Our generator which generates the placement of the mines
  20.     private Random gen;
  21.     // Total number of mines
  22.     private final int totalMines = 10;
  23.     // Total number of columns
  24.     private final int totalColumns = 10;
  25.     // Total number of rows
  26.     private final int totalRows = 10;
  27.     // Number of blocks remaining
  28.     private int remainingBlocks;
  29.     // The cell for our grid
  30.     private Minesweeper.Cell[][] grid;
  31.  
  32.     /**
  33.      * main() Our main method which initializes Minesweeper, and starts a new
  34.      * game.
  35.      *
  36.      * @param args
  37.      */
  38.     public static void main(String[] args) {
  39.         Minesweeper game = new Minesweeper();
  40.         game.go();
  41.     }
  42.  
  43.     public void clear() {
  44.  
  45.     }
  46.  
  47.     public void go() {
  48.         boolean game = false;
  49.         do {
  50.             game = false;
  51.             startGame();
  52.             show();
  53.             while (!game) {
  54.                 game = guess();
  55.                 show();
  56.             }
  57.  
  58.         } while (playAgain());
  59.         endMessage();
  60.     }
  61.    
  62.     /**
  63.      * Cell Class; our class within a class.
  64.      */
  65.  
  66.     private class Cell {
  67.  
  68.         private String content;
  69.         private String  hyphen;
  70.         private boolean hasGuessed;
  71.  
  72.         public Cell() {
  73.             this.hyphen = "- ";
  74.             this.hasGuessed = false;
  75.             this.content = "0 ";
  76.         }
  77.        
  78.         public Cell(String hyphen, String content, boolean hasGuessed){
  79.             this.hyphen = "- ";
  80.             this.content = "0 ";
  81.             this.hasGuessed = false;
  82.         }
  83.        
  84.        
  85.     }
  86.  
  87.     /**
  88.      * Minesweeper()
  89.      *
  90.      * Our default constructor.
  91.      */
  92.     public Minesweeper() {
  93.         this.scan = new Scanner(System.in);
  94.         this.grid = new Minesweeper.Cell[10][10];
  95.         for (int i = 0; i < 10; i++) {
  96.             for (int j = 0; j < 10; j++) {
  97.                 this.grid[i][j] = new Minesweeper.Cell();
  98.             }
  99.         }
  100.         clear();
  101.         this.gen = new Random();
  102.         }
  103.  
  104.  
  105.     private boolean playAgain() {
  106.         String entry;
  107.         do {
  108.             playAgainMessage();
  109.             entry = this.scan.nextLine();
  110.         } while ((!entry.equalsIgnoreCase("yes"))
  111.                 && (!entry.equalsIgnoreCase("no")));
  112.         return entry.equalsIgnoreCase("yes");
  113.     }
  114.  
  115.     private boolean guess() {
  116.         if(Minesweeper.Cell.){
  117.            
  118.         }
  119.         return false;
  120.     }
  121.  
  122.     private void show() {
  123.         // TODO Auto-generated method stub
  124.  
  125.     }
  126.  
  127.     private void startGame() {
  128.         // Let's clear our previous board before the new game starts
  129.         clear();
  130.         startMessage();
  131.         buildGrid();
  132.  
  133.         for (int i = 1;; i++) {
  134.             getClass();
  135.             if (i > 8)
  136.                 break;
  137.             for (int j = 1;; j++) {
  138.                 getClass();
  139.                 if (j > 8)
  140.                     break;
  141.                 // Minesweeper.Cell(this.grid[1][j], countClose(i, j) + " ");
  142.             }
  143.         }
  144.     }
  145.  
  146.     private String countClose(int i, int j) {
  147.        
  148.         return null;
  149.     }
  150.  
  151.     private void buildGrid() {
  152.         // TODO Auto-generated method stub
  153.  
  154.     }
  155.  
  156.     /**
  157.      * Below are our strings used for communication to the user.
  158.      */
  159.  
  160.     private void startMessage() {
  161.         System.out.println("Do you want to see the mines (yes/no)?");
  162.     }
  163.  
  164.     private void endMessage() {
  165.         System.out.println("Thank you for playing minesweeper.");
  166.     }
  167.  
  168.     private void playAgainMessage() {
  169.         System.out.println("Would you like to play again? (Yes/No)");
  170.     }
  171.  
  172.     private void enterRow() {
  173.         System.out.println("Enter row to guess (Value must be 0 through 7).");
  174.     }
  175.  
  176.     private void enterColumn() {
  177.         System.out
  178.                 .println("Enter column to guess (Value must be 0 through 7).");
  179.     }
  180.  
  181.     private void confirmMine() {
  182.         System.out
  183.                 .println("Do you think there is a mine at this square (yes/no)?");
  184.     }
  185.  
  186.     private void hitMine() {
  187.         int x = 12;
  188.         int y = 11;
  189.         System.out.println("Row " + x + ", column " + y + "is a mine.");
  190.     }
  191.  
  192.     private void missMine() {
  193.         int x = 1;
  194.         int y = 2;
  195.         System.out.println("Row " + x + ", column " + y + "is not a mine.");
  196.     }
  197.  
  198.     private void loseGame() {
  199.         System.out.println("Incorrect guess, end of game.");
  200.     }
  201.  
  202.     private void winGame() {
  203.         System.out.println("Correctly Guessed all cells. You win!");
  204.     }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement