All pastes #918657 Raw Edit

Someone

public text v1 · immutable
#918657 ·published 2008-02-26 08:18 UTC
rendered paste body
	import java.util.Scanner;
import java.util.*;

/**
 * This a program or a maze game that incorporates some of the code that we have learned
 * @author Bryson Hori
 *
 */
public class BrysonHori_6
{
	public static void main(String[] args) {
		
		Scanner keybd = new Scanner(System.in);

		final int MAZE_WIDTH = 10;
		final int MAZE_HEIGHT = 10;
		
		final String FLOOR = ".";
		final char PLAYER = 'P';
		final char EXIT = 'X';
		
		System.out.println("This is a maze game.");
		System.out.println("The point of the game is for the player to get out of a room that is" + MAZE_WIDTH + " by " + MAZE_HEIGHT);
		System.out.println("This is done by pressing keys w,a,s,d");
		System.out.println("The direction north,south,east and west:");
		System.out.println("north = up");
		System.out.println("west = left");
		System.out.println("south = down");
		System.out.println("east = right");
		System.out.println("The capitol letter P represens you the player and the capitol letter X represents the exit.");
		System.out.println("");
		
		double mazeExitY = (int) (Math.random() * MAZE_HEIGHT);
		double mazeExitX = (int) (MAZE_WIDTH);
		
		double mazePlayerX = (int)(Math.random() * MAZE_WIDTH);
		double mazePlayerY = (int)(Math.random() * MAZE_HEIGHT);
		
		for (int y = 0; y <= MAZE_HEIGHT; y++) {
			  for (int x = 0; x <= MAZE_WIDTH; x++) {
				  if ( x == mazePlayerX &&  y == mazePlayerY) {
			      System.out.print(PLAYER);
			    }else if (x == mazeExitX && y == mazeExitY) {
			      System.out.print(EXIT);
			    }else {
			      System.out.print(FLOOR);
			    }
			  }
			  System.out.println();
			}

		
		while(mazeExitY != mazePlayerY && mazeExitX != mazePlayerX){ 
		                
		System.out.println("");
		System.out.println("What direction do you what to go?");
		String direction = keybd.next();
		
			if (direction.equalsIgnoreCase("north")){
				mazePlayerY = mazePlayerY -1;
			}if (direction.equalsIgnoreCase("south")){
				mazePlayerY = mazePlayerY +1;
			}if (direction.equalsIgnoreCase("west")){
				mazePlayerX = mazePlayerX -1;
			}if (direction.equalsIgnoreCase("east")){
				mazePlayerX = mazePlayerX +1;
			}
		
			for (int y = 0; y <= MAZE_HEIGHT; y++) {
				  for (int x = 0; x <= MAZE_WIDTH; x++) {
					  if (x == mazePlayerX &&  y == mazePlayerY) {
				      System.out.print(PLAYER);
				    }else if (x == mazeExitX && y == mazeExitY) {
				      System.out.print(EXIT);
				    }else {
				      System.out.print(FLOOR);
				    }
				  }
				  System.out.println();
				}
		System.out.println("Do you want to enter another direction?");
		System.out.println("Yes or No?");	
		}
		System.out.println("Congradulation You WIN!!!");
	}
}