Notes
Notes - notes.io |
var arr = new Array(cols);
for (var i = 0; i < arr.length; i++) {
arr[i] = new Array(rows);
}
return arr;
}
function Cell(x, y, w, fp, sp, bomb) {
this.x = x;
this.y = y;
this.w = w;
this.firstplayer = fp;
this.secondplayer = sp;
this.bomb = bomb;
if (this.x === 0 || this.y === 0 || this.x / w == rows - 1 || this.y / w == cols - 1) this.type = 0
else this.type = floor(random(0, 3));
}
Cell.prototype.show = function() {
if (this.type === 0) {
fill(255);
rect(this.x, this.y, this.w, this.w);
} else if (this.type == 1) {
fill(255, 205, 0);
rect(this.x, this.y, this.w, this.w);
} else {
fill('black');
rect(this.x, this.y, this.w, this.w);
}
if (this.firstplayer) {
fill('red');
rect(this.x + 12, this.y + 12, 15, 15);
}
if (this.secondplayer) {
fill('blue');
rect(this.x + 12, this.y + 12, 15, 15);
}
if (this.bomb) {
fill('black');
ellipse(this.x+20, this.y+20, 15, 15);
}
}
Cell.prototype.isPlayer = function(x) {
if (x == 1) {
if (this.firstplayer) return true;
else return false;
} else if (x == 2) {
if (this.secondplayer) return true;
else return false;
}
}
Cell.prototype.SetOffPlayer = function(x) {
if (x == 1) this.firstplayer = false;
else if (x == 2) this.secondplayer = false;
}
Cell.prototype.SetOnPlayer = function(x) {
if (x == 1) this.firstplayer = true;
else if (x == 2) this.secondplayer = true;
}
Cell.prototype.CheckType = function() {
if (this.type === 0) return true;
else return false;
}
Cell.prototype.CallBomb = function() {
this.bomb = true;
}
Cell.prototype.DestroyBare = function() {
if (this.type === 0 || this.type == 1) this.type = 0
}
var field;
var checkcell = false;
var cols = 15;
var rows = 15;
var w = 40; /// 30x30
function setup() {
createCanvas(605, 605);
field = make2DArray(cols, rows);
field[0][0] = new Cell(0, 0, w, true, false, false);
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
if (i !== 0 || j !== 0) field[i][j] = new Cell(i * w, j * w, w, false, false, false);
}
}
field[cols - 1][rows - 1] = new Cell((cols - 1) * w, (rows - 1) * w, w, false, true, false);
}
function draw() {
background(255);
noCursor();
for (var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
field[i][j].show();
}
}
}
function keyPressed() {
if (keyIsDown(68)) { ////////D
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (field[i][j].isPlayer(1)) {
checkcell = true;
if (i < cols - 1)
if (field[i + 1][j].CheckType()) {
field[i][j].SetOffPlayer(1);
field[i + 1][j].SetOnPlayer(1);
}
}
if (checkcell) break;
}
if (checkcell) break;
}
checkcell = false;
} else if (keyIsDown(65)) { ////////A
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (field[i][j].isPlayer(1)) {
checkcell = true;
if (i > 0)
if (field[i - 1][j].CheckType()) {
field[i][j].SetOffPlayer(1);
field[i - 1][j].SetOnPlayer(1);
}
}
if (checkcell) break;
}
if (checkcell) break;
}
checkcell = false;
} else if (keyIsDown(83)) { ////////S
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (field[i][j].isPlayer(1)) {
checkcell = true;
if (j < rows - 1)
if (field[i][j + 1].CheckType()) {
field[i][j].SetOffPlayer(1);
field[i][j + 1].SetOnPlayer(1);
}
}
if (checkcell) break;
}
if (checkcell) break;
}
checkcell = false;
} else if (keyIsDown(87)) { ////////W
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (field[i][j].isPlayer(1)) {
checkcell = true;
if (j > 0)
if (field[i][j - 1].CheckType()) {
field[i][j].SetOffPlayer(1);
field[i][j - 1].SetOnPlayer(1);
}
}
if (checkcell) break;
}
if (checkcell) break;
}
checkcell = false;
} else if (keyIsDown(32)) {
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
if (field[i][j].isPlayer(1)) {
checkcell = true;
field[i][j].CallBomb();
if (i>1) field[i-1][j].DestroyBare();
if (j>1) field[i][j-1].DestroyBare();
if (i<rows-1) field[i+1][j].DestroyBare();
if (j<cols-1) field[i][j+1].DestroyBare();
}
if (checkcell) break;
}
if (checkcell) break;
}
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team