Skip to content

Commit be91d89

Browse files
committed
add icon and fix release mode brikSize error
1 parent 158cd71 commit be91d89

31 files changed

+159
-59
lines changed

android/app/build.gradle

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ if (flutterVersionName == null) {
2424
apply plugin: 'com.android.application'
2525
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2626

27+
def keystoreProperties = new Properties()
28+
def keystorePropertiesFile = rootProject.file('key.properties')
29+
if (keystorePropertiesFile.exists()) {
30+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
31+
}
32+
2733
android {
2834
compileSdkVersion 27
2935

@@ -32,7 +38,6 @@ android {
3238
}
3339

3440
defaultConfig {
35-
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3641
applicationId "tech.soit.tetris"
3742
minSdkVersion 16
3843
targetSdkVersion 27
@@ -41,11 +46,21 @@ android {
4146
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
4247
}
4348

49+
signingConfigs {
50+
release {
51+
keyAlias keystoreProperties['keyAlias']
52+
keyPassword keystoreProperties['keyPassword']
53+
storeFile file(keystoreProperties['storeFile'])
54+
storePassword keystoreProperties['storePassword']
55+
}
56+
}
57+
4458
buildTypes {
4559
release {
46-
// TODO: Add your own signing config for the release build.
47-
// Signing with the debug keys for now, so `flutter run --release` works.
48-
signingConfig signingConfigs.debug
60+
signingConfig signingConfigs.release
61+
minifyEnabled true
62+
useProguard true
63+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4964
}
5065
}
5166
}

android/app/proguard-rules.pro

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Flutter Wrapper
2+
-keep class io.flutter.app.** { *; }
3+
-keep class io.flutter.plugin.** { *; }
4+
-keep class io.flutter.util.** { *; }
5+
-keep class io.flutter.view.** { *; }
6+
-keep class io.flutter.** { *; }
7+
-keep class io.flutter.plugins.** { *; }

android/app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
23
package="tech.soit.tetris">
34

45
<!-- The INTERNET permission is required for development. Specifically,
@@ -7,21 +8,19 @@
78
-->
89
<uses-permission android:name="android.permission.INTERNET"/>
910

10-
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
11-
calls FlutterMain.startInitialization(this); in its onCreate method.
12-
In most cases you can leave this as-is, but you if you want to provide
13-
additional functionality it is fine to subclass or reimplement
14-
FlutterApplication and put your custom class here. -->
1511
<application
1612
android:name="io.flutter.app.FlutterApplication"
13+
android:allowBackup="false"
14+
android:fullBackupContent="@xml/backup_descriptor"
15+
android:icon="@mipmap/ic_launcher"
1716
android:label="tetris"
18-
android:icon="@mipmap/ic_launcher">
17+
tools:ignore="GoogleAppIndexingWarning">
1918
<activity
2019
android:name=".MainActivity"
21-
android:launchMode="singleTop"
22-
android:theme="@style/LaunchTheme"
2320
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
2421
android:hardwareAccelerated="true"
22+
android:launchMode="singleTop"
23+
android:theme="@style/LaunchTheme"
2524
android:windowSoftInputMode="adjustResize">
2625
<!-- This keeps the window background of the activity showing
2726
until Flutter renders its first frame. It can be removed if
@@ -31,8 +30,8 @@
3130
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
3231
android:value="true" />
3332
<intent-filter>
34-
<action android:name="android.intent.action.MAIN"/>
35-
<category android:name="android.intent.category.LAUNCHER"/>
33+
<action android:name="android.intent.action.MAIN" />
34+
<category android:name="android.intent.category.LAUNCHER" />
3635
</intent-filter>
3736
</activity>
3837
</application>
34.1 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@color/ic_launcher_background"/>
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
5+
</adaptive-icon>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="ic_launcher_background">#26A69A</color>
4+
</resources>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<full-backup-content>
3+
<!-- Exclude specific shared preferences that contain GCM registration Id -->
4+
</full-backup-content>

android/key.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
storeFile=****
2+
storePassword=****
3+
keyPassword=****
4+
keyAlias=****

lib/gamer/block.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ class Block {
115115
}
116116

117117
bool isValidInMatrix(List<List<int>> matrix) {
118-
if (xy[1] < 0 ||
119-
xy[1] + shape.length > GAME_PAD_MATRIX_H ||
118+
if (xy[1] + shape.length > GAME_PAD_MATRIX_H ||
120119
xy[0] < 0 ||
121120
xy[0] + shape[0].length > GAME_PAD_MATRIX_W) {
122121
return false;

lib/gamer/gamer.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class GameControl extends State<Game> {
158158
_current = _current.fall(step: i);
159159
_states = GameStates.drop;
160160
setState(() {});
161-
await Future.delayed(const Duration(milliseconds: 50));
161+
await Future.delayed(const Duration(milliseconds: 100));
162162
_mixCurrentIntoData();
163163
break;
164164
}
@@ -207,13 +207,15 @@ class GameControl extends State<Game> {
207207
if (clearLines.isNotEmpty) {
208208
setState(() => _states = GameStates.clear);
209209

210+
sounds.clear();
211+
210212
///消除效果动画
211-
for (int count = 0; count < 6; count++) {
213+
for (int count = 0; count < 5; count++) {
212214
clearLines.forEach((line) {
213215
_mask[line].fillRange(0, GAME_PAD_MATRIX_W, count % 2 == 0 ? -1 : 1);
214216
});
215217
setState(() {});
216-
await Future.delayed(Duration(milliseconds: 80));
218+
await Future.delayed(Duration(milliseconds: 100));
217219
}
218220
clearLines
219221
.forEach((line) => _mask[line].fillRange(0, GAME_PAD_MATRIX_W, 0));
@@ -235,7 +237,7 @@ class GameControl extends State<Game> {
235237
_states = GameStates.mixing;
236238
_forTable((i, j) => _mask[i][j] = _current.get(j, i) ?? _mask[i][j]);
237239
setState(() {});
238-
await Future.delayed(const Duration(milliseconds: 120));
240+
await Future.delayed(const Duration(milliseconds: 200));
239241
_forTable((i, j) => _mask[i][j] = 0);
240242
setState(() {});
241243
}
@@ -244,15 +246,13 @@ class GameControl extends State<Game> {
244246
_current = null;
245247

246248
//检查游戏是否结束,即检查第一行是否有元素为1
247-
for (var item in _data[0]) {
248-
if (item != 0) {
249-
reset();
250-
return;
251-
}
249+
if (_data[0].contains(1)) {
250+
reset();
251+
return;
252+
} else {
253+
//游戏尚未结束,开启下一轮方块下落
254+
_startGame();
252255
}
253-
254-
//游戏尚未结束,开启下一轮方块下落
255-
_startGame();
256256
}
257257

258258
///遍历表格

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class _HomePage extends StatelessWidget {
5858
decoration:
5959
BoxDecoration(border: Border.all(color: Colors.black54)),
6060
child: Container(
61-
decoration: BoxDecoration(
62-
border: Border.all(width: 6, color: SCREEN_BACKGROUND)),
61+
padding: const EdgeInsets.all(3),
62+
color: SCREEN_BACKGROUND,
6363
child: Screen(width: screenW),
6464
),
6565
),

lib/material/briks.dart

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import 'package:flutter/material.dart';
22

3-
///the size of a single brik
4-
Size brikSize = Size(16, 16);
5-
63
const _COLOR_NORMAL = Colors.black87;
74

85
const _COLOR_NULL = Colors.black12;
96

10-
const _COLOR_HIGHLIGHT = Color(0xFF3E2723);
7+
const _COLOR_HIGHLIGHT = Color(0xFF560000);
8+
9+
class BrikSize extends InheritedWidget {
10+
const BrikSize({
11+
Key key,
12+
@required this.size,
13+
@required Widget child,
14+
}) : assert(child != null),
15+
super(key: key, child: child);
16+
17+
final Size size;
18+
19+
static BrikSize of(BuildContext context) {
20+
final brikSize = context.inheritFromWidgetOfExactType(BrikSize) as BrikSize;
21+
assert(brikSize != null, "....");
22+
return brikSize;
23+
}
24+
25+
@override
26+
bool updateShouldNotify(BrikSize old) {
27+
return old.size != size;
28+
}
29+
}
1130

1231
///the basic brik for game panel
1332
class Brik extends StatelessWidget {
@@ -24,7 +43,7 @@ class Brik extends StatelessWidget {
2443
@override
2544
Widget build(BuildContext context) {
2645
return SizedBox.fromSize(
27-
size: brikSize,
46+
size: BrikSize.of(context).size,
2847
child: Container(
2948
margin: EdgeInsets.all(1),
3049
padding: EdgeInsets.all(2),

lib/panel/controller.dart

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ class _LeftController extends StatelessWidget {
8888
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
8989
children: <Widget>[
9090
_SystemButton(
91+
color: const Color(0xFF2dc421),
9192
label: "SOUNDS",
9293
onTap: () {
9394
Game.of(context).soundSwitch();
9495
},
9596
),
9697
_SystemButton(
98+
color: const Color(0xFF2dc421),
9799
label: "PAUSE/RESUME",
98100
onTap: () {
99101
Game.of(context).pauseOrResume();
@@ -140,12 +142,14 @@ class _SystemButton extends StatelessWidget {
140142
Widget build(BuildContext context) {
141143
return Column(
142144
children: <Widget>[
143-
_Button(
144-
enableLongPress: false,
145-
size: _SYSTEM_BUTTON_SIZE,
146-
color: color,
147-
onTap: onTap,
148-
),
145+
ClipOval(
146+
child: SizedBox.fromSize(
147+
size: _SYSTEM_BUTTON_SIZE,
148+
child: RaisedButton(
149+
onPressed: onTap,
150+
child: Container(),
151+
color: color,
152+
))),
149153
SizedBox(height: 8),
150154
Text(
151155
label,
@@ -185,15 +189,32 @@ class _ButtonState extends State<_Button> {
185189

186190
bool _tapEnded = false;
187191

192+
Color _color;
193+
194+
@override
195+
void didUpdateWidget(_Button oldWidget) {
196+
super.didUpdateWidget(oldWidget);
197+
_color = widget.color;
198+
}
199+
200+
@override
201+
void initState() {
202+
super.initState();
203+
_color = widget.color;
204+
}
205+
188206
@override
189207
Widget build(BuildContext context) {
190208
return Material(
191-
color: widget.color,
209+
color: _color,
192210
elevation: 2,
193211
shape: CircleBorder(),
194212
child: GestureDetector(
195213
behavior: HitTestBehavior.opaque,
196214
onTapDown: (_) async {
215+
setState(() {
216+
_color = widget.color.withOpacity(0.5);
217+
});
197218
if (_timer != null) {
198219
return;
199220
}
@@ -206,7 +227,7 @@ class _ButtonState extends State<_Button> {
206227
if (_tapEnded) {
207228
return;
208229
}
209-
_timer = Timer.periodic(const Duration(milliseconds: 50), (t) {
230+
_timer = Timer.periodic(const Duration(milliseconds: 60), (t) {
210231
if (!_tapEnded) {
211232
widget.onTap();
212233
} else {
@@ -217,11 +238,19 @@ class _ButtonState extends State<_Button> {
217238
},
218239
onTapCancel: () {
219240
_tapEnded = true;
241+
_timer?.cancel();
242+
_timer = null;
243+
setState(() {
244+
_color = widget.color;
245+
});
220246
},
221247
onTapUp: (_) {
222248
_tapEnded = true;
223249
_timer?.cancel();
224250
_timer = null;
251+
setState(() {
252+
_color = widget.color;
253+
});
225254
},
226255
child: SizedBox.fromSize(size: widget.size),
227256
),

lib/panel/player_panel.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import 'package:tetris/material/briks.dart';
33
import 'package:tetris/material/images.dart';
44
import 'package:tetris/gamer/gamer.dart';
55

6-
const MATRIX_H = GAME_PAD_MATRIX_H;
7-
const MATRIX_W = GAME_PAD_MATRIX_W;
6+
const _PLAYER_PANEL_PADDING = 6;
7+
8+
Size getBrikSizeForScreenWidth(double width) {
9+
return Size.square((width - _PLAYER_PANEL_PADDING) / GAME_PAD_MATRIX_W);
10+
}
811

912
///the matrix of player content
1013
class PlayerPanel extends StatelessWidget {
@@ -18,7 +21,6 @@ class PlayerPanel extends StatelessWidget {
1821

1922
@override
2023
Widget build(BuildContext context) {
21-
brikSize = Size((size.width - 6) / MATRIX_W, (size.height - 6) / MATRIX_H);
2224
return SizedBox.fromSize(
2325
size: size,
2426
child: Container(

0 commit comments

Comments
 (0)