//mengurangi nilai matrix ketika pentomino dikeluarkan dari board public void delMatrixBoard(int i, int j, Pentominos p) { int x, y; Boolean oke = false; for (int a = 0; a < 5; a++) { for (int b = 0; b < 5; b++) { if (p.getMatrix()[a, b] == 1) { oke = true; x = i + a; y = j + b; matrix[x, y]--; } else { if (!oke) { j--; } } } } }
//melakukan penempatan pentomino pada posisi x, y public void place_pentomino(Pentominos p, int x, int y) { int lalaye = 0; Boolean laye = false; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (p.getMatrix()[i, j] == 1) { p.SetPos(x, y - lalaye); laye = true; break; } else { lalaye += 25; } } if (laye) { break; } } }
//mengecek apakah terdapat pentomino yang bertumpukan public Boolean pentominoCollision(Pentominos p, int z) { for (int j = 0; j < 12; j++) { for (int a = 0; a < 5; a++) { for (int b = 0; b < 5; b++) { if (p.getMatrix()[a, b] == 1) { for (int c = 0; c < 5; c++) { for (int d = 0; d < 5; d++) { if (pentomino[j].getMatrix()[c, d] == 1) { if (p.GetX() + (a * 25) == pentomino[j].GetX() + (c * 25) && p.GetY() + (b * 25) == pentomino[j].GetY() + (d * 25) && z != j) { return(true); } } } } } } } } return(false); }
// mengeset nilai ketika ada pentomino dimasukan public Boolean setMatrixBoard(int i, int j, Pentominos p) { int x, y; int ia = i; int ja = j; Boolean notvalid = false; Boolean oke = false; for (int a = 0; a < 5; a++) { for (int b = 0; b < 5; b++) { if (p.getMatrix()[a, b] == 1) { oke = true; x = i + a; y = j + b; if (!isValid(i, j, p)) { notvalid = true; break; } matrix[x, y]++; } else { if (!oke) { j--; } } } if (notvalid) { break; } } if (notvalid) { return(false); } if (isCollisionOnBoard()) { delMatrixBoard(ia, ja, p); return(false); } else { return(true); } }