Giter Site home page Giter Site logo

reactive-snake's Introduction

reactive-snake

Taming snakes with reactive streams

Overview

This repo includes the source code for a series of posts on reactive-snake. Each part builds on top of the previous one and adds features on top. Here's a quick overview:

  • Part 1: Basic features
  • Part 2: Advanced features

Remember, if you clone this repo you'll sit on the latest commit. There's a tag for each part that you can checkout. Alternatively, you browse through the source code on GitHub.

Install

Clone this repo and execute the following command in your favorite shell:

  • npm install or short npm i

Play

After you have installed all dependencies you can now run the app:

  • npm start will build the application and start a local server using webpack-dev-server to watch, re-build (in-memory) and reload the app on each change.

  • npm run build or npm run build:prod can be used to prepare a distribution bundle.

Finally, open a browser and navigate to localhost:9000.

Have fun!

reactive-snake's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reactive-snake's Issues

there is a bug

Suppose now that the snake is moving to the "right". I quickly press the "up" and "left" directions keys in the speed time. The direction$ will push the "up" and "left", but withLatestFrom only Taking "Left", "Up" will be ignored, causing the snake to immediately go to the "Left" and collide with itself.

So both ticks$ and direction$ should make the snake moving.

I think change snake$ to be like this will resolve this bug:

let snake$: Observable<Array<Point2D>> = combineLatest(ticks$, direction$).pipe(
    withLatestFrom(snakeLength$, ([_, direction], snakeLength) => [direction, snakeLength]),
    scan(move, generateSnake()),
    share()
  );

There are some unnecessary code here

  let length$ = new BehaviorSubject<number>(SNAKE_LENGTH);

  let snakeLength$ = length$.pipe(
    scan((step, snakeLength) => snakeLength + step),
    share()
  );

I think BehaviorSubject is multicast, share should not be used

How to restart the game?

Hey, I just built this in Angular 7 following your guide. I tried to get the game to restart on click by unsubscribing all Observables, then calling a function to recreate them and clear the canvas. But it doesn't seem to work. Any advice on restarting the game?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.