Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cái hồ
- var fishtank = new Array(12);
- endy = 5;
- endx = 10;
- var nx, ny, x, y;
- for (i=0;i< fishtank.length;i++){
- fishtank[i] = [];
- for (j=0;j<=6;j++){
- fishtank[i][j] = 0;
- }
- }
- for (y=0;y<=6;++y){
- fishtank[0][y]=1;
- fishtank[11][y]=1;
- }
- for (x=0;x<=11;x++){
- fishtank[x][0]=1;
- fishtank[x][6]=1;
- }
- // //////in ra cai ho
- // for (i=0;i<fishtank.length;i++){
- // console.log(fishtank[i]);
- // }
- //class cá
- class Fish{
- constructor(position) {
- atk = 10;
- hp = 1000;
- this.position = position;
- }
- }
- //FISH1
- var fish1 = new Fish();
- x1 = 1;
- y1 = 1;
- //FISH2
- var fish2= new Fish();
- x2 = 1;
- y2 = 1;
- a2 = 0;
- //FISH 3
- var fish3 = new Fish();
- x3 = 1;
- y3 = 1;
- a3 = 0;
- h = 0;
- while (true) {
- //fish 1 changes
- if (x1 == 1) nx1 = 1;
- if (x1 == 10) nx1 = -1;
- if (y1 == 1) ny1 = 1;
- if (y1 == 5) ny1 =- 1;
- //fish 2 changes
- if (x2 == 1) nx2 = 1;
- if (x2 == 10) nx2 = -1;
- if (y2 == 1) ny2 = 1;
- if (y2 == 5) ny2 =- 1;
- //fish3 changes
- if (x3 == 1) nx3 = 1;
- if (x3 == 10) nx3 = -1;
- if (y3 == 1) ny3 = 1;
- if (y3 == 5) ny3 = -1;
- while (h < 20) {
- //fish 1 movement
- fish1.position = [x1,y1];
- fishtank[x1][y1] = 0;
- x1 += nx1;
- y1 += ny1;
- fishtank[x1][y1] = fish1;
- //fish2 movement
- fish2.position = [x2,y2];
- fishtank[x2][y2] = 0;
- if (a2 == 1) {
- x2 += nx2;
- a2 = 0;
- }
- else if (x2 == 10) {
- y2 += ny2;
- a2 += 1;
- }
- else if ((x2 == 1) && (y2 > 1)) {
- y2 += ny2;
- a2 += 1;
- }
- else x2 += nx2;
- fishtank[x2][y2] = fish2;
- //fish 3 movement
- fish3.position = [x3,y3]
- if (a3 == 1){
- y3 += ny3;
- a3 = 0;
- }
- else if (y3 == 5){
- x3 += nx3;
- a3 += 1;
- }
- else if (y3 == 1 && x3 > 1){
- x3 += nx3;
- a3 += 1;
- }
- else y3 += ny3;
- fishtank[x3][y3] = fish3;
- h += 1;
- console.log("fish1", fish1.position, "fish2:", fish2.position,"fish3:",fish3.position);
- if (fishtank[x1+nx1][y1+ny1] == 1) break;
- if (fishtank[x2+nx2][y2] == 1) break;
- if (fishtank[x3][y3+ny3] == 1) break;
- }
- }
- // // FISH 4
- // var fish4 = new Fish();
- // x4 = 1;
- // y4 = 1;
- // while (true) {
- // if (y4 == 1)
- // }
- //attack
- if (fish1.position == fish2.position) {
- fish1.hp += -fish2.atk;
- fish2.hp += -fish1.atk;
- }
- if (fish1.position == fish3.position) {
- fish1.hp += -fish3.atk;
- fish3.hp += -fish1.atk;
- }
- if (fish3.position == fish2.position) {
- fish3.hp += -fish2.atk;
- fish2.hp += -fish3.atk;
- }
- //bait
- var bait = [];
- var N = 5;
- for (i;i>=0;++i){
- if (h%5 == 0) {
- bait[i] = new bait();
- bait[i].position = [bx,by]
- }
- else break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement