Skip to content

Change columns and rows #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ function Button(label, x, y, w, h, callback) {
}
}

function rowNumBox(label, x, y, w, h) {
this.label = label;
this.x = x;
this.y = y;
this.w = w;
this.h = h;

this.show = function() {
stroke(0);
strokeWeight(1);
noFill();
rect(this.x, this.y, this.w, this.h);
fill(0);
noStroke();
text(this.label + rows, this.x + 5, this.y + 5, this.w - 10, this.h - 10);
}
this.mouseClick = function(x, y) {
}
}
function colNumBox(label, x, y, w, h) {
this.label = label;
this.x = x;
this.y = y;
this.w = w;
this.h = h;

this.show = function() {
stroke(0);
strokeWeight(1);
noFill();
rect(this.x, this.y, this.w, this.h);
fill(0);
noStroke();
text(this.label + cols, this.x + 5, this.y + 5, this.w - 10, this.h - 10);
}
this.mouseClick = function(x, y) {
}
}
// Start and end
// start = grid[0][0];
// end = grid[cols - 1][rows - 1];
Expand Down Expand Up @@ -163,6 +201,21 @@ function doGUI() {
}
}

function decRows() {
rows = rows - 10;
}

function incRows() {
rows = rows + 10;
}

function decCols() {
cols = cols - 10;
}

function incCols() {
cols = cols + 10;
}

var gamemap;
var uiElements = [];
Expand All @@ -171,10 +224,9 @@ var pathfinder;
var status = "";
var stepsAllowed = 0;
var runPauseButton;

function initaliseSearchExample(rows, cols) {
mapGraphic = null;
gamemap = new MapFactory().getMap(cols, rows, 10, 10, 410, 410, allowDiagonals, percentWalls);
gamemap = new MapFactory().getMap(cols, rows, 200, 10, 500,500, allowDiagonals, percentWalls);
start = gamemap.grid[0][0];
end = gamemap.grid[cols - 1][rows - 1];
start.wall = false;
Expand All @@ -187,7 +239,7 @@ function setup() {
startTime();

if (getURL().toLowerCase().indexOf("fullscreen") === -1) {
createCanvas(600, 600);
createCanvas(800, 800);
} else {
var sz = min(windowWidth, windowHeight);
createCanvas(sz, sz);
Expand All @@ -196,11 +248,20 @@ function setup() {

initaliseSearchExample(cols, rows);

runPauseButton = new Button("run", 430, 20, 50, 30, runpause);
runPauseButton = new Button("run", 10, 20, 50, 30, runpause);
uiElements.push(runPauseButton);
uiElements.push(new Button("step", 430, 70, 50, 30, step));
uiElements.push(new Button("restart", 430, 120, 50, 30, restart));
uiElements.push(new SettingBox("AllowDiag", 430, 180, allowDiagonals, toggleDiagonals));
uiElements.push(new Button("step", 10, 70, 50, 30, step));
uiElements.push(new Button("restart", 10, 120, 50, 30, restart));
uiElements.push(new SettingBox("AllowDiag", 10, 180, allowDiagonals, toggleDiagonals));

uiElements.push(new Button("<", 0, 250, 15, 30, decRows));
uiElements.push(new rowNumBox("Rows: ", 15, 250, 80, 30));
uiElements.push(new Button(">", 95 ,250, 15, 30, incRows));


uiElements.push(new Button("<", 0, 300, 15, 30, decCols));
uiElements.push(new colNumBox("Cols: ", 15, 300, 80, 30));
uiElements.push(new Button(">", 95, 300, 15, 30, incCols));

recordTime("Setup");
}
Expand Down