/* * Maze * Copyright (C) 2000 Paul Davis, pdavis@lpccomp.bc.ca * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** * Show a crude representation of the maze on standard output. */ public class MazeTextDisplay { /** * The maze model. * @see MazeModel */ private MazeModel model; private Coordinate3D size; /** * Create the display with the given MazeModel. */ public MazeTextDisplay(MazeModel model) { this.model = model; size = model.getSize(); } /** * Display the maze on standard output. */ public void display(Coordinate3D cur) { int x,y,z; Coordinate3D finish = model.getFinish(); System.out.println(""); for ( z=0 ; z<size.z ; z++ ) { for ( x=0 ; x<size.x ; x++ ) System.out.print("+--"); System.out.println("+"); for ( y=0 ; y<size.y ; y++ ) { for ( x=0 ; x<size.x ; x++ ) { if ( (model.grid(x,y,z) & MazeModel.XMI) != 0 ) System.out.print(' '); else System.out.print('|'); if ( finish != null && x == finish.x && y == finish.y && z == finish.z ) System.out.print('F'); else if ( (model.grid(x,y,z) & MazeModel.ZPL) != 0 ) System.out.print('u'); else if ( (model.grid(x,y,z) & MazeModel.MARK) != 0 ) System.out.print('.'); else System.out.print(' '); if ( cur != null && x == cur.x && y == cur.y && z == cur.z ) System.out.print('*'); else if ( (model.grid(x,y,z) & MazeModel.ZMI) != 0 ) System.out.print('d'); else if ( (model.grid(x,y,z) & MazeModel.MARK) != 0 ) System.out.print('.'); else System.out.print(' '); } System.out.println("|"); for ( x=0 ; x<size.x ; x++ ) if ( (model.grid(x,y,z) & MazeModel.YPL) != 0 ) System.out.print("+ "); else System.out.print("+--"); System.out.println("+"); } } } }