diff --git a/frontend/js/main.js b/frontend/js/main.js index 42eb6d4..5d174b1 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -120,16 +120,20 @@ class Field{ setIsOccupiedByAgent(isOccupiedByAgent){ this.isOccupiedByAgent = isOccupiedByAgent; } + + setCostOfTravel(costOfTravel){ + this.costOfTravel = costOfTravel; + } } class Shelf{ - constructor(x, y){ - this.xField = x; - this.yField = y; + constructor(accessY, accessX, havePlace, box1, box2, box3){ + this.accessX = accessX; + this.accessY = accessY; this.havePlace = true; - this.box1 = 0; - this.box2 = 0; - this.box3 = 0; + this.box1 = box1; + this.box2 = box2; + this.box3 = box3; } getParams(){ @@ -151,11 +155,11 @@ class Shelf{ } setbox2(box1){ - this.box2 = box1; + this.box2 = box2; } setbox3(box1){ - this.box3 = box1; + this.box3 = box3; } setHavePlace(havePlace){ @@ -163,6 +167,19 @@ class Shelf{ } } +class Candy{ + constructor(type, taste, mark, id){ + this.type = type; + this.taste = taste; + this.mark = mark; + this.id = id; + } + + getId(){ + return this.id; + } + +} //funckcje function createBoard(rangeX, rangeY){ @@ -179,7 +196,7 @@ function createBoard(rangeX, rangeY){ return board } -function createShelf(board){ +function createShelfOnBoard(board){ //pierwszy poziom board[2][2].setIsShelf(true); board[3][2].setIsShelf(true); @@ -215,6 +232,94 @@ function createShelf(board){ return board } +function createCostofField(board, rangeX, rangeY){ + let cost; + let number; + for(let y = 0; y < rangeY; y++){ + for(let x = 0; x < rangeX; x++){ + number = 0; + if(y<9 && board[y+1][x].getIsShelf()){ + number = number + 1; + } + if(y>0 && board[y-1][x].getIsShelf()){ + number = number + 1; + } + if(x<9 && board[y][x+1].getIsShelf()){ + number = number + 1; + } + if(x>0 && board[y][x-1].getIsShelf()){ + number = number + 1; + } + cost = number*2; + if(cost==0){ + cost = 1; + } + board[y][x].setCostOfTravel(cost); + } + } + return board; +} + +function createShelf(){ + const listOfShelf = []; + + //pierwszy poziom + let shelf = new Shelf(2, 1, true, 221, 222, 0); + listOfShelf.push(shelf) + shelf = new Shelf(3, 1, true, 321, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(4, 4, false, 341, 342, 343); + listOfShelf.push(shelf) + shelf = new Shelf(1, 4, true, 0, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(4, 6, true, 361, 362, 0); + listOfShelf.push(shelf) + shelf = new Shelf(1, 6, true, 261, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(3, 9, true, 381, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(2, 9, true, 281, 0, 0); + listOfShelf.push(shelf) + + //drugi poziom + shelf = new Shelf(5, 1, true, 521, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(5, 4, true, 531, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(5, 6, true, 571, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(5, 9, true, 581, 0, 0); + listOfShelf.push(shelf) + + //trzeci poziom + shelf = new Shelf(7, 1, true, 721, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(8, 1, true, 821, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(6, 4, true, 741, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(9, 4, true, 841, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(6, 6, true, 761, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(9, 6, true, 861, 0, 0); + listOfShelf.push(shelf) + + shelf = new Shelf(7, 9, true, 781, 0, 0); + listOfShelf.push(shelf) + shelf = new Shelf(8, 9, true, 881, 0, 0); + listOfShelf.push(shelf) + + + return listOfShelf; +} + function showBoard(board){ for(let y = board.length - 1; y >= 0 ; y--){ document.getElementById("board").innerHTML += "