Robot
Move a little robot.
robot.js File Reference

Script for interacting with the robot grid. More...

Functions

function async onKeyDown (event)
 Handle keydown events for moving robot. More...
 
document addEventListener ("keydown", onKeyDown)
 
function async onClick (event)
 Handle click events (on grid or buttons). More...
 
function readCookies ()
 Reads cookies of document. More...
 
function generateGrid (x_coord, y_coord, x_max=5, y_max=5)
 Generate grid given robot's coordinate and size of grid. More...
 
function updateCoords (x_coord, y_coord)
 Updates coordinates written on top of page. More...
 
function replaceGrid ()
 Replace grid by newly generated one (with new robot's coordinates). More...
 

Variables

const robot_grid = document.getElementById("robot-grid")
 
const up_button = document.getElementById("up")
 
const down_button = document.getElementById("down")
 
const right_button = document.getElementById("right")
 
const left_button = document.getElementById("left")
 
const reset_button = document.getElementById("reset")
 

Detailed Description

Script for interacting with the robot grid.

Function Documentation

◆ addEventListener()

reset_button addEventListener ( "keydown"  ,
onKeyDown   
)

◆ generateGrid()

function generateGrid (   x_coord,
  y_coord,
  x_max = 5,
  y_max = 5 
)

Generate grid given robot's coordinate and size of grid.

Parameters
{int}x_coord Robot's x coordinate.
{int}y_coord Robot's y coordinate.
{int}x_max Value max for x (so number of lines in the grid - 1).
{int}y_max Value max for y (so number of columns in the grid - 1).

◆ onClick()

function async onClick (   event)

Handle click events (on grid or buttons).

Parameters
{MouseEvent}event - The click event.

◆ onKeyDown()

function async onKeyDown (   event)

Handle keydown events for moving robot.

Parameters
{KeyboardEvent}event - The keydown event.

◆ readCookies()

function readCookies ( )

Reads cookies of document.

◆ replaceGrid()

function replaceGrid ( )

Replace grid by newly generated one (with new robot's coordinates).

◆ updateCoords()

function updateCoords (   x_coord,
  y_coord 
)

Updates coordinates written on top of page.

Parameters
{int}x_coord Robot's x coordinate.
{int}y_coord Robot's y coordinate.

Variable Documentation

◆ down_button

const down_button = document.getElementById("down")

◆ left_button

const left_button = document.getElementById("left")

◆ reset_button

const reset_button = document.getElementById("reset")

◆ right_button

const right_button = document.getElementById("right")

◆ robot_grid

const robot_grid = document.getElementById("robot-grid")

◆ up_button

const up_button = document.getElementById("up")