Skip to content

Instantly share code, notes, and snippets.

@tterrag1098

tterrag1098/Hw4.java

Forked from treeofwar/java
Created Oct 12, 2018
Embed
What would you like to do?
import java.util.Scanner;
import java.util.Random;
public class Hw4 {
public static final int BOARD_SIZE = 10;
enum space {Empty,Player,Walked_Path,Goal,Mines};//eumeration creates a type
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int pX = 0;//players x and y
int pY = 0;
int gX = r.nextInt(BOARD_SIZE);//the goals random location
int gY = r.nextInt(BOARD_SIZE);
space[] [] board = new space[BOARD_SIZE][BOARD_SIZE];
for(int i=0;i<board.length;i++)
{
for(int j=0;j<board[i].length;j++)
{
board[i][j] = space.Empty;
}
}
board[pX][pY] = space.Player;
board[gX][gY] = space.Goal;
System.out.println("welcome to the game");
//game loop
boolean gameOver = false;
while(!gameOver)
{
//draw the boardfor
for(int i=0;i<board.length;i++)
{
for(int j=0;j<board[i].length;j++)
{
switch(board[i][j])
{
case Empty:
System.out.print("_");
break;
case Player:
System.out.print("X");
break;
case Walked_Path:
System.out.print("#");
break;
case Goal:
System.out.print("_");
break;
case Mines:
System.out.print("_");
break;
default:
System.out.print("?");
}
}
System.out.println();
}
gameOver=true;
}
//xinput
System.out.println("enter either a -1 0 or 1 to move in the x direction");
int dX = keyboard.nextInt();
if(dX < -1 || dX > 1)
{
dX = 0;
}
//yinput
System.out.println("enter either a -1 0 or 1 to move in the y direction");
int dY = keyboard.nextInt();
if(dY < -1 || dY > 1)
{
dY = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment