Game

Game !

by DupontTD

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
	<session id="aff">
</session>
  <article id="exit">
  <div id="anim-div">
    <pre>coucou</pre>
</div>
<div id="stop">
Stop</div>
</article>
</body>
</html>

CSS

#stop {
  width : 100px;
  background : black;
  color : white;
  border-radius : 20px;
  height : ;
  text-align : center;
	margin : 5px;
}

#aff {
	background-color : "yellow";
  display : grid;
  grid-auto-rows: 20px;
  grid-auto-columns :20px;	
}  

.Empty{
	background-color :white;
}

.Dirty{
	background-color : black;
}

.Wall{
	background-color : gray;
}

.Exit{
	border : 1px dotted;
	background-color : green;
}

.BouncingCritter{
	background-color : red;
//	width : 10px;
//	height : 10px;
	border-radius : 50%;
	//align-self: end;
}

 .WallFollower{
  border-width:5px;  
  border-style:inset;
	background-color : green;

}

div {
	border-radius : 50%;
}

JavaScript

/*const  Plateau = 
			     ["############################",
						"                            ",
						"                            ",
						"                            ",
						"            o               ",
						"                            ",
						"                            ",
						"            o               ",
						"                            ",
						"                            ",
						"############################"];

*/
const  Plateau = 
			     ["############################",
            "#      #    #      o      ##",
            "#    o  o ~                #",
            "E       E                  #",
            "#####       E  #    ## E   #",
            "###                 #      #",
            "#   #  ~    ###      #     #",
            "# #####             o      #",
            "#  o  #    ###             #",
            "#   oo##       o       ### #",
            "#      #                   E",
            "###############EEE##########"];
						

/*
const  Plateau = ["  ",
                  " o"];
*/

function dirPlus(dir, n) {
	console.log(` dir : ${dir} , n : ${n} `);
  var index = directionNames.indexOf(dir);
  return directionNames[(index + n + 8) % 8];
}

class WallFollower {
	
	 constructor (){
      this.dir = "n";
  }

  act(view) {
  let start = this.dir;
  if (view.look(dirPlus(this.dir, -3)) != " ")
    start = this.dir = dirPlus(this.dir, -2);
  while (view.look(this.dir) != " ") {
    this.dir = dirPlus(this.dir, 1);
    if (this.dir == start) break;
  }
  return {type: "move", direction: this.dir};
  }

}
           

let nbo=0;
    nbDirty=0;

class BouncingCritter {
  constructor (){
    this.direction = randomElement(directionNames);
  }
  
  act(view) {

    if (view.look(this.direction) == "E"){
       console.log("exit");
       return {type: "exit", direction: this.direction};
    }
    
    if (view.look(this.direction) != " "){
       this.direction = view.find(" ") || "s";
    }
    
    return {type:...