diff --git a/frontend/index.html b/frontend/index.html index f65b762..88e9da8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -8,12 +8,11 @@ - +
- \ No newline at end of file diff --git a/frontend/js/Agent.js b/frontend/js/Archiwum/Agent.js similarity index 100% rename from frontend/js/Agent.js rename to frontend/js/Archiwum/Agent.js diff --git a/frontend/js/Board.js b/frontend/js/Archiwum/Board.js similarity index 100% rename from frontend/js/Board.js rename to frontend/js/Archiwum/Board.js diff --git a/frontend/js/Field.js b/frontend/js/Archiwum/Field.js similarity index 100% rename from frontend/js/Field.js rename to frontend/js/Archiwum/Field.js diff --git a/frontend/js/script.js b/frontend/js/Archiwum/script.js similarity index 100% rename from frontend/js/script.js rename to frontend/js/Archiwum/script.js diff --git a/frontend/js/main.js b/frontend/js/main.js index 735d905..4aae68b 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -1,27 +1,146 @@ -import * as Board from './Board.js' -import Agent from './Agent.js' +//Klasy +class Agent{ + constructor(positionX, positionY, turn){ + this.positionX = positionX; + this.positionY = positionY; + this.turn = turn; + } -let board = Board.createBoard(10,10); -Board.showBoard(board); + 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; + } +} + +//funckcje + +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 showBoard(board){ + for(let y = board.length - 1; y >= 0 ; y--){ + document.getElementById("board").innerHTML += "
"; + + for(let x = 0; x < board[y].length; x++){ + document.getElementById("row-" + y).innerHTML += "
" + } + } +} + +let board = createBoard(10,10); let agent = new Agent(0,0, 'Right'); - -agent.showAgent(); - - - - - - - - - - - - - - - - +function start(){ + showBoard(board); + agent.showAgent(); +}