-
-
Save lb7n/3171730ae194aa5aaf4e to your computer and use it in GitHub Desktop.
Board Navigation with Multi Dimensional Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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