398 lines
26 KiB
HTML
398 lines
26 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Maze.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||
|
.literal {color: #cc7832}
|
||
|
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
.ST0 {color: #287bde}
|
||
|
.number {color: #6897bb}
|
||
|
.string {color: #6a8759}
|
||
|
.ST1 {color: #9876aa}
|
||
|
.ST2 {color: #ffc66d}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
.ST5 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP3_Recursion_CalebFontenot/src/mp3_recursion_calebfontenot/Maze.java</td></tr></table>
|
||
|
<pre>
|
||
|
<span class="comment">/*</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||
|
<span class="comment"> */</span>
|
||
|
<span class="literal">package</span> mp3_recursion_calebfontenot;
|
||
|
|
||
|
<span class="literal">import</span> java.util.Optional;
|
||
|
<span class="literal">import</span> javafx.application.Application;
|
||
|
<span class="literal">import</span> javafx.geometry.Pos;
|
||
|
<span class="literal">import</span> javafx.scene.Scene;
|
||
|
<span class="literal">import</span> javafx.scene.control.Alert;
|
||
|
<span class="literal">import</span> javafx.scene.control.Button;
|
||
|
<span class="literal">import</span> javafx.scene.control.ButtonType;
|
||
|
<span class="literal">import</span> javafx.scene.control.Label;
|
||
|
<span class="literal">import</span> javafx.scene.layout.BorderPane;
|
||
|
<span class="literal">import</span> javafx.scene.layout.GridPane;
|
||
|
<span class="literal">import</span> javafx.scene.layout.HBox;
|
||
|
<span class="literal">import</span> javafx.scene.layout.StackPane;
|
||
|
<span class="literal">import</span> javafx.scene.paint.Color;
|
||
|
<span class="literal">import</span> javafx.scene.shape.Line;
|
||
|
<span class="literal">import</span> javafx.scene.shape.Rectangle;
|
||
|
<span class="literal">import</span> javafx.stage.Stage;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">class</span> Maze <span class="literal">extends</span> Application {
|
||
|
|
||
|
<span class="literal">double</span> <span class="ST1">paneWidth</span> = <span class="number">600</span>;
|
||
|
<span class="literal">double</span> <span class="ST1">paneHeight</span> = <span class="number">600</span>;
|
||
|
|
||
|
<span class="literal">private</span> Cell[][] <span class="ST1">board</span> = <span class="literal">new</span> Cell[<span class="number">8</span>][<span class="number">8</span>];
|
||
|
<span class="literal">private</span> Button <span class="ST1">btFindPath</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Find Path Top Left to Bottom Right</span><span class="string">"</span>);
|
||
|
<span class="literal">private</span> Button <span class="ST1">btFindPath2</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Find Path Top Right to Bottom Left</span><span class="string">"</span>);
|
||
|
<span class="literal">private</span> Button <span class="ST1">btClearPath</span> = <span class="literal">new</span> Button(<span class="string">"</span><span class="string">Clear Path</span><span class="string">"</span>);
|
||
|
<span class="literal">private</span> Label <span class="ST1">lblStatus</span> = <span class="literal">new</span> Label();
|
||
|
|
||
|
@Override <span class="comment">// Override the start method in the Application class</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">start</span>(Stage primaryStage) {
|
||
|
GridPane gridPane = <span class="literal">new</span> GridPane();
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; i++) {
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">8</span>; j++) {
|
||
|
gridPane.add(<span class="ST1">board</span>[i][j] = <span class="literal">new</span> Cell(), j, i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
HBox hBox = <span class="literal">new</span> HBox(<span class="number">5</span>);
|
||
|
hBox.setAlignment(Pos.<span class="ST3">CENTER</span>);
|
||
|
hBox.getChildren().addAll(<span class="ST1">b</span><span class="ST1">tFindPath</span>, <span class="ST1">b</span><span class="ST1">tFindPath2</span>, <span class="ST1">b</span><span class="ST1">tClearPath</span>);
|
||
|
|
||
|
BorderPane pane = <span class="literal">new</span> BorderPane();
|
||
|
pane.setTop(<span class="ST1">l</span><span class="ST1">blStatus</span>);
|
||
|
BorderPane.<span class="ST4">setAlignment</span>(<span class="ST1">l</span><span class="ST1">blStatus</span>, Pos.<span class="ST3">CENTER</span>);
|
||
|
pane.setCenter(gridPane);
|
||
|
pane.setBottom(hBox);
|
||
|
|
||
|
<span class="comment">// Create a scene and place it in the stage</span>
|
||
|
Scene scene = <span class="literal">new</span> Scene(pane, <span class="ST1">p</span><span class="ST1">aneWidth</span>, <span class="ST1">paneHeight</span> + <span class="number">60</span>);
|
||
|
primaryStage.setTitle(<span class="string">"</span><span class="string">Maze</span><span class="string">"</span>); <span class="comment">// Set the stage title</span>
|
||
|
primaryStage.setScene(scene); <span class="comment">// Place the scene in the stage</span>
|
||
|
primaryStage.show(); <span class="comment">// Display the stage</span>
|
||
|
|
||
|
<span class="ST1">btFindPath</span>.setOnAction(e -> findPath());
|
||
|
<span class="ST1">btFindPath2</span>.setOnAction(e -> findPath2());
|
||
|
<span class="ST1">btClearPath</span>.setOnAction(e -> clearPath());
|
||
|
showSampleMessage();
|
||
|
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">showSampleMessage</span>() {
|
||
|
Alert a = <span class="literal">new</span> Alert(Alert.<span class="ST4">AlertType</span>.<span class="ST3">CONFIRMATION</span>);
|
||
|
|
||
|
a.setTitle(<span class="string">"</span><span class="string">Maze Information</span><span class="string">"</span>);
|
||
|
a.setHeaderText(<span class="string">"</span><span class="string"> Put this message in its proper place. </span><span class="string">"</span>);
|
||
|
a.setContentText(<span class="string">"</span><span class="string">This square cannot have an X</span><span class="string">"</span>);
|
||
|
Optional<ButtonType> result = a.showAndWait();
|
||
|
<span class="literal">if</span> (result.get() == ButtonType.<span class="ST3">OK</span>) {
|
||
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">OK </span><span class="string">"</span>);
|
||
|
} <span class="literal">else</span> <span class="literal">if</span> (result.get() == ButtonType.<span class="ST3">CANCEL</span>) {
|
||
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">CANCEL</span><span class="string">"</span>);
|
||
|
}
|
||
|
}
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">clearCells</span>() {
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; ++i) {
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">8</span>; j++) {
|
||
|
<span class="ST1">board</span>[i][j].resetCell();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">findPath</span>() {
|
||
|
clearCells();
|
||
|
<span class="literal">if</span> (findPath(<span class="number">0</span>, <span class="number">0</span>)) {
|
||
|
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">path found</span><span class="string">"</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">No path exists</span><span class="string">"</span>);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">findPath2</span>() {
|
||
|
clearCells();
|
||
|
<span class="literal">if</span> (findPath2(<span class="number">0</span>, <span class="number">7</span>)) {
|
||
|
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">path found</span><span class="string">"</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
<span class="ST1">lblStatus</span>.setText(<span class="string">"</span><span class="string">No path exists</span><span class="string">"</span>);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">findPath</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||
|
<span class="ST1">board</span>[row][col].visit();
|
||
|
|
||
|
<span class="literal">if</span> ((col == <span class="number">7</span>) && (row == <span class="number">7</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCell();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((row > <span class="number">0</span>) && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].marked()
|
||
|
&& !<span class="ST1">board</span>[row - <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].visited()) {
|
||
|
block(row, col);
|
||
|
|
||
|
<span class="literal">if</span> (findPath(row - <span class="number">1</span>, col)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCell();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((row < <span class="number">7</span>) && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].marked()
|
||
|
&& !<span class="ST1">board</span>[row + <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].visited()) {
|
||
|
block(row, col);
|
||
|
|
||
|
<span class="literal">if</span> (findPath(row + <span class="number">1</span>, col)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCell();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((col > <span class="number">0</span>) && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].marked()
|
||
|
&& !<span class="ST1">board</span>[row][col - <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].visited()) {
|
||
|
block(row, col);
|
||
|
<span class="literal">if</span> (findPath(row, col - <span class="number">1</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCell();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((col < <span class="number">7</span>) && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].marked()
|
||
|
&& !<span class="ST1">board</span>[row][col + <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].visited()) {
|
||
|
block(row, col);
|
||
|
<span class="literal">if</span> (findPath(row, col + <span class="number">1</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCell();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">return</span> <span class="literal">false</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">findPath2</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||
|
<span class="ST1">board</span>[row][col].visit();
|
||
|
|
||
|
<span class="literal">if</span> ((col == <span class="number">0</span>) && (row == <span class="number">7</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((row > <span class="number">0</span>) && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].marked()
|
||
|
&& !<span class="ST1">board</span>[row - <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row - <span class="number">1</span>][col].visited()) {
|
||
|
block(row, col);
|
||
|
|
||
|
<span class="literal">if</span> (findPath2(row - <span class="number">1</span>, col)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((row < <span class="number">7</span>) && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].marked()
|
||
|
&& !<span class="ST1">board</span>[row + <span class="number">1</span>][col].blocked() && !<span class="ST1">board</span>[row + <span class="number">1</span>][col].visited()) {
|
||
|
block(row, col);
|
||
|
|
||
|
<span class="literal">if</span> (findPath2(row + <span class="number">1</span>, col)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((col > <span class="number">0</span>) && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].marked()
|
||
|
&& !<span class="ST1">board</span>[row][col - <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col - <span class="number">1</span>].visited()) {
|
||
|
block(row, col);
|
||
|
<span class="literal">if</span> (findPath2(row, col - <span class="number">1</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> ((col < <span class="number">7</span>) && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].marked()
|
||
|
&& !<span class="ST1">board</span>[row][col + <span class="number">1</span>].blocked() && !<span class="ST1">board</span>[row][col + <span class="number">1</span>].visited()) {
|
||
|
block(row, col);
|
||
|
<span class="literal">if</span> (findPath2(row, col + <span class="number">1</span>)) {
|
||
|
<span class="ST1">board</span>[row][col].selectCellGreen();
|
||
|
<span class="literal">return</span> <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
unblock(row, col);
|
||
|
}
|
||
|
|
||
|
<span class="literal">return</span> <span class="literal">false</span>;
|
||
|
}
|
||
|
|
||
|
<span class="comment">// Temporary block the neighbor to prevent neighboring path</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">block</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||
|
<span class="literal">if</span> (row > <span class="number">0</span>) {
|
||
|
<span class="ST1">board</span>[row - <span class="number">1</span>][col].block();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (row < <span class="number">7</span>) {
|
||
|
<span class="ST1">board</span>[row + <span class="number">1</span>][col].block();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (col > <span class="number">0</span>) {
|
||
|
<span class="ST1">board</span>[row][col - <span class="number">1</span>].block();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (col < <span class="number">7</span>) {
|
||
|
<span class="ST1">board</span>[row][col + <span class="number">1</span>].block();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="comment">// Remove the temporary block</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unblock</span>(<span class="literal">int</span> row, <span class="literal">int</span> col) {
|
||
|
<span class="literal">if</span> (row > <span class="number">0</span>) {
|
||
|
<span class="ST1">board</span>[row - <span class="number">1</span>][col].unblock();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (row < <span class="number">7</span>) {
|
||
|
<span class="ST1">board</span>[row + <span class="number">1</span>][col].unblock();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (col > <span class="number">0</span>) {
|
||
|
<span class="ST1">board</span>[row][col - <span class="number">1</span>].unblock();
|
||
|
}
|
||
|
|
||
|
<span class="literal">if</span> (col < <span class="number">7</span>) {
|
||
|
<span class="ST1">board</span>[row][col + <span class="number">1</span>].unblock();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">clearPath</span>() {
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> row = <span class="number">0</span>; row < <span class="ST1">board</span>.<span class="ST1">length</span>; row++) {
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> col = <span class="number">0</span>; col < <span class="ST1">board</span>[row].<span class="ST1">length</span>; col++) {
|
||
|
<span class="ST1">board</span>[row][col].deselectCell();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args) {
|
||
|
<span class="ST4">launch</span>(args);
|
||
|
}
|
||
|
|
||
|
<span class="comment">// Inner class</span>
|
||
|
<span class="literal">class</span> Cell <span class="literal">extends</span> StackPane {
|
||
|
|
||
|
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">marked</span> = <span class="literal">false</span>;
|
||
|
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">visited</span> = <span class="literal">false</span>;
|
||
|
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||
|
|
||
|
<span class="literal">double</span> <span class="ST1">width</span> = <span class="ST1">paneWidth</span> / <span class="number">8</span>;
|
||
|
<span class="literal">double</span> <span class="ST1">height</span> = <span class="ST1">paneHeight</span> / <span class="number">8</span>;
|
||
|
<span class="literal">private</span> Rectangle <span class="ST1">rectangle</span> = <span class="literal">new</span> Rectangle(<span class="number">0</span>, <span class="number">0</span>, <span class="ST1">w</span><span class="ST1">idth</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||
|
|
||
|
Line <span class="ST1">line1</span> = <span class="literal">new</span> Line(<span class="number">0</span>, <span class="number">0</span>, <span class="ST1">w</span><span class="ST1">idth</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||
|
Line <span class="ST1">line2</span> = <span class="literal">new</span> Line(<span class="ST1">w</span><span class="ST1">idth</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="ST1">h</span><span class="ST1">eight</span>);
|
||
|
|
||
|
<span class="literal">public</span> Cell() {
|
||
|
<span class="literal">this</span>.getChildren().add(<span class="ST1">r</span><span class="ST1">ectangle</span>);
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">WHITE</span>);
|
||
|
<span class="ST1">rectangle</span>.setStroke(Color.<span class="ST3">BLACK</span>);
|
||
|
|
||
|
<span class="literal">this</span>.setOnMousePressed(e
|
||
|
-> {
|
||
|
<span class="ST1">marked</span> = !<span class="ST1">marked</span>;
|
||
|
<span class="literal">if</span> (<span class="ST1">marked</span>) {
|
||
|
mark();
|
||
|
} <span class="literal">else</span> {
|
||
|
unmark();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">mark</span>() {
|
||
|
<span class="literal">this</span>.getChildren().addAll(<span class="ST1">l</span><span class="ST1">ine1</span>, <span class="ST1">l</span><span class="ST1">ine2</span>);
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unmark</span>() {
|
||
|
<span class="literal">this</span>.getChildren().remove(<span class="ST1">l</span><span class="ST1">ine1</span>);
|
||
|
<span class="literal">this</span>.getChildren().remove(<span class="ST1">l</span><span class="ST1">ine2</span>);
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">marked</span>() {
|
||
|
<span class="literal">return</span> <span class="ST1">marked</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">visit</span>() {
|
||
|
<span class="ST1">visited</span> = <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">visited</span>() {
|
||
|
<span class="literal">return</span> <span class="ST1">visited</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">blocked</span>() {
|
||
|
<span class="literal">return</span> <span class="ST1">blocked</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">block</span>() {
|
||
|
<span class="ST1">blocked</span> = <span class="literal">true</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">unblock</span>() {
|
||
|
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">selectCell</span>() {
|
||
|
<span class="literal">if</span> (<span class="ST1">rectangle</span>.getFill().equals(Color.<span class="ST3">GREEN</span>)) {
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">YELLOW</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">RED</span>);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">selectCellGreen</span>() {
|
||
|
<span class="literal">if</span> (<span class="ST1">rectangle</span>.getFill().equals(Color.<span class="ST3">RED</span>)) {
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">YELLOW</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">GREEN</span>);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">deselectCell</span>() {
|
||
|
<span class="ST1">rectangle</span>.setFill(Color.<span class="ST3">WHITE</span>);
|
||
|
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||
|
<span class="ST1">visited</span> = <span class="literal">false</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">resetCell</span>() {
|
||
|
<span class="comment">//rectangle.setFill(Color.WHITE);</span>
|
||
|
<span class="ST1">blocked</span> = <span class="literal">false</span>;
|
||
|
<span class="ST1">visited</span> = <span class="literal">false</span>;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
</pre></body>
|
||
|
</html>
|