import React from "react"; import styled, { css } from "styled-components"; import Title from "../components/Title.js"; import PageSection from "../components/PageSection.js"; import Code from "../components/Code.js"; import Button from "../components/Button.js"; import Link from "../components/Link.js"; const MainPageSection = styled(PageSection)` background-color: ${({ theme }) => theme.colors.pageSectionMainColor}; min-height: 20rem; ${PageSection.Content} { box-sizing: border-box; padding: 1rem 2rem; } `; const StandardPageSection = styled(PageSection)` background-color: ${({ theme }) => theme.colors.pageSectionStandardColor}; ${PageSection.Content} { box-sizing: border-box; padding: 2rem 8rem; } `; const AlternatePageSection = styled(PageSection)` background-color: ${({ theme }) => theme.colors.pageSectionAlternateColor}; ${PageSection.Content} { box-sizing: border-box; padding: 2rem 8rem; } `; const Icon = styled.div` font-size: 150pt; display: inline-block; `; const Layout = styled.div` display: flex; width: 100%; // place-content: center; // justify-content: space-around; // align-content: space-around; margin-top: 2rem; ${({ direction }) => direction === "horizontal" && css` flex-direction: row; `} ${({ direction }) => direction === "vertical" && css` flex-direction: column; `} `; const StyledAboutPage = styled.div` font-size: 1.5rem; `; const KeyMapTable = styled.table` margin: 3rem 0; thead td { font-size: 0.7em; color: ${({ theme }) => theme.colors.colorAlternate}; } td:nth-child(1), td:nth-child(2) { padding: 0 1rem; text-align: center; } td:nth-child(3) { padding: 0 1rem; line-height: 2.3rem; font-size: 0.8em; } `; export const About = () => ( Crafity Snake Play snake with HTML 5 and Javascript. 🐍 Introduction

This game has been created as a Crafity experiment to test out React, Redux and Styled Components and see if it is possible to create a simple web based game like snake. The{" "} source code {" "} for this game is open source and free to download and change.

A couple of noticeable features in this game are resumable game play using local storage. The page can be reloaded or reopened any time and the game should continue from where it was left.

How to play

In this game you play a snake and the goal is to eat as many apples as possible. Every time your snake eats an apple its tail grows a little bit longer and you earn a point. If your snake touches its own tail or one of the four walls* it will die.

* Only when allow wrapping is turned off

Key Alternative r (Re)start the game s Stop the game p Pause the game h Left j Down k Up l Right w Allow Wrapping + = Increase FPS - Decrease FPS 0...9 Zoom level

Technology

Snake has been developed with the folowing technologies.

  • React
  • React Router
  • Redux
  • Styled Components
  • Webpack
  • Babel
  • Font Awesome
  • Jest
  • ESLint
  • pre-commit
  • Docker
React Logo Redux Logo Styled Components Logo Font Awesome Logo Webpack Logo Jest Logo Docker Logo State Management

All the game and UI state is managed with Redux. This means all the state is stored in a central state store. Every second the state is serialized and stored in the browser"s localStorage. This makes the game fully resumable.

Change is changed using Redux reducers and the orchistration of actions is handled by Redux Middleware.

Styling

All the styling and theming is handled by the module styled-components. Styled-components let"s you style your react components directly from your Javascript code.

Source Code

The source code is hosted on Crafity's Gitea environment at the following location:

Download here

The source code is MIT licensed. Feel free to make modifications and share. Suggestions and pull requests are welcome. Use Crafity"s git repository to file issues and pull requests.

Running Snake

After donwloading the source code run the following commands:

$ npm install

$ npm run dev

); export default About;