Skip to content

Commit

Permalink
add sound effect to tip when input wrong number
Browse files Browse the repository at this point in the history
  • Loading branch information
einsitang committed Jan 13, 2023
1 parent 85ad49b commit 36b098c
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## about

![SUDOKU-FILTTER](document/img/sudoku-flutter-logo.png)
![SUDOKU-FILTTER](assets/image/sudoku_logo.png)

A open source Sudoku game application powered by Flutter .

Expand Down
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.sevlow.app.sudoku"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/drawable/launch_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/sudoku_flutter_logo" />
android:src="@mipmap/sudoku_flutter_logo"
/>
</item>
</layer-list>
Binary file added assets/audio/wrong_tip.mp3
Binary file not shown.
File renamed without changes
12 changes: 12 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
PODS:
- audio_session (0.0.1):
- Flutter
- Flutter (1.0.0)
- just_audio (0.0.1):
- Flutter
- path_provider_ios (0.0.1):
- Flutter
- url_launcher_ios (0.0.1):
- Flutter

DEPENDENCIES:
- audio_session (from `.symlinks/plugins/audio_session/ios`)
- Flutter (from `Flutter`)
- just_audio (from `.symlinks/plugins/just_audio/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

EXTERNAL SOURCES:
audio_session:
:path: ".symlinks/plugins/audio_session/ios"
Flutter:
:path: Flutter
just_audio:
:path: ".symlinks/plugins/just_audio/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de

Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
<string>sound effect</string>
</dict>
</plist>
24 changes: 24 additions & 0 deletions lib/effect/input_effect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:just_audio/just_audio.dart';

/// this class define input sound
class InputSoundEffect {
static bool _init = false;

static AudioPlayer _wrongAudio = new AudioPlayer();

static init() async {
if (!_init) {
await _wrongAudio.setAsset("assets/audio/wrong_tip.mp3");
}
_init = true;
}

static tipWrongSound() async {
if(!_init){
await init();
}
await _wrongAudio.seek(Duration.zero);
await _wrongAudio.play();
return;
}
}
14 changes: 10 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logger/logger.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:sudoku/constant.dart';
import 'package:sudoku/effect/input_effect.dart';
import 'package:sudoku/page/bootstrap.dart';
import 'package:sudoku/page/sudoku_game.dart';
import 'package:sudoku/state/sudoku_state.dart';
Expand All @@ -20,9 +20,14 @@ void main() {
class MyApp extends StatelessWidget {
// This widget is the root of your application.

// initialization effect when application build before
_initEffect() async {
await InputSoundEffect.init();
}

Future<SudokuState> _loadState() async {
SudokuState sudokuState = await SudokuState.resumeFromDB();
return sudokuState;
await _initEffect();
return await SudokuState.resumeFromDB();
}

@override
Expand All @@ -40,7 +45,8 @@ class MyApp extends StatelessWidget {
textDirection: TextDirection.ltr)));
}
if (snapshot.hasError) {
log.e(snapshot.error, snapshot.stackTrace);
log.w("here is builder future throws error you shoud see it");
log.w(snapshot.error);
}
SudokuState sudokuState = snapshot.data ?? SudokuState();
BootstrapPage bootstrapPage = BootstrapPage(title: "Loading");
Expand Down
40 changes: 21 additions & 19 deletions lib/page/sudoku_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:logger/logger.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:sudoku/constant.dart';
import 'package:sudoku/effect/input_effect.dart';
import 'package:sudoku/page/sudoku_pause_cover.dart';
import 'package:sudoku/state/sudoku_state.dart';
import 'package:sudoku_dart/sudoku_dart.dart';
import 'package:url_launcher/url_launcher_string.dart';

final Logger log = Logger();

final AudioPlayer tipsPlayer = AudioPlayer();

final ButtonStyle flatButtonStyle = TextButton.styleFrom(
foregroundColor: Colors.black54,
shadowColor: Colors.blue,
Expand Down Expand Up @@ -52,17 +56,17 @@ class _SudokuGamePageState extends State<SudokuGamePage>
_aboutDialogAction(BuildContext context) {
Widget appIcon = GestureDetector(
child: Image(
image: AssetImage("assets/image/about_me.jpg"),
width: 30,
height: 30),
image: AssetImage("assets/image/sudoku_logo.png"),
width: 45,
height: 45),
onDoubleTap: () {
WidgetBuilder columnWidget = (BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("assets/image/about_me.jpg")),
Image(image: AssetImage("assets/image/sudoku_logo.png")),
CupertinoButton(
child: Text("死月半子"),
child: Text("Sudoku"),
onPressed: () {
Navigator.pop(context, false);
},
Expand All @@ -77,7 +81,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>
children: <Widget>[
GestureDetector(
child: Text(
"visit repository on github",
"Github Repository",
style: TextStyle(color: Colors.blue),
),
onTap: () async {
Expand Down Expand Up @@ -207,7 +211,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>
if (!hasNumStock) {
fillOnPressed = null;
} else {
fillOnPressed = () {
fillOnPressed = () async {
log.d("input : $num");
if (_isOnlyReadGrid(_chooseSudokuBox)) {
// 非填空项
Expand All @@ -233,12 +237,13 @@ class _SudokuGamePageState extends State<SudokuGamePage>
// 游戏结束
return _gameOver();
}

showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text("Oops..."),
content:
Text("\nWrong Input\nYou can't afford ${_state.life} more turnovers"),
content: Text(
"\nWrong Input\nYou can't afford ${_state.life} more turnovers"),
actions: [
CupertinoDialogAction(
child: Text('Got It'),
Expand All @@ -249,9 +254,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>
],
),
);
// showDialog(
// context: context,
// builder: (_) => AlertDialog(content: Text("输入错误")));
await InputSoundEffect.tipWrongSound();

return;
}
Expand Down Expand Up @@ -516,11 +519,11 @@ class _SudokuGamePageState extends State<SudokuGamePage>
/// 笔记网格控件
///
Widget _markGridWidget(
BuildContext context, int index, {GestureTapCallback? onTap}) {
BuildContext context, int index, GestureTapCallback onTap) {
Widget markGrid = InkWell(
highlightColor: Colors.blue,
customBorder: Border.all(color: Colors.blue),
// onTap: onTap,
onTap: onTap,
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.all(1),
Expand All @@ -541,7 +544,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>
style: TextStyle(
color: _chooseSudokuBox == index
? Colors.white
: Color.fromARGB(255, 0x16, 0x85, 0xA9),
: Color.fromARGB(255, 0x16, 0x69, 0xA9),
fontSize: 12));
})));

Expand Down Expand Up @@ -627,9 +630,8 @@ class _SudokuGamePageState extends State<SudokuGamePage>
_state.mark[index].any((element) => element);

if (isUserMark) {
return _markGridWidget(context, index);
// return _markGridWidget(
// context, index, _wellOnTapBuilder(index));
return _markGridWidget(
context, index, _wellOnTapBuilder(index));
}

return _gridInWellWidget(
Expand Down Expand Up @@ -719,7 +721,7 @@ class _SudokuGamePageState extends State<SudokuGamePage>

// 开始计时
void _beginTimer() {
log.d("开始计时");
log.d("timer begin");
if (_timer == null) {
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (_state.status == SudokuGameStatus.gaming) {
Expand Down
48 changes: 48 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.10.0"
audio_session:
dependency: transitive
description:
name: audio_session
sha256: e4acc4e9eaa32436dfc5d7aed7f0a370f2d7bb27ee27de30d6c4f220c2a05c73
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.13"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -325,6 +333,30 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.7.0"
just_audio:
dependency: "direct main"
description:
name: just_audio
sha256: "7a5057a4d05c8f88ee968cec6fdfe1015577d5184e591d5ac15ab16d8f5ecb17"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.31"
just_audio_platform_interface:
dependency: transitive
description:
name: just_audio_platform_interface
sha256: eff112d5138bea3ba544b6338b1e0537a32b5e1425e4d0dc38f732771cda7c84
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.2.0"
just_audio_web:
dependency: transitive
description:
name: just_audio_web
sha256: "89d8db6f19f3821bb6bf908c4bfb846079afb2ab575b783d781a6bf119e3abaf"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.7"
logger:
dependency: "direct main"
description:
Expand Down Expand Up @@ -502,6 +534,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.27.7"
scoped_model:
dependency: "direct main"
description:
Expand Down Expand Up @@ -699,6 +739,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
url_launcher: ^6.1.7
just_audio: ^0.9.31

dev_dependencies:
flutter_test:
Expand All @@ -67,6 +68,7 @@ flutter:
# - images/a_dot_ham.jpeg
assets:
- assets/image/
- assets/audio/

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
Expand Down

0 comments on commit 36b098c

Please sign in to comment.