mirror of
https://github.com/Xevion/power-math.git
synced 2025-12-09 16:08:02 -06:00
style unhoverable button away from rest of group, add special difficulty level button styling, implement custom options for difficulty-based method execution, problems.getProblem mixin
This commit is contained in:
@@ -36,11 +36,12 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import arithmetic from './arithmetic.js';
|
import problems from "@/problems";
|
||||||
import SettingsMenu from "@/components/SettingsMenu";
|
import SettingsMenu from "@/components/SettingsMenu";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
|
mixins: [problems],
|
||||||
components: {SettingsMenu},
|
components: {SettingsMenu},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -78,7 +79,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
nextQuestion(fail = false) {
|
nextQuestion(fail = false) {
|
||||||
let problem = arithmetic.methods.getProblem();
|
let problem = this.getProblem();
|
||||||
if (this.currentQuestion == null)
|
if (this.currentQuestion == null)
|
||||||
this.currentQuestion = problem;
|
this.currentQuestion = problem;
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ import utils from '@/utils';
|
|||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
// Generate a addition problem
|
// Generate a addition problem
|
||||||
addition(mult = 1) {
|
addition(options) {
|
||||||
let a = utils.methods.getRandomInt(5 * mult, 100 * mult);
|
let a = utils.methods.getRandomInt(options.low, options.high);
|
||||||
let b = utils.methods.getRandomInt(5 * mult, 100 * mult);
|
let b = utils.methods.getRandomInt(options.low, options.high);
|
||||||
return {
|
return {
|
||||||
text: `${a} + ${b}`,
|
text: `${a} + ${b}`,
|
||||||
answer: a + b
|
answer: a + b
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subtraction(mult = 1) {
|
subtraction(options) {
|
||||||
let a = utils.methods.getRandomInt(5 * mult, 100 * mult);
|
let a = utils.methods.getRandomInt(options.low, options.high);
|
||||||
let b = utils.methods.getRandomInt(5 * mult, 100 * mult);
|
let b = utils.methods.getRandomInt(options.low, options.high);
|
||||||
if (Math.random() > 0.5)
|
if (Math.random() > 0.5)
|
||||||
return {
|
return {
|
||||||
text: `${a} - ${b}`,
|
text: `${a} - ${b}`,
|
||||||
@@ -49,11 +49,6 @@ export default {
|
|||||||
text: `\\sqrt{${a * a}}`,
|
text: `\\sqrt{${a * a}}`,
|
||||||
answer: a
|
answer: a
|
||||||
}
|
}
|
||||||
},
|
|
||||||
getProblem: function () {
|
|
||||||
let possible = [this.addition, this.subtraction, this.multiplication, this.division, this.square_root];
|
|
||||||
let index = utils.methods.getRandomInt(0, possible.length);
|
|
||||||
return possible[index]();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -63,30 +58,37 @@ export default {
|
|||||||
{
|
{
|
||||||
name: 'Addition',
|
name: 'Addition',
|
||||||
id: 'addition',
|
id: 'addition',
|
||||||
|
description: 'Find the sum of two integers',
|
||||||
difficulties: [
|
difficulties: [
|
||||||
{
|
{
|
||||||
id: 'easy',
|
id: 'easy',
|
||||||
name: 'Easy',
|
name: 'Easy',
|
||||||
options: {
|
options: {
|
||||||
multiplier: 1
|
low: 7,
|
||||||
}
|
high: 50
|
||||||
|
},
|
||||||
|
style: 'is-success'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'medium',
|
||||||
|
name: 'Medium',
|
||||||
|
options: {
|
||||||
|
low: 9,
|
||||||
|
high: 100
|
||||||
|
},
|
||||||
|
style: 'is-warning'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'hard',
|
id: 'hard',
|
||||||
name: 'Hard',
|
name: 'Hard',
|
||||||
options: {
|
options: {
|
||||||
multiplier: 2.5
|
low: 15,
|
||||||
}
|
high: 150
|
||||||
},
|
},
|
||||||
{
|
style: 'is-danger'
|
||||||
id: 'very_hard',
|
|
||||||
name: 'Very Hard',
|
|
||||||
options: {
|
|
||||||
multiplier: 4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
method: self.addition,
|
method: self.methods.addition,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
current: 0
|
current: 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<section class="modal-card-body">
|
<section class="modal-card-body">
|
||||||
<b-field addons v-for="(problemType, problemIndex) in problems" :key="problemType.id">
|
<b-field addons v-for="(problemType, problemIndex) in problems" :key="problemType.id">
|
||||||
<p class="control">
|
<p class="control">
|
||||||
<b-button class="button-unhoverable" :hovered="false" style="cursor: default;">
|
<b-button class="button-unhoverable darker" :hovered="false" style="cursor: default;">
|
||||||
{{ problemType.name }}
|
{{ problemType.name }}
|
||||||
</b-button>
|
</b-button>
|
||||||
</p>
|
</p>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</b-button>
|
</b-button>
|
||||||
</p>
|
</p>
|
||||||
<p class="control" v-for="(difficulty, difficultyIndex) in problemType.difficulties" :key="difficulty.id">
|
<p class="control" v-for="(difficulty, difficultyIndex) in problemType.difficulties" :key="difficulty.id">
|
||||||
<b-button :type="problemType.enabled && problemType.current === difficultyIndex ? 'is-info' : ''"
|
<b-button :type="problemType.enabled && problemType.current === difficultyIndex ? (difficulty.style || 'is-info') : ''"
|
||||||
:selected="problemType.enabled && problemType.current === difficultyIndex"
|
:selected="problemType.enabled && problemType.current === difficultyIndex"
|
||||||
@click.native="selectProblemDifficulty(problemIndex, difficultyIndex)">
|
@click.native="selectProblemDifficulty(problemIndex, difficultyIndex)">
|
||||||
{{ difficulty.name }}
|
{{ difficulty.name }}
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
import arithmetic from "@/arithmetic";
|
import arithmetic from "@/arithmetic";
|
||||||
|
import utils from "@/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: () => {
|
methods: {
|
||||||
return arithmetic.data().problems
|
getProblem() {
|
||||||
|
let problem = this.problems[utils.methods.getRandomInt(0, this.problems.length)];
|
||||||
|
return problem.method(problem.difficulties[problem.current].options);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
problems: arithmetic.data().problems
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,28 @@ $grey-lightest: hsl(0, 0%, 22%);
|
|||||||
|
|
||||||
$button-border-width: 0;
|
$button-border-width: 0;
|
||||||
$button-hover-color: $grey-darker;
|
$button-hover-color: $grey-darker;
|
||||||
|
$button-background-color: lighten($scheme-main, 0.5%);
|
||||||
|
|
||||||
// Import Bulma and Buefy styles
|
// Import Bulma and Buefy styles
|
||||||
@import "~bulma";
|
@import "~bulma";
|
||||||
@import "~buefy/src/scss/buefy";
|
@import "~buefy/src/scss/buefy";
|
||||||
|
|
||||||
// Special button class that disables hover/active/focus effects
|
// Special button class that disables hover/active/focus effects
|
||||||
.button.button-unhoverable {
|
.button {
|
||||||
&:hover, &:active, &:focus, .is-hovered, .is-active, .is-focused {
|
// Text/border changes
|
||||||
border-color: $button-border-color;
|
&.button-unhoverable {
|
||||||
|
&:hover, &:active, &:focus, &.is-hovered, &.is-active, &.is-focused {
|
||||||
|
border-color: $button-border-color !important;
|
||||||
color: $text-strong !important;
|
color: $text-strong !important;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Focused button link box shadow
|
||||||
|
&:not(:active) {
|
||||||
|
&:focus, &.is-focused {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.darker {
|
||||||
|
background-color: darken($scheme-main, 3%);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user