2
0
forked from s444420/AL-2020

Stworzenie agenta i jego okrojonego ruchu

This commit is contained in:
Tomek 2020-04-06 19:23:17 +02:00
parent e123508d38
commit 5358e809ab
5 changed files with 103 additions and 20 deletions

BIN
frontend/Agent.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Inteligentny wózek</title> <title>Inteligentny wózek</title>
<link type="text/css" rel="stylesheet" href="styles.css"> <link type="text/css" rel="stylesheet" href="styles.css">
<script type="module" src="script.js"> <script type="text/javascript" src="script.js">
</script> </script>
</head> </head>
@ -12,7 +12,7 @@
<div class="container"> <div class="container">
<div class="plansza"> <div class="plansza">
<div class="row" id="row-0"> <div class="row" id="row-0">
<div class="pole" id="0-0"> </div> <div class="pole" id="0-0"> </div>
<div class="pole" id="0-1"> </div> <div class="pole" id="0-1"> </div>
<div class="pole" id="0-2"> </div> <div class="pole" id="0-2"> </div>
<div class="pole" id="0-3"> </div> <div class="pole" id="0-3"> </div>

View File

@ -1,13 +1,77 @@
import Agent from '../objects/Agent.js'; //Klasy
class Agent {
constructor(x, y){
this.xField = x;
this.yField = y;
}
getid(){
return this.xField + "-" + this.yField;
}
}
class Field {
constructor(x, y, isEmpty) {
this.xField = x;
this.yField = y;
this.isFieldEmpty = isEmpty;
}
getCoordinates(){
return this.xField + this.yField;
}
getStatus(){
return this.isFieldEmpty;
}
}
class Product {
constructor(name, type, farcing, price) {
this.name = name;
this.type = type;
this.farcing = farcing;
this.price = price
}
}
class Rack{
constructor(noOfShelf, typOfProduct) {
this.noOfShelf = noOfShelf;
}
addShelf(){
this.noOfShelf = this.noOfShelf + 1;
}
isEmpty(){
if (this.noOfShelf === 0){
return true;
}else {
return false;
}
}
}
class Shelf {
constructor(number) {
this.number = number;
}
}
//Objekty i zmienne
var regaly = ['1-1', '1-3', '1-4', '1-6', '1-7', '1-9', '2-1', '2-9', '3-3', '3-4', '3-6', '3-7', '4-1', '4-9', '5-1', '5-3', '5-4', '5-6', '5-7', '5-9'] var regaly = ['1-1', '1-3', '1-4', '1-6', '1-7', '1-9', '2-1', '2-9', '3-3', '3-4', '3-6', '3-7', '4-1', '4-9', '5-1', '5-3', '5-4', '5-6', '5-7', '5-9']
const agent = new Agent(3, 0);
//Funkcja uruchamiająca prace calego scriptu
function start(){ function start(){
ponumerujPola(); ponumerujPola();
pokolorujRegaly(); pokolorujRegaly();
umiescAgenta(); umiescAgenta();
droga();
} }
//Funkcja kolorujaca miejsca na planszy gdzie znajduja sie regaly
function pokolorujRegaly(){ function pokolorujRegaly(){
let x; let x;
for(x = 0; x < regaly.length; x++){ for(x = 0; x < regaly.length; x++){
@ -15,6 +79,7 @@ function pokolorujRegaly(){
} }
} }
//Funkcja wyswietlajaca id pol
function ponumerujPola(){ function ponumerujPola(){
let x,y let x,y
for(x = 0; x < 7; x++){ for(x = 0; x < 7; x++){
@ -25,9 +90,37 @@ function ponumerujPola(){
} }
} }
//Funckja wyswietlajaca agenta gdy ten zmieni polozenie
function umiescAgenta() { function umiescAgenta() {
const agent = new Agent(3, 0); document.getElementById(id).style.backgroundImage = "none";
id = agent.getid(); id = agent.getid();
document.getElementById(id).className = 'regal'; document.getElementById(id).style.backgroundImage = "url('Agent.jpg')";
} }
//Funkcja zmieniajaca polozenie agenta o 1 pole
function przemieszczenie(side, time){
setTimeout(function(){
if(side == "left")
agent.yField--;
if(side == "right")
agent.yField++;
if(side == "up")
agent.xField--;
if(side == "down")
agent.xField++;
umiescAgenta();
}, time);
}
//Funkcja ktora ustala droge agenta do przebycia
function droga() {
przemieszczenie("right", 1000);
przemieszczenie("right", 2000);
przemieszczenie("up", 3000);
przemieszczenie("right", 4000);
przemieszczenie("right", 5000);
przemieszczenie("right", 6000);
przemieszczenie("right", 7000);
przemieszczenie("right", 8000);
przemieszczenie("right", 9000);
}

View File

@ -28,6 +28,8 @@
height: 100px; height: 100px;
width: 100px; width: 100px;
background-color: lightyellow; background-color: lightyellow;
background-image: none;
background-size: cover;
border-color: black; border-color: black;
border-width: 1px; border-width: 1px;
border-style: solid; border-style: solid;
@ -54,4 +56,4 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }

View File

@ -1,12 +0,0 @@
class Agent {
constructor(x, y){
this.xField = x;
this.yField = y;
}
getid(){
return this.xField + "-" + this.yField;
}
}
export default Agent;