Repository for the Math Attack! online game
Contents
This is a simple online game for reviewing basic arithmetic concepts. It's written in the TypeScript dialect of JavaScript, and it uses the Vue framework for a modern user experience.
- Fork and clone this repository to your local computer
- Run
npm i
to install all dependencies locally (if you run into conflicts with module versions, trynpm i --legacy-peer-deps
)
- Run
npm run serve
within your local directory - View the live version of the site at
http://localhost:8080
Alternatively, you may use the live version of the Math Attack! app, deployed via Netlify
- Fully functional, playable game with win and lose conditions
- Unlimited question bank since questions generated dynamically instead of being accessed statically
- Score board in the header, so user can easily always view their score, strikes, and remaining time
- Feedback for all questions to inform users of correct answers before moving on to a new question
- Routing for separate pages to move beyond SPA basics
- Native storage for state management via Vue's Reactivity API
- Test suites for every major file
Helper function to create a new question
function generateQuestion(
level: number,
type: string,
previous?: string
): IQuestion {
const symbol: string = selectSymbol(type)
const pair: IPair = generatePair(level, type)
const answer: number = generateAnswer(pair.firstNumber, pair.secondNumber, type)
const choices: number[] = generateChoices(answer, pair.firstNumber, pair.secondNumber, type)
const question: string = `${pair.firstNumber} ${symbol} ${pair.secondNumber}`
let result: IQuestion = {
question,
choices
}
if (
previous === result.question ||
Math.floor(answer) !== answer
) {
result = generateQuestion(level, type, previous)
}
return result
}
Store to simplify state management across app with accessor and mutators
export default reactive(<IScore>{
value: 0,
increment(points: number) {
this.value += points
},
decrement(points: number) {
this.value -= points
},
reset() {
this.value = 0
}
})
Custom composable to simplify navigation
function useLandingPages(): LandingPagesComposable {
const router: Router = useRouter()
function goHome(): void {
router.push('/home')
}
function playGame(): void {
router.push('/question')
}
function readInstructions(): void {
router.push('/instructions/1')
}
return {
goHome,
playGame,
readInstructions
}
}
Vue component with template to dynamically display content
<template>
<article>
<p :class="props.styling">
{{ feedback }}
</p>
<GenericButton
:text="buttonText"
@click="handleClick"
/>
</article>
</template>
This repository uses Jest for testing. It should be one of the dev dependencies initially installed.
- The app features 254 passing automated tests
- To check them, run
npm run test
- More tests to increase code coverage, handle edge cases, and test UI's functionality, which may require implementing Cypress for integration tests
- Improve styling for a more enjoyable user experience