Anda di halaman 1dari 7

import java.io.

IOException;

import java.util.Scanner;

public class MazeRunner {

public static void main(String[] args) {

intro();

userMove();

private static void intro() {

Scanner input = new Scanner(System.in);

Maze myMap = new Maze();

System.out.print("Please type your name here:\t");

String name = input.nextLine();

System.out.println("Hi " + name + " welcome to Maze Runner!");

System.out.println("\nTake a look through the control system.");

System.out.println("\t\tW = Up \t\tS = Down\n\t\tA = Left\tD = Right\n\t\t\t J = Jump");

System.out.println("\n\t___________________________________________________________");

System.out.print("\n\t\t\tPlease press Enter to continue");

getch();

System.out.println(name + " here is your current position");

myMap.printMap();

private static void userMove() {

Scanner input = new Scanner(System.in);

Maze myMap = new Maze();

System.out.println("press ENTER to start the game");

getch();

String move;

String massage = "";

int moveleft = 100;

while ((moveleft > 0) && (!myMap.didIWin()) && (!massage.equalsIgnoreCase("Pitted"))){


clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

move = input.next();

if (move.equalsIgnoreCase("W")) {

if (myMap.isThereAPit(move)){

massage = "Watch out there is a pit.\t\tJump";

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

String jump = input.next();

if (jump.equalsIgnoreCase("J")) {

myMap.jumpOverPit(move);

massage = "Jumped over.";

} else {

massage = "Pitted";

}else if (myMap.canIMoveUp()) {

myMap.moveUp();

massage = "Moved";

}
else {

massage = "You can not move that way. There is a Wall.";

} else if (move.equalsIgnoreCase("S")) {

if (myMap.isThereAPit(move)){

massage = "Watch out there is a pit.\t\tJump";

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

String jump = input.next();

if (jump.equalsIgnoreCase("J")) {

myMap.jumpOverPit(move);

massage = "Jumped over.";

} else {

massage = "Pitted";

}else if (myMap.canIMoveDown()) {

myMap.moveDown();

massage = "Moved";

} else {

massage = "You can not move that way. There is a Wall.";

} else if (move.equalsIgnoreCase("A")) {

if (myMap.isThereAPit(move)){

massage = "Watch out there is a pit.\t\tJump";

clrscr();
System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

String jump = input.next();

if (jump.equalsIgnoreCase("J")) {

myMap.jumpOverPit(move);

massage = "Jumped over.";

} else {

massage = "Pitted";

}else if (myMap.canIMoveLeft()) {

myMap.moveLeft();

massage = "Moved";

} else {

massage = "You can not move that way. There is a Wall.";

} else if (move.equalsIgnoreCase("D")) {

if (myMap.isThereAPit(move)){

massage = "Watch out there is a pit.\t\tJump";

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();
String jump = input.next();

if (jump.equalsIgnoreCase("J")) {

myMap.jumpOverPit(move);

massage = "Jumped over.";

} else {

massage = "Pitted";

}else if (myMap.canIMoveRight()) {

myMap.moveRight();

massage = "Moved";

} else {

massage = "You can not move that way. There is a Wall.";

} else {

massage = "Your choice is invalid";

moveleft++;

moveleft--;

if ((moveleft > 0) && (myMap.didIWin())){

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

System.out.println("\n\n\t\tWonderful! You have escaped!");

if ((moveleft == 0) && (!myMap.didIWin())){

clrscr();
System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

System.out.println("\n\t\tSorry, You are out of move. And, you couldn't escaped! Better luck next time.");

if ((moveleft > 0) && (!myMap.didIWin()) && (massage.equalsIgnoreCase("Pitted"))){

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();

System.out.println("\n\t\tGame Over. You have fall down throw the pit. Be careful next time.");

if ((moveleft == 0) && (myMap.didIWin())){

clrscr();

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~");

System.out.println("\t\t| W = Up \t\tS = Down\t\tA = Left\t\tD = Right\t\tJ = Jump |\t\t\t| Moves Left: " +
moveleft+" |");

System.out.println("\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~\n\n\t"+massage);

myMap.printMap();
System.out.println("\n\t\tWow! You just escaped at the last move!");

private static void getch(){

try {

System.in.read();

catch (IOException e) {

e.printStackTrace();

private static void clrscr(){

for(int i = 0; i < 50; i++) {

System.out.println("");

Anda mungkin juga menyukai