Skip to content

Commit

Permalink
Merge pull request #5 from Sanotsu/feat_2048
Browse files Browse the repository at this point in the history
feat:添加了几个其他小游戏主体
  • Loading branch information
Sanotsu authored Feb 19, 2024
2 parents f526c84 + f11c620 commit a26070f
Show file tree
Hide file tree
Showing 124 changed files with 6,452 additions and 19 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,28 @@ freader-media-player(FMP Player),一个使用 flutter 开发的简单的本地

## 更新说明

### 2024-02-01 主要更新

- feat:添加了扫雷小游戏
- 更多参看对应模块的 [readme](lib/views/game_center/minesweeper/readme.md)

### 2024-01-31 主要更新

- feat:添加了恐龙快跑小游戏
- 更多参看对应模块的 [readme](lib/views/game_center/t-rex_dinosaur/readme.md)
- feat:添加了贪吃蛇小游戏
- 更多参看对应模块的 [readme](lib/views/game_center/snake/readme.md)

### 2024-01-30 主要更新

- feat:添加了俄罗斯方块小游戏
- 更多参看对应模块的[readme](lib/views/game_center/tetris/readme.md).
- 更多参看对应模块的 [readme](lib/views/game_center/tetris/readme.md)

### 2024-01-29 主要更新

- feat:添加了 2048 小游戏
- 更多参看对应模块的[readme](lib/views/game_center/flutter_2048/readme.md).
- 添加了休闲游戏模块后,原本的“本地图片”和“本地视频”模块就初始默认隐藏,同样长按退出弹窗正文可切换.
- 更多参看对应模块的 [readme](lib/views/game_center/flutter_2048/readme.md)
- 添加了休闲游戏模块后,原本的“本地图片”和“本地视频”模块就初始默认隐藏,同样长按退出弹窗正文可切换

### 2024-01-26 主要更新

Expand Down
Binary file added assets/games/cover-dinosaur.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/cover-minesweeper.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/cover-snake.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/cover-sudoku.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_large_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_large_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_small_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_small_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cacti/cacti_small_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino/dino_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/dino_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/ptera/ptera_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/dinosaur/ptera/ptera_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/minesweeper/audio/blue.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/clickEmpty.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/clickFour.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/clickOne.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/clickThree.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/clickTwo.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/lastHit.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/lose.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/pink.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/purple.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/putFlag.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/removeFlag.wav
Binary file not shown.
Binary file added assets/games/minesweeper/audio/win.wav
Binary file not shown.
Binary file added assets/games/minesweeper/images/flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/minesweeper/images/homeScreenBg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games/minesweeper/images/logo.png
Binary file added assets/games/minesweeper/images/loseScreen.png
Binary file added assets/games/minesweeper/images/pickaxe.png
Binary file added assets/games/minesweeper/images/pickaxe_old.png
Binary file added assets/games/minesweeper/images/redCross.png
Binary file added assets/games/minesweeper/images/stopwatch.png
Binary file added assets/games/minesweeper/images/trophy.png
Binary file added assets/games/minesweeper/images/winScreen.png
Binary file added assets/games/sodoku/audio/answer_tip.mp3
Binary file not shown.
Binary file added assets/games/sodoku/audio/gameover_tip.mp3
Binary file not shown.
Binary file added assets/games/sodoku/audio/victory_tip.mp3
Binary file not shown.
Binary file added assets/games/sodoku/audio/wrong_tip.mp3
Binary file not shown.
Binary file added assets/games/sodoku/image/about_me.jpg
Binary file added assets/games/sodoku/image/icon_eraser.png
Binary file added assets/games/sodoku/image/icon_idea.png
Binary file added assets/games/sodoku/image/icon_life.png
Binary file added assets/games/sodoku/image/logo.png
Binary file added assets/games/sodoku/image/sudoku_icon.png
Binary file added assets/games/sodoku/image/sudoku_logo.png
1 change: 1 addition & 0 deletions assets/games/sodoku/svg/idea.svg
4 changes: 4 additions & 0 deletions lib/common/global/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class GlobalConstants {
const String placeholderImageUrl = 'assets/launch_background.png';
const String cover2048ImageUrl = 'assets/games/cover-2048.jpg';
const String coverTetrisImageUrl = 'assets/games/cover-tetris.jpg';
const String coverDinosaurImageUrl = 'assets/games/cover-dinosaur.jpg';
const String coverSnakeImageUrl = 'assets/games/cover-snake.jpg';
const String coverMinesweeperImageUrl = 'assets/games/cover-minesweeper.jpg';
const String coverSudokuImageUrl = 'assets/games/cover-sudoku.png';

/*
// 音频播放列表支持的类型,使用扩展可以直接比较属性值
Expand Down
43 changes: 36 additions & 7 deletions lib/layout/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ import '../views/local_video/index.dart';
/// 主页面
class HomePage extends StatefulWidget {
const HomePage({super.key});
const HomePage({super.key, this.selectedIndex});

// 2024-02-01 新加可以指定默认选中的底部导航索引
// 主要是游戏中心的扫雷游戏,退出游戏界面后是使用pushAndRemoveUntil导航到home页面,
// 所以可以指定索引以便显示的是正确的游戏中心而不是初始化的第一个导航栏
final int? selectedIndex;

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
// 默认选中第一个底部导航条目
int _selectedIndex = 0;
// // 当前选中项的索引 默认选中第一个底部导航条目
int _currentIndex = 0;
// 2024-02-02 新加记录上一个底部导航索引,如果是从休闲游戏模块切换到其他模块。需要重新构建音频播放列表
// 因为目前游戏中心的背景音乐播放器和本地音乐模块播放器是同一个,因为背景播放插件的限制
// 上一个选中项的索引
int _previousIndex = 0;

final _audioHandler = getIt<MyAudioHandler>();
// 统一简单存储操作的工具类实例
Expand All @@ -44,14 +53,18 @@ class _HomePageState extends State<HomePage> {

// 2024-01-25 根据缓存值显示底部导航条目数量
changeBottomNavItemNum();

if (widget.selectedIndex != null) {
_currentIndex = widget.selectedIndex!;
}
}

/// 2024-01-25 彩蛋功能,根据缓存展示底部导航栏条目的数量
/// 2 个时就只显示本地音乐盒全部资源;否则就4个全部显示
changeBottomNavItemNum() {
setState(() {
// 2024-01-25 注意,因为可能在4切换成2的时候,当前标签tab在2或者3,那就找不到对应的了。所以默认都改成第一个。
_selectedIndex = 0;
_currentIndex = 0;

var num = _simpleStorage.getBottomNavItemMun();

Expand Down Expand Up @@ -106,7 +119,23 @@ class _HomePageState extends State<HomePage> {

void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
_previousIndex = _currentIndex; // 更新上一个索引值
_currentIndex = index; // 更新当前索引值

// 2024-02-02
// 检查是否是从游戏中心tab切换到其他tab
int gameCenterIndex = _simpleStorage.getBottomNavItemMun() > 3 ? 4 : 2;
if (_previousIndex == gameCenterIndex &&
_currentIndex != _previousIndex) {
initAudio();
}

// 如果是从其他tab进入游戏中心,则暂停音乐播放
var num = _simpleStorage.getBottomNavItemMun();
if (num > 3 ? _currentIndex == 4 : _currentIndex == 2) {
// 默认是暂停状态
_audioHandler.pause();
}
});
}

Expand Down Expand Up @@ -198,11 +227,11 @@ class _HomePageState extends State<HomePage> {
],
),
)
: Center(child: _widgetOptions.elementAt(_selectedIndex)),
: Center(child: _widgetOptions.elementAt(_currentIndex)),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: bottomNavBarItems,
currentIndex: _selectedIndex,
currentIndex: _currentIndex,
// // 底部导航栏的颜色
// backgroundColor: Theme.of(context).primaryColor,
// // 被选中的item的图标颜色和文本颜色
Expand Down
14 changes: 14 additions & 0 deletions lib/services/my_get_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ class MyGetStorage {
}

int? getTetrisBestScore() => box.read("gameTetrisBestScore");

/// 2024-01-31 恐龙游戏保存获取历史最高分
Future<void> setDinosaurBestScore(int score) async {
await box.write("gameDinosaurBestScore", score);
}

int? getDinosaurBestScore() => box.read("gameDinosaurBestScore");

/// 2024-01-31 贪吃蛇小游戏保存获取历史最高分
Future<void> setSnakeBestScore(int score) async {
await box.write("gameSnakeBestScore", score);
}

int? getSnakeBestScore() => box.read("gameSnakeBestScore");
}
5 changes: 4 additions & 1 deletion lib/views/game_center/flutter_2048/managers/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class BoardManager extends StateNotifier<Board> {

// 创建一个新游戏棋盘状态
Board _newGame() {
return Board.newGame(state.best + state.score, state.bestNum, [random([])]);
// return Board.newGame(state.best + state.score, state.bestNum, [random([])]);
// 2024-02-19 初始化的最佳分数不应该包含上次得分,需要在游戏结束时更新最佳得分
return Board.newGame(state.best, state.bestNum, [random([])]);
}

// 开始新游戏
Expand Down Expand Up @@ -364,6 +366,7 @@ class BoardManager extends StateNotifier<Board> {

state = state.copyWith(
tiles: tiles,
best: max(state.score, state.best),
bestNum: max(maxValue, state.bestNum),
won: gameWon,
over: gameOver,
Expand Down
67 changes: 60 additions & 7 deletions lib/views/game_center/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../common/global/constants.dart';
import 'flutter_2048/index.dart';
import 'minesweeper/index.dart';

import 'snake/index.dart';
import 'sudoku/index.dart';
import 't-rex_dinosaur/index.dart';
import 'tetris/index.dart';

class GameCenter extends StatefulWidget {
Expand Down Expand Up @@ -46,7 +51,7 @@ class _GameCenterState extends State<GameCenter> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(flex: 1, child: Container()),
// Expanded(flex: 1, child: Container()),
Expanded(
flex: 2,
child: Row(
Expand All @@ -70,7 +75,53 @@ class _GameCenterState extends State<GameCenter> {
],
),
),
Expanded(flex: 1, child: Container()),
Expanded(
flex: 2,
child: Row(
children: [
Expanded(
child: buildCoverCardColumn(
context,
const TRexDinosaur(),
"恐龙快跑",
imageUrl: coverDinosaurImageUrl,
),
),
Expanded(
child: buildCoverCardColumn(
context,
const SnakeGame(),
"贪吃蛇",
imageUrl: coverSnakeImageUrl,
),
)
],
),
),
Expanded(
flex: 2,
child: Row(
children: [
Expanded(
child: buildCoverCardColumn(
context,
const InitMinesweeper(),
"扫雷",
imageUrl: coverMinesweeperImageUrl,
),
),
Expanded(
child: buildCoverCardColumn(
context,
const InitSudoku(),
"数独",
imageUrl: coverSudokuImageUrl,
),
)
],
),
),
// Expanded(flex: 1, child: Container()),
],
),
);
Expand Down Expand Up @@ -99,11 +150,13 @@ buildCoverCardColumn(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(5.sp),
child: Image.asset(
imageUrl ?? placeholderImageUrl,
fit: BoxFit.contain,
Expanded(
child: Padding(
padding: EdgeInsets.all(5.sp),
child: Image.asset(
imageUrl ?? placeholderImageUrl,
fit: BoxFit.scaleDown,
),
),
),
Text(
Expand Down
Loading

0 comments on commit a26070f

Please sign in to comment.