Skip to content

Commit

Permalink
text optimization;add tip sound
Browse files Browse the repository at this point in the history
  • Loading branch information
einsitang committed Oct 21, 2023
1 parent fcd3e57 commit 0e802e1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
Binary file added assets/audio/answer_tip.mp3
Binary file not shown.
11 changes: 11 additions & 0 deletions lib/effect/sound_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class SoundEffect {
static final AudioPlayer _wrongAudio = new AudioPlayer();
static final AudioPlayer _victoryAudio = new AudioPlayer();
static final AudioPlayer _gameOverAudio = new AudioPlayer();
// show user tips sound effect
static final AudioPlayer _answerTipAudio = new AudioPlayer();

static init() async {
if (!_init) {
await _wrongAudio.setAsset("assets/audio/wrong_tip.mp3");
await _victoryAudio.setAsset("assets/audio/victory_tip.mp3");
await _gameOverAudio.setAsset("assets/audio/gameover_tip.mp3");
await _answerTipAudio.setAsset("assets/audio/answer_tip.mp3");
}
_init = true;
}
Expand Down Expand Up @@ -41,4 +44,12 @@ class SoundEffect {
await _gameOverAudio.seek(Duration.zero);
await _gameOverAudio.play();
}

static answerTips() async {
if (!_init) {
await init();
}
await _answerTipAudio.seek(Duration.zero);
await _answerTipAudio.play();
}
}
4 changes: 2 additions & 2 deletions lib/l10n/sudoku_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"gotItText" : "Got It",

"levelText" : "Level",
"tipsText" : "Tips",
"tipsText" : "Random Tips",
"enableMarkText" : "Enable Note",
"closeMarkText" : "Close Note",
"exitGameText" : "Exit Game",
"exitGameContentText": "Whether to end this round of Sudoku ?",
"openText" : "Open",
"cancelText" : "Cancel",
"pauseText" : "Pause",
"pauseText" : "Pause Game",
"markText" : "Mark",
"pauseGameText" : "Paused",
"elapsedTimeText" : "elapsed time",
Expand Down
4 changes: 2 additions & 2 deletions lib/l10n/sudoku_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"gotItText" : "明白",

"levelText" : "难度",
"tipsText" : "提示",
"tipsText" : "随机提示",
"enableMarkText" : "启用笔记",
"closeMarkText" : "关闭笔记",
"exitGameText" : "退出游戏",
"exitGameContentText": "是否要结束本轮数独?",
"openText" : "打开",
"cancelText" : "取消",
"pauseText" : "暂停",
"pauseText" : "暂停游戏",
"markText" : "笔记",
"pauseGameText" : "游戏暂停",
"elapsedTimeText" : "耗时",
Expand Down
3 changes: 2 additions & 1 deletion lib/page/sudoku_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:url_launcher/url_launcher_string.dart';

final Logger log = Logger();

final AudioPlayer tipsPlayer = AudioPlayer();
// final AudioPlayer tipsPlayer = AudioPlayer();

final ButtonStyle flatButtonStyle = TextButton.styleFrom(
foregroundColor: Colors.black54,
Expand Down Expand Up @@ -423,6 +423,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>
for (int i = 0; i < puzzle.length; i++) {
int index = (i + randomBeginPoint) % puzzle.length;
if (puzzle[index] == -1 && record[index] == -1) {
SoundEffect.answerTips();
_state.setRecord(index, solution[index]);
_state.hintLoss();
_chooseSudokuBox = index;
Expand Down
7 changes: 4 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,10 @@ packages:
sudoku_dart:
dependency: "direct main"
description:
path: "/Users/element/github/sevlow/sudoku-dart"
relative: false
source: path
name: sudoku_dart
sha256: "393baeb629dcc5590639286feff94da8b44589aa9765408e8bf81dcd03d5701c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
Expand Down

0 comments on commit 0e802e1

Please sign in to comment.