I'm using Javascript to build my humble robot army.
// Objet Robot
function Robot(nick, pv, maxSpeed, position) {
this.nick = nick;
this.pv = pv;
this.maxSpeed = maxSpeed;
this.position = position;
};
//Méthode présentation des robots
Robot.prototype.sePresenter = function() {
console.log("Bonjour je m'appelle " + this.nick + ". J'ai " + this.pv + " points de vie." + " Je me déplace à " + this.maxSpeed + " cases par seconde. Je suis à la case de coordonnées " + this.position);
};
//Variables array
var robots = [
new Robot('Maurice',95,2,[5,8]),
new Robot('Lilian',76,3,[12,25]),
new Robot('Ernest',100,1,[11,14]),
new Robot('Juliette',87,3,[2,17]),
];
//boucle
robots.forEach(function(robot) {
robot.sePresenter();
});
I would like to add Robot movement. Every turn, a Robot can move a number of space between 1 and its maxSpeed. Each move can be up/down/left/right.
I know I have to use Maths.random
but I can't explain how robots can move.
Here the start of the function
Robot.prototype.seDeplacer = function() {
var point1X = (this.position(Math.random() * this.maxSpeed+1);
var point1Y = (this.position(Math.random() * this.maxSpeed)+1;
console.log("je suis" + point1X + point1Y);
};
robots.forEach(function(robot) {
robot.seDeplacer();
});
Am I on the right track for Robot movement?