diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..06b6028 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,47 @@ +{ + "parser": "babel-eslint", + "extends": [ + "standard", + "plugin:react/recommended", + "prettier", + "prettier/react", + "prettier/standard" + ], + "plugins": ["react", "prettier", "standard"], + "parserOptions": { + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "env": { + "es6": true, + "node": true + }, + "rules": { + "prettier/prettier": [ + "error", + { + "printWidth": 80, + "tabWidth": 2, + "singleQuote": true, + "trailingComma": "all", + "bracketSpacing": false, + "semi": false, + "useTabs": false, + "parser": "babylon", + "jsxBracketSameLine": true + } + ], + "eqeqeq": ["error", "always"], + "space-before-function-paren": 0, + "generator-star-spacing": 0, + "react/prop-types": 0, + "react/display-name": 0, + "import/no-unresolved": [1, {"commonjs": true, "amd": true}], + "import/named": 2, + "import/namespace": 2, + "import/default": 2, + "import/export": 2 + } +} diff --git a/game.js b/game.js deleted file mode 100644 index 2a05043..0000000 --- a/game.js +++ /dev/null @@ -1,283 +0,0 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - * @flow - */ - -import React, { Component } from 'react'; -import { - StyleSheet, - Text, - View, - Image, - Button, - TouchableHighlight, - AsyncStorage, -} from 'react-native'; -const STORAGE_KEY = '@Game:data'; -var timeLimit=10; -var timer = null; -var Turtle = React.createClass({ - render(){ - return( - - {this.props.show ? '🐢':''} - - ) - } -}) - -export default class Game extends Component { - - constructor(){ - super(); - this.state ={ - highScore: 0, - currentScore: 0, - timeout: 0, - playing: false, - holes: [false, false, false, - false, false, false, - false, false, false] - } - } - - _startGame(){ - this.setState({ - timeout: timeLimit, - playing: true, - currentScore: 0, - }); - - appear = setInterval(()=>{ - var currentHoles = this.state.holes; - var randomNumber = Math.floor(Math.random()*9); - if(currentHoles[randomNumber]==false){ - currentHoles[randomNumber] = true; - setTimeout(function(){currentHoles[randomNumber]= false},2000); - // if(!Math.floor(Math.random()*3)){ - // currentHoles = [false, false, false, false, false, false, false, false, false]; - // } - this.setState({ holes: currentHoles }) - } - - - if(!this.state.playing){ - clearInterval(appear); - this.setState({ holes: [false, false, false, false, false, false, false, false, false] }) - } - - },1000); - - - timer = setInterval(()=>{ - this.setState({ - timeout: this.state.timeout - 1, - }); - if(this.state.timeout == 0){ - this._stopGame(); - } - }, 1000); - } - - _handleTouch(holeNumber){ - currentHoles = this.state.holes; - if(currentHoles[holeNumber]==true){ - currentHoles[holeNumber]=false; - this.setState({ - currentScore: this.state.currentScore +1, - holes: currentHoles, - }) - } - } - - _stopGame(){ - clearInterval(timer); - this.setState({ - playing: false, - }) - if(this.state.currentScore>this.state.highScore){ - alert('YEAH! you got a new high score'); - this.setState({ - highScore: ""+this.state.currentScore, - }) - } - this._save(); - } - - - _save(){ - AsyncStorage.setItem(STORAGE_KEY, this.state.highScore) - .then(()=>console.log('data has been saved')) - .catch((error)=>console.log('AsyncStorage: '+ error.message)) - .done(); - } - - componentDidMount(){ - AsyncStorage.getItem(STORAGE_KEY) - .then((value)=>{ - this.setState({ - highScore: value, - }) - }).catch((error)=>console.log('AsyncStorage: '+ error.message)) - .done(); - } - - render() { - return ( - - - - High Score - {this.state.highScore} - - - Timeout - {this.state.timeout} - - - Score - {this.state.currentScore} - - - - - - this._handleTouch(0)}/> - - - this._handleTouch(1)}/> - - - this._handleTouch(2)}/> - - - - - this._handleTouch(3)}/> - - - this._handleTouch(4)}/> - - - this._handleTouch(5)}/> - - - - - this._handleTouch(6)}/> - - - this._handleTouch(7)}/> - - - this._handleTouch(8)}/> - - - - -