Skip to content

Commit

Permalink
try to fix all bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer committed Jan 15, 2021
1 parent 02b2033 commit 4042bf1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
fmt.Println(`请输入科目:
1. 马原
2. 毛概`)
fmt.Scanf("%d", &choice)
fmt.Scan(&choice)
switch choice {
case 1:
subject = file.Mayuan
Expand All @@ -30,7 +30,7 @@ func main() {
2. 随机刷题
3. 模拟考试
4. 错题本`)
fmt.Scanf("%d", &choice)
fmt.Scan(&choice)
switch choice {
case 1:
handler.ProblemInOrder()
Expand Down
23 changes: 10 additions & 13 deletions question/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,50 @@ func (e *entity) SaveHistory() {
func (e *entity) ProblemInOrder() {
currentNum := int(e.history.Progress)
for index, problem := range e.problemList[currentNum:] {
e.SaveHistory()
// 判断是否一次答对
switch showProblem(problem, currentNum+index+1, len(e.problemList)+1) {
case quit:
e.SaveHistory()
fmt.Println("保存刷题记录成功,正在退出...")
fmt.Println("正在退出...")
os.Exit(0)
case wrong:
if !isIn(index, e.history.ErrorProblems) {
e.history.ErrorProblems = append(e.history.ErrorProblems, float64(index))
}
}
e.history.Progress = float64(currentNum + index + 1)
e.SaveHistory()
}
fmt.Println("题目已刷完,是否清空以便二刷?(y/n)")
fmt.Println("题目已刷完,是否清空刷题记录以便二刷?(y/n)")
var answer string
fmt.Scanf("%s", &answer)
if answer == "y" {
e.history.Progress = 0
e.SaveHistory()
fmt.Println("已清空,正在退出...")
}
e.SaveHistory()
os.Exit(0)
}

func (e *entity) ProblemInRandomOrder() {
var index int
for {
e.SaveHistory()
index = rand.Intn(len(e.problemList))
switch showProblem(e.problemList[index], 0, 0) {
case quit:
e.SaveHistory()
fmt.Println("保存刷题记录成功,正在退出...")
fmt.Println("正在退出...")
os.Exit(0)
case wrong:
if !isIn(index, e.history.ErrorProblems) {
e.history.ErrorProblems = append(e.history.ErrorProblems, float64(index))
}
}
e.SaveHistory()
}
}

func (e *entity) ProblemForExam() {
var index int
for i := 0; i < 50; i++ {
e.SaveHistory()
for {
index = rand.Intn(len(e.problemList))
if (i < 40 && len(e.problemList[index].Answer) == 1) || (i >= 40 && len(e.problemList[index].Answer) > 1) {
Expand All @@ -89,33 +86,33 @@ func (e *entity) ProblemForExam() {
}
switch showProblem(e.problemList[index], i+1, 50) {
case quit:
e.SaveHistory()
fmt.Println("保存刷题记录成功,正在退出...")
os.Exit(0)
case wrong:
if !isIn(index, e.history.ErrorProblems) {
e.history.ErrorProblems = append(e.history.ErrorProblems, float64(index))
}
}
e.SaveHistory()
}
fmt.Println("模拟考试结束,正在退出...")
os.Exit(0)
}

func (e *entity) ProblemWrongBefore() {
length := len(e.history.ErrorProblems)
tmp := make([]float64, length)
copy(tmp, e.history.ErrorProblems)
for num, index := range tmp {
e.SaveHistory()
switch showProblem(e.problemList[int(index)], num+1, length) {
case quit:
e.SaveHistory()
fmt.Println("保存刷题记录成功,正在退出...")
os.Exit(0)
case correct:
e.history.ErrorProblems = remove(index, e.history.ErrorProblems)
}
e.SaveHistory()
}
fmt.Println("错题本已刷完,正在退出...")
e.SaveHistory()
os.Exit(0)
}
16 changes: 13 additions & 3 deletions question/entity.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package question

import (
"os"
"os/exec"
"runtime"

"github.com/amtoaer/goqut/file"
)

var clearScreen string
var clear func()

func init() {
switch runtime.GOOS {
case "windows":
clearScreen = "cls"
clear = func() {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
}
default:
clearScreen = "clear"
clear = func() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
}
}

Expand Down
11 changes: 1 addition & 10 deletions question/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package question
import (
"fmt"

"os"
"os/exec"

"strings"

"github.com/amtoaer/goqut/file"
Expand All @@ -28,7 +25,7 @@ func showProblem(problem file.Problem, begin, end int) status {
fmt.Println("答案错误")
}
fmt.Printf("请输入答案:")
fmt.Scanf("%s", &answer)
fmt.Scan(&answer)
if strings.ToUpper(answer) == problem.Answer {
break
} else if answer == "quit" {
Expand Down Expand Up @@ -61,9 +58,3 @@ func remove(num float64, slice []float64) []float64 {
}
return slice
}

func clear() {
cmd := exec.Command(clearScreen)
cmd.Stdout = os.Stdout
cmd.Run()
}

0 comments on commit 4042bf1

Please sign in to comment.