Coder Social home page Coder Social logo

snake's People

Contributors

jackherizsmith avatar jamesj-0 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

bobbysebolao

snake's Issues

Make repo public

Your repo is currently private, which means no one outside the fac19 GitHub organisation can see it. This will be a problem when a graduate tries to code review the project tomorrow/Friday.

Could you make it public please? :)

Show score

  • - increase score when the snake eats a food

CSS - Using a :focus pseudo-class and labels on level buttons

CSS: The hover on the snakes looks really cool. You could add a :focus pseudo-class so it stays highlighted after you've selected it. Same with the levels.

hahaa love the levels. Perhaps show difficulty levels for those less politically inclined (easy, medium, impossible)

Sssssssuperb job!

Hey frens, this is such a cool take on Snake!!! The decrementing score counter is funny, and the reward of seeing a new GIF each time you get a new vote is a nice incentive to keep playing 💯

My favourite detail is the way each block of the snake animates to make it look stretchy and slithery. And the way the tail is slightly more opaque than the head. It's a really nice touch!

As for the code/logic, I will take a look and leave you some feedback in separate issues

(update: it's not allowing me to add labels to these issues, feel free to add the code review label yourselves)

topnotch

Sophisticated use of React

I learnt a load of stuff reading this, including:

  • function invocation when you pass a function to useState
  • useRef

Possibility for refactor

in snake.js instead of a big if-else you could just do a ternary inside the {}, or alternately do a small if-else before the return statement that assigns the data to a variable, then put the variable inside the {}. Then you could keep your code DRY by not repeating the HTML tags.

Allow users to disable animation

This is an accessibility thing: people with certain vestibular disorders struggle with UIs containing lots of motion. There's also the obvious problem for people with photosensitive epilepsy—some of the gif backgrounds flash really fast and could be dangerous.

Modern browsers support a new media query called prefers-reduced-motion that will tell you if the user has opted out of animations etc in their operating system settings. You can detect this and hide gifs/disable CSS animations

Blue flash when GIF is loading

There is a brief blue flash that occurs when you eat food and a new GIF loads (I don't think it shows in the GIF below though :( ):

fa827fddb6614357638f3d83aa8b8368

It looks like there is a brief moment when the backgroundUrl of the game-area div is set to nothing before the new one loads. One way to stop the flash from happening is to set the GIF as the src on an <img /> tag inside the if (gameplay) { ... block starting on line 136 of App.js:

  if (gamePlay) {
    return (
      <div
        className="game-area"
      >
        <img 
        src={
          `https://media.giphy.com/media/${
            backgroundURL ? backgroundURL : initialState.id
          }/giphy.gif`
        }
        alt="alt-text-goes-here"
        />

...
...
...

}

Just doing the above seemed to fix issue locally for me 💥. Apparently the so-called 'Flash Of Unstyled Content' (or FOUC) is a common problem in React apps. Here's a thread on how to handle it in other situations, like when there are slow loading images on page load

Issue with seeing all content of page

Cannot see div with 'how to play' information as not able to scroll down page. When I resize the page this means I cannot select the 'GO' button.

Component naming convention

This is a minor comment, I noticed you've capitalised the name of the top level App component file in your application, and that the other component file names (characterSelector.js, food.js, score.js, snake.js) aren't capitalised. I'd recommend sticking to one naming convention - the one that is commonly recommended for React apps is to capitalise all component names (which you've quite rightly done 👍 ) and the names of the files and folders that contain those components (Food.js, Score.js, etc.) :)

Fetch not working properly?

The fetch request doesn't work for me, either locally or on the deployed site, but do work for James. Not sure if this is a code issue or a my laptop issue?

Importing components/utils from index files

At the top of App.js:

import React, { useState, useEffect } from 'react'
import Score from './components/score'
import Snake from './components/snake'
import Food from './components/food'
import CharacterSelector from './components/characterSelector'
import getRandomCoordinates from './utils/getRandomCoordinates'
import initialState from './utils/initialState'
import onKeydown from './utils/keyDown'
import getGif from './utils/getSnake'
import useInterval from './utils/useInterval'

one thing you might like to try as your app increases in complexity is to import all of the components and utils that you need from an index.js file (instead of importing them from the individual component/util files). When you start having more components/utils, using index files can help keep things easy to read in App.js.

E.g. if you were to use this file structure to organise your components, you'd create an index.js file in your components folder, from which you'd export an object containing all your components from it:

components/index.js

import CharacterSelector from './characterSelector';
import Food from './food';
import Score from './score';
import Snake from './snake';

export { CharacterSelector, Food, Score, Snake };

You'd import this index file in App.js, and use ES6 object destructuring to unpack the components from it (exactly the same as you've done to access the useState and useEffect methods from the React object):

import React, { useState, useEffect } from 'react'
import { CharacterSelector, Food, Score, Snake } from './components/index'

(hope this reads clearly, but if it doesn't than do give me a shout!)

Nice folder structure

Nice job creating components and utils folders for your components and general purpose application logic!

Utilizing css imports for components

You can separate your CSS out based on the specific component. For example for the food.js component file create a style sheet called food.css and in food.js import it with import ./food.css

Good place for a comment?

The onKeyDown function is really interesting - I notice you plan to mention it in the presentation, which I'm looking forward to because tbh I don't get it. It might also be good to include an explanatory comment for yourself six months down the line.

React Fragments: the miracle cure for div-itis!

In case you don't know, React provides a component called Fragment that you can use in place of a div to group together JSX elements inside a return block. You can import it from React and use it exactly like you would use a div, the advantage is that it Fragments don't appear in the rendered HTML page (in other words, it doesn't clutter the web page with semantically meaningless divs) :

import React, { Fragment } from 'react'

export default ({ startGame, topScore, chooseCharacter, chooseDifficulty }) => {
  return (
    <Fragment>
       ...
       ...
       ...
       ...
       ...
    </Fragment>
  )
}

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.