Hai Fellas !! saya Farid Hadiyan akan melanjutkan tahap dari progres project game MAZE, Permainan maze adalah permainan edukatif dengan jalan sempit yang berliku dan berbelok dan kadang kala merupakan jalan buntu ataupun jalan yang mempunyai halangan, dapat juga dikatakan permainan mencari jalan keluar.
Untuk tahap awal dapat dilihat melalui link berikut
Untuk tahap sesudah ini dapat dilihat melalui link berikut
void show (int dimension) {
if (dimension > 1 && dimension < 10) _d = dimension;
// Maze
for (int j = 0; j < _h; ++j) {
for (int k = 0; k < _w; ++k) {
color col = red;
int val = _m[j][k];
if (val == VIDE || val == MUR) col = color (0x80, 0x80, 0x80);
else if (val == PAS) col = color (0xFF, 0xFF, 0xFF);
rectMode(CORNER);
fill(col);
rect(k*_d, j*_d, _d, _d);
}
}
// Starting point
fill(red);
rect(_sx*_d, _sy*_d, _d, _d);
// Ending point
fill(green);
rect(_ex*_d, _ey*_d, _d, _d);
}
void checkNode (Node aNode) {
int x = aNode.getX();
int y = aNode.getY();
int distance = aNode.getDistance();
switch (aNode.getDir()) {
case 1: if (TestN (x, y-1)) addNode (x, y-1, distance+1); break; // N
case 2: if (TestE (x+1, y)) addNode (x+1, y, distance+1); break; // E
case 3: if (TestS (x, y+1)) addNode (x, y+1, distance+1); break; // S
case 4: if (TestW (x-1, y)) addNode (x-1, y, distance+1); break; // W
default: break;
}
}
boolean TestN (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y][x+1] == PAS) return false;
return true;
}
boolean TestE (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y][x+1] == PAS) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
boolean TestS (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y][x+1] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
boolean TestW (int x, int y){
if (_m[y][x] != VIDE) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
void reset () {
for (int y = 0; y < _h; ++y) {
for (int x = 0; x < _w; ++x) {
_m[y][x]= VIDE;
}
}
for (int y= 0; y < _h; ++y) {
_m[y][0] = MUR;
_m[y][_w-1] = MUR;
}
for (int x= 0; x < _w; ++x) {
_m[0][x] = MUR;
_m[_h-1][x] = MUR;
}
_sx = int (random (1, _w-1));
_sy = int (random (1, _h-1));
_ex = _sx;
_ey = _sy;
_mx = _sx;
_my = _sy;
_maxdistance=0;
_d = 4;
_dirs = int (random (0, 24));
}
void addNode (int x, int y, int distance) {
// Compute new directions
if (_p > 1) {
if (int(random (0, _p)) == 0) {
_dirs = int(random (0, 24)); // Select moves order
}
}
else {
_dirs = int (random (0, 24)); // Select moves order
}
for (int idx = 0; idx < 4; ++idx) {
int d = dirset[_dirs][idx];
_nodes.add (new Node (x, y, d, distance)); // Adds 4 Nodes
}
_m[y][x] = PAS; // OK we walked on it
if (distance > _maxdistance) {
_maxdistance = distance;
_ex = x;
_ey = y;
}
}
void compute () {
reset ();
addNode (_sx, _sy, 0); // inserting first node
while (true) {
int n = _nodes.size();
if (n == 0) return; // The end
Node node = (Node) _nodes.get(n - 1); // Taking last one
_nodes.remove (n - 1);
checkNode (node);
}
}
int getCell (int y, int x) {
if (x >= _w || x < 0) return 0;
if (y >= _h || y < 0) return 0;
return _m[y][x];
}
int getMaxDistance () { return _maxdistance; }
int getStep () { return _step; }
boolean AtEnd() {
if (_my != _ey) return false;
if (_mx != _ex) return false;
return true;
}
Untuk tahap awal dapat dilihat melalui link berikut
Untuk tahap sesudah ini dapat dilihat melalui link berikut
void show (int dimension) {
if (dimension > 1 && dimension < 10) _d = dimension;
// Maze
for (int j = 0; j < _h; ++j) {
for (int k = 0; k < _w; ++k) {
color col = red;
int val = _m[j][k];
if (val == VIDE || val == MUR) col = color (0x80, 0x80, 0x80);
else if (val == PAS) col = color (0xFF, 0xFF, 0xFF);
rectMode(CORNER);
fill(col);
rect(k*_d, j*_d, _d, _d);
}
}
// Starting point
fill(red);
rect(_sx*_d, _sy*_d, _d, _d);
// Ending point
fill(green);
rect(_ex*_d, _ey*_d, _d, _d);
}
void checkNode (Node aNode) {
int x = aNode.getX();
int y = aNode.getY();
int distance = aNode.getDistance();
switch (aNode.getDir()) {
case 1: if (TestN (x, y-1)) addNode (x, y-1, distance+1); break; // N
case 2: if (TestE (x+1, y)) addNode (x+1, y, distance+1); break; // E
case 3: if (TestS (x, y+1)) addNode (x, y+1, distance+1); break; // S
case 4: if (TestW (x-1, y)) addNode (x-1, y, distance+1); break; // W
default: break;
}
}
boolean TestN (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y][x+1] == PAS) return false;
return true;
}
boolean TestE (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y][x+1] == PAS) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
boolean TestS (int x, int y) {
if (_m[y][x] != VIDE) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y][x+1] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
boolean TestW (int x, int y){
if (_m[y][x] != VIDE) return false;
if (_m[y][x-1] == PAS) return false;
if (_m[y-1][x] == PAS) return false;
if (_m[y+1][x] == PAS) return false;
return true;
}
void reset () {
for (int y = 0; y < _h; ++y) {
for (int x = 0; x < _w; ++x) {
_m[y][x]= VIDE;
}
}
for (int y= 0; y < _h; ++y) {
_m[y][0] = MUR;
_m[y][_w-1] = MUR;
}
for (int x= 0; x < _w; ++x) {
_m[0][x] = MUR;
_m[_h-1][x] = MUR;
}
_sx = int (random (1, _w-1));
_sy = int (random (1, _h-1));
_ex = _sx;
_ey = _sy;
_mx = _sx;
_my = _sy;
_maxdistance=0;
_d = 4;
_dirs = int (random (0, 24));
}
void addNode (int x, int y, int distance) {
// Compute new directions
if (_p > 1) {
if (int(random (0, _p)) == 0) {
_dirs = int(random (0, 24)); // Select moves order
}
}
else {
_dirs = int (random (0, 24)); // Select moves order
}
for (int idx = 0; idx < 4; ++idx) {
int d = dirset[_dirs][idx];
_nodes.add (new Node (x, y, d, distance)); // Adds 4 Nodes
}
_m[y][x] = PAS; // OK we walked on it
if (distance > _maxdistance) {
_maxdistance = distance;
_ex = x;
_ey = y;
}
}
void compute () {
reset ();
addNode (_sx, _sy, 0); // inserting first node
while (true) {
int n = _nodes.size();
if (n == 0) return; // The end
Node node = (Node) _nodes.get(n - 1); // Taking last one
_nodes.remove (n - 1);
checkNode (node);
}
}
int getCell (int y, int x) {
if (x >= _w || x < 0) return 0;
if (y >= _h || y < 0) return 0;
return _m[y][x];
}
int getMaxDistance () { return _maxdistance; }
int getStep () { return _step; }
boolean AtEnd() {
if (_my != _ey) return false;
if (_mx != _ex) return false;
return true;
}
aku mkmentar pertama horeee
BalasHapusMau beli kaos polos premium berkualitas yang murah dimana ya gan?
BalasHapusdi @thebracelet.id aja gan baju pejabat harga merakyat
HapusMantap gan๐๐๐
BalasHapusGasskkeeeuun
Terimakasih, informasinya sangat membantu
BalasHapusmakasih cantik
Hapussangat inspiratif sekali..terimakasih min
BalasHapusmakasih ganteng
Hapuslucu ๐
BalasHapusKomentar ini telah dihapus oleh pengarang.
HapusMaanntuuull๐๐
BalasHapusmakasih gan
Hapusgame maze itu apa ya gan?
BalasHapusgame maze ini semacam game yang dirancang untuk menemukan jalan keluar seperti labirin
Hapuswah keren, sangat bermanfaat ��
BalasHapusterimakasih gan
Hapusterimakasih banyak ya gan
BalasHapusBagus sekali penjelasannya, thanks gan๐
BalasHapus