//Klasy class Agent{ constructor(positionX, positionY, turn){ this.positionX = positionX; this.positionY = positionY; this.turn = turn; } getParams(){ let params = {}; positionX = this.positionX; positionY = this.positionY; turn = this.turn; params = {positionX, positionY, turn}; return params; } goForward(){ if(this.turn == 'Up'){ this.positionY += 1; } else if(this.turn == 'Down'){ this.positionY -= 1; } else if(this.turn == 'Left'){ this.positionX -= 1; } else if(this.turn == 'Right'){ this.positionX += 1; } } turnLeft(){ if(this.turn == 'Up'){ this.turn = 'Left'; } else if(this.turn == 'Down'){ this.turn = 'Right'; } else if(this.turn == 'Left'){ this.turn = 'Down'; } else if(this.turn == 'Right'){ this.turn = 'Up' } } turnRight(){ if(this.turn == 'Up'){ this.turn = 'Right'; } else if(this.turn == 'Down'){ this.turn = 'Left'; } else if(this.turn == 'Left'){ this.turn = 'Up'; } else if(this.turn == 'Right'){ this.turn = 'Down' } } showAgent(){ console.log(this.turn) if(this.turn === "Up"){ document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Up.png')"; } else if(this.turn === "Down"){ document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Down.png')"; } else if(this.turn === "Right"){ document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Right.png')"; } else if(this.turn === "Left"){ document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Left.png')"; } } hideAgent(){ document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = ""; } } class Field{ constructor(x, y, isShelf, isOccupiedByAgent, costOfTravel){ this.xField = x; this.yField = y; this.isShelf = isShelf; this.isOccupiedByAgent = isOccupiedByAgent; this.costOfTravel = costOfTravel; } getParams(){ let params = {}; xField = this.xField; yField = this.yField; isShelf = this.isShelf; isOccupiedByAgent = this.isOccupiedByAgent; costOfTravel = this.costOfTravel; params = {xField, yField, isShelf, isOccupiedByAgent, costOfTravel} return params; } setIsShelf(isShelf){ this.isShelf = isShelf; } getIsShelf(){ return this.isShelf; } setIsOccupiedByAgent(isOccupiedByAgent){ this.isOccupiedByAgent = isOccupiedByAgent; } } class Shelf{ constructor(x, y){ this.xField = x; this.yField = y; this.havePlace = true; this.box1 = 0; this.box2 = 0; this.box3 = 0; } getParams(){ let params = {}; xField = this.xField; yField = this.yField; havePlace = this.havePlace; box1 = this.box1; box2 = this.box2; box3 = this.box3; params = {xField, yField, havePlace, box1, box2, box3} return params; } setbox1(box1){ this.box1 = box1; } setbox2(box1){ this.box2 = box1; } setbox3(box1){ this.box3 = box1; } setHavePlace(havePlace){ this.havePlace = havePlace; } } //funkcje function createBoard(rangeX, rangeY){ const board = []; for(let y = 0; y < rangeY; y++){ const row = []; for(let x = 0; x < rangeX; x++){ let field = new Field(x, y, false, false, 1); row.push(field) } board.push(row) } return board } function createShelf(board){ //pierwszy poziom board[2][2].setIsShelf(true); board[3][2].setIsShelf(true); board[2][4].setIsShelf(true); board[3][4].setIsShelf(true); board[2][6].setIsShelf(true); board[3][6].setIsShelf(true); board[2][8].setIsShelf(true); board[3][8].setIsShelf(true); //drugi poziom board[5][2].setIsShelf(true); board[5][3].setIsShelf(true); board[5][7].setIsShelf(true); board[5][8].setIsShelf(true); //trzeci poziom board[7][2].setIsShelf(true); board[8][2].setIsShelf(true); board[7][4].setIsShelf(true); board[8][4].setIsShelf(true); board[7][6].setIsShelf(true); board[8][6].setIsShelf(true); board[7][8].setIsShelf(true); board[8][8].setIsShelf(true); return board } function showBoard(board){ for(let y = board.length - 1; y >= 0 ; y--){ document.getElementById("board").innerHTML += "
"; for(let x = 0; x < board[y].length; x++){ if(board[y][x].getIsShelf()) document.getElementById("row-" + y).innerHTML += "
" else document.getElementById("row-" + y).innerHTML += "
" } } } let board = createBoard(10,10); board = createShelf(board); let agent = new Agent(0,0, 'Right'); function start(){ let board = createBoard(10,10); let agent = new Agent(0,0, 'Right'); showBoard(board); agent.showAgent() }