Skip to content

Instantly share code, notes, and snippets.

@lb7n
Last active August 29, 2015 14:05
Show Gist options
  • Save lb7n/3171730ae194aa5aaf4e to your computer and use it in GitHub Desktop.
Save lb7n/3171730ae194aa5aaf4e to your computer and use it in GitHub Desktop.
Board Navigation with Multi Dimensional Arrays
import java.util.Scanner;
public class Game {
private int[][] board;
public Game() {
board = new int[10][10];
}
public void startGame()
{
System.out.println("WELCOME TO BOARD NAVIGATOR!!!!!!~~~~");
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
board[i][j] = 0;
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
System.out.print(board[i][j]);
}
System.out.println();
}
}
public void updateScreen () {
System.out.println("WELCOME TO MINESWEEPER!!!!!!!~~~~");
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
System.out.print(board[i][j]);
}
System.out.println();
}
}
public void resetBoard(){
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
board[i][j] = 0;
}
}
}
public void continueGame(){
boolean running = true;
Scanner myscanner = new Scanner(System.in);
while (running){
System.out.println("Enter a spot to click and navigate around the grid! (Row, then column)");
int row = myscanner.nextInt();
int column = myscanner.nextInt();
resetBoard();
board[row][column] = 1;
updateScreen();
}
}
}
public class Mainclass {
public static void main(String[] args)
{
Game myGame = new Game();
myGame.startGame();
myGame.continueGame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment