8000 GitHub - nabchar/FiefDOM_demo: A simple implementation of the classic game of Snake using the custom DOM manipulation library FiefDOM.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple implementation of the classic game of Snake using the custom DOM manipulation library FiefDOM.

Notifications You must be signed in to change notification settings

nabchar/FiefDOM_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiefDOM_demo

A simple implementation of the classic game of Snake using the custom DOM manipulation library FiefDOM.

Game Set-up

FiefDOM's wrapper function allows us to grab the element in that DOM where we will inject the game board. In addition, we place an event listener on the play button, passing in callback that will generation a new iteration of the game on each click.

$f(function () {
  const rootEl = $f('.snake-game');
  const setUp = new SnakeView(rootEl)
71C6
;

  window.clearInterval(setUp.intervalId);
  const playButton = $f('.play');

  playButton.on("click", () => {
    new SnakeView(rootEl);
  });
});

Gameplay

FiefDOM's event handling functions are used to listen for keydown actions by the user.

  $f(window).on("keydown", this.handleKeyEvent.bind(this));

Game-Over Message

When the player inevitably loses (because Snake is hard!), FiefDOM's AJAX is utilized to fire off a request to Giphy to display an informative "Game Over" GIF to the user.

The request returns a Promise, which is resolved with a function that inserts the GIF into an image tag via FiefDOM's #attr method.

const fetchGiphy = () => {
  let offset = Math.floor(Math.random() * 100);
  return $f.ajax({
    method: 'GET',
    url:`http://api.giphy.com/v1/gifs/search?q=game+over&api_key=dc6zaTOxFJmzC&limit=1&offset=${offset}`
  });
}

fetchGiphy().then((res) => {
  $f('#game-over').attr("src", res.data[0].images.downsized.url)
  modal.style.display = "block";
});

About

A simple implementation of the classic game of Snake using the custom DOM manipulation library FiefDOM.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0