2020-04-06 19:23:17 +02:00
|
|
|
//Klasy
|
|
|
|
class Agent {
|
|
|
|
constructor(x, y){
|
|
|
|
this.xField = x;
|
|
|
|
this.yField = y;
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:09:50 +02:00
|
|
|
getId(){
|
2020-04-06 19:23:17 +02:00
|
|
|
return this.xField + "-" + this.yField;
|
|
|
|
}
|
2020-04-06 20:09:50 +02:00
|
|
|
|
|
|
|
right(){
|
|
|
|
this.yField++;
|
|
|
|
}
|
|
|
|
|
|
|
|
left(){
|
|
|
|
this.yField--;
|
|
|
|
}
|
|
|
|
|
|
|
|
up(){
|
|
|
|
this.xField--;
|
|
|
|
}
|
|
|
|
|
|
|
|
down(){
|
|
|
|
this.xField++;
|
|
|
|
}
|
2020-04-06 19:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-04-06 15:21:40 +02:00
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
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
|
2020-04-04 22:44:19 +02:00
|
|
|
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']
|
2020-04-06 20:09:50 +02:00
|
|
|
const agent1 = new Agent(3, 0);
|
2020-04-04 22:44:19 +02:00
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
//Funkcja uruchamiająca prace calego scriptu
|
2020-04-04 22:44:19 +02:00
|
|
|
function start(){
|
2020-04-06 20:09:50 +02:00
|
|
|
//ponumerujPola();
|
2020-04-04 22:44:19 +02:00
|
|
|
pokolorujRegaly();
|
2020-04-06 20:09:50 +02:00
|
|
|
umiescAgenta(agent1);
|
|
|
|
droga(agent1);
|
2020-04-04 22:44:19 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
//Funkcja kolorujaca miejsca na planszy gdzie znajduja sie regaly
|
2020-04-04 22:44:19 +02:00
|
|
|
function pokolorujRegaly(){
|
|
|
|
let x;
|
|
|
|
for(x = 0; x < regaly.length; x++){
|
|
|
|
document.getElementById(regaly[x]).className = 'regal';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
//Funkcja wyswietlajaca id pol
|
2020-04-04 22:44:19 +02:00
|
|
|
function ponumerujPola(){
|
|
|
|
let x,y
|
|
|
|
for(x = 0; x < 7; x++){
|
|
|
|
for(y = 0; y < 11; y++){
|
|
|
|
id = x.toString() + "-" + y.toString();
|
|
|
|
document.getElementById(id).innerHTML = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:09:50 +02:00
|
|
|
//Funkcja usuwająca agenta z pola, przed przemieszczeniem
|
|
|
|
function usunAgenta(agent){
|
|
|
|
document.getElementById(agent.getId()).style.backgroundImage = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
//Funckja wyswietlajaca agenta gdy ten zmieni polozenie
|
2020-04-06 20:09:50 +02:00
|
|
|
function umiescAgenta(agent) {
|
|
|
|
document.getElementById(agent.getId()).style.backgroundImage = "url('Agent.jpg')";
|
2020-04-06 15:21:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 19:23:17 +02:00
|
|
|
//Funkcja zmieniajaca polozenie agenta o 1 pole
|
2020-04-06 20:09:50 +02:00
|
|
|
function przemieszczenie(side, time, agent){
|
|
|
|
const lastPosition = agent.getId();
|
2020-04-06 19:23:17 +02:00
|
|
|
setTimeout(function(){
|
2020-04-06 20:09:50 +02:00
|
|
|
usunAgenta(agent)
|
2020-04-06 19:23:17 +02:00
|
|
|
if(side == "left")
|
2020-04-06 20:09:50 +02:00
|
|
|
agent.left();
|
2020-04-06 19:23:17 +02:00
|
|
|
if(side == "right")
|
2020-04-06 20:09:50 +02:00
|
|
|
agent.right();
|
2020-04-06 19:23:17 +02:00
|
|
|
if(side == "up")
|
2020-04-06 20:09:50 +02:00
|
|
|
agent.up();
|
2020-04-06 19:23:17 +02:00
|
|
|
if(side == "down")
|
2020-04-06 20:09:50 +02:00
|
|
|
agent.down();
|
|
|
|
umiescAgenta(agent);
|
2020-04-06 19:23:17 +02:00
|
|
|
}, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Funkcja ktora ustala droge agenta do przebycia
|
2020-04-06 20:09:50 +02:00
|
|
|
function droga(agent) {
|
|
|
|
przemieszczenie("right", 1000, agent);
|
|
|
|
przemieszczenie("right", 2000, agent);
|
|
|
|
przemieszczenie("up", 3000, agent);
|
|
|
|
przemieszczenie("right", 4000, agent);
|
|
|
|
przemieszczenie("right", 5000, agent);
|
|
|
|
przemieszczenie("right", 6000, agent);
|
|
|
|
przemieszczenie("right", 7000, agent);
|
|
|
|
przemieszczenie("right", 8000, agent);
|
|
|
|
przemieszczenie("right", 9000, agent);
|
2020-04-06 19:23:17 +02:00
|
|
|
}
|