Repository: yubo725/flutter-tetris
Branch: master
Commit: 46db0a59570e
Files: 67
Total size: 163.5 KB
Directory structure:
gitextract_o9euvs9q/
├── .gitignore
├── .idea/
│ ├── libraries/
│ │ ├── Dart_Packages.xml
│ │ ├── Dart_SDK.xml
│ │ ├── Flutter_Plugins.xml
│ │ └── Flutter_for_Android.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations/
│ │ └── main_dart.xml
│ ├── vcs.xml
│ └── workspace.xml
├── .metadata
├── LICENSE
├── README.md
├── android/
│ ├── .gitignore
│ ├── app/
│ │ ├── build.gradle
│ │ └── src/
│ │ └── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── yubo/
│ │ │ └── fluttertetris/
│ │ │ └── MainActivity.java
│ │ └── res/
│ │ ├── drawable/
│ │ │ └── launch_background.xml
│ │ └── values/
│ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle/
│ │ └── wrapper/
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── settings.gradle
├── files/
│ └── app-release.apk
├── flutter_tetris.iml
├── flutter_tetris_android.iml
├── ios/
│ ├── .gitignore
│ ├── Flutter/
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Runner/
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Assets.xcassets/
│ │ │ ├── AppIcon.appiconset/
│ │ │ │ └── Contents.json
│ │ │ └── LaunchImage.imageset/
│ │ │ ├── Contents.json
│ │ │ └── README.md
│ │ ├── Base.lproj/
│ │ │ ├── LaunchScreen.storyboard
│ │ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ └── main.m
│ ├── Runner.xcodeproj/
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace/
│ │ │ └── contents.xcworkspacedata
│ │ └── xcshareddata/
│ │ └── xcschemes/
│ │ └── Runner.xcscheme
│ └── Runner.xcworkspace/
│ ├── contents.xcworkspacedata
│ └── xcshareddata/
│ └── IDEWorkspaceChecks.plist
├── lib/
│ ├── constants/
│ │ ├── Constants.dart
│ │ └── Global.dart
│ ├── event/
│ │ ├── MoveEvent.dart
│ │ ├── ScoreEvent.dart
│ │ └── StatusEvent.dart
│ ├── main.dart
│ ├── splash.dart
│ ├── util/
│ │ ├── Point.dart
│ │ └── ShapeFactory.dart
│ └── view/
│ ├── Cell.dart
│ ├── ControllerBar.dart
│ ├── GameOverPanel.dart
│ ├── GameView.dart
│ ├── Ground.dart
│ ├── InfoPanel.dart
│ ├── PausePanel.dart
│ ├── PlayPanel.dart
│ └── Shape.dart
├── pubspec.yaml
└── test/
└── widget_test.dart
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.DS_Store
.dart_tool/
.packages
.pub/
build/
.flutter-plugins
================================================
FILE: .idea/libraries/Dart_Packages.xml
================================================
================================================
FILE: .idea/libraries/Dart_SDK.xml
================================================
================================================
FILE: .idea/libraries/Flutter_Plugins.xml
================================================
================================================
FILE: .idea/libraries/Flutter_for_Android.xml
================================================
================================================
FILE: .idea/misc.xml
================================================
================================================
FILE: .idea/modules.xml
================================================
================================================
FILE: .idea/runConfigurations/main_dart.xml
================================================
================================================
FILE: .idea/vcs.xml
================================================
================================================
FILE: .idea/workspace.xml
================================================
shapeData
new
newSha
newShape
1532669488741
1532669488741
================================================
FILE: .metadata
================================================
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: c7ea3ca377e909469c68f2ab878a5bc53d3cf66b
channel: beta
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2018 yubo_725
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
# flutter-tetris
基于Flutter的俄罗斯方块小游戏,支持Android与iOS。
# 玩法
底部三个按钮分别控制方块的左右移动和变形
**在游戏区域从上至下滑动屏幕可让方块迅速落下**
*排行榜功能未实现*
# Android扫码下载
# 运行截图
================================================
FILE: android/.gitignore
================================================
*.iml
*.class
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
GeneratedPluginRegistrant.java
================================================
FILE: android/app/build.gradle
================================================
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.yubo.fluttertetris"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
================================================
FILE: android/app/src/main/AndroidManifest.xml
================================================
================================================
FILE: android/app/src/main/java/com/yubo/fluttertetris/MainActivity.java
================================================
package com.yubo.fluttertetris;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
================================================
FILE: android/app/src/main/res/drawable/launch_background.xml
================================================
================================================
FILE: android/app/src/main/res/values/styles.xml
================================================
================================================
FILE: android/build.gradle
================================================
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: android/gradle/wrapper/gradle-wrapper.properties
================================================
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
================================================
FILE: android/gradle.properties
================================================
org.gradle.jvmargs=-Xmx1536M
================================================
FILE: android/gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: android/gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: android/settings.gradle
================================================
include ':app'
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
================================================
FILE: flutter_tetris.iml
================================================
================================================
FILE: flutter_tetris_android.iml
================================================
================================================
FILE: ios/.gitignore
================================================
.idea/
.vagrant/
.sconsign.dblite
.svn/
.DS_Store
*.swp
profile
DerivedData/
build/
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m
.generated/
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3
xcuserdata
*.moved-aside
*.pyc
*sync/
Icon?
.tags*
/Flutter/app.flx
/Flutter/app.zip
/Flutter/flutter_assets/
/Flutter/App.framework
/Flutter/Flutter.framework
/Flutter/Generated.xcconfig
/ServiceDefinitions.json
Pods/
.symlinks/
================================================
FILE: ios/Flutter/AppFrameworkInfo.plist
================================================
CFBundleDevelopmentRegion
en
CFBundleExecutable
App
CFBundleIdentifier
io.flutter.flutter.app
CFBundleInfoDictionaryVersion
6.0
CFBundleName
App
CFBundlePackageType
FMWK
CFBundleShortVersionString
1.0
CFBundleSignature
????
CFBundleVersion
1.0
MinimumOSVersion
8.0
================================================
FILE: ios/Flutter/Debug.xcconfig
================================================
#include "Generated.xcconfig"
================================================
FILE: ios/Flutter/Release.xcconfig
================================================
#include "Generated.xcconfig"
================================================
FILE: ios/Runner/AppDelegate.h
================================================
#import
#import
@interface AppDelegate : FlutterAppDelegate
@end
================================================
FILE: ios/Runner/AppDelegate.m
================================================
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
================================================
FILE: ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
================================================
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@1x.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@1x.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@1x.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "Icon-App-1024x1024@1x.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
================================================
FILE: ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
================================================
{
"images" : [
{
"idiom" : "universal",
"filename" : "LaunchImage.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "LaunchImage@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "LaunchImage@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
================================================
FILE: ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md
================================================
# Launch Screen Assets
You can customize the launch screen with your own desired assets by replacing the image files in this directory.
You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
================================================
FILE: ios/Runner/Base.lproj/LaunchScreen.storyboard
================================================
================================================
FILE: ios/Runner/Base.lproj/Main.storyboard
================================================
================================================
FILE: ios/Runner/Info.plist
================================================
CFBundleDevelopmentRegion
en
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
flutter_tetris
CFBundlePackageType
APPL
CFBundleShortVersionString
1.0
CFBundleSignature
????
CFBundleVersion
1
LSRequiresIPhoneOS
UILaunchStoryboardName
LaunchScreen
UIMainStoryboardFile
Main
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIViewControllerBasedStatusBarAppearance
================================================
FILE: ios/Runner/main.m
================================================
#import
#import
#import "AppDelegate.h"
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
================================================
FILE: ios/Runner.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
9705A1C41CF9048500538489 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
97C146EB1CF9000F007C117D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
9740EEB31CF90195004384FC /* Generated.xcconfig */,
);
name = Flutter;
sourceTree = "";
};
97C146E51CF9000F007C117D = {
isa = PBXGroup;
children = (
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
);
sourceTree = "";
};
97C146EF1CF9000F007C117D /* Products */ = {
isa = PBXGroup;
children = (
97C146EE1CF9000F007C117D /* Runner.app */,
);
name = Products;
sourceTree = "";
};
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
97C147021CF9000F007C117D /* Info.plist */,
97C146F11CF9000F007C117D /* Supporting Files */,
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
);
path = Runner;
sourceTree = "";
};
97C146F11CF9000F007C117D /* Supporting Files */ = {
isa = PBXGroup;
children = (
97C146F21CF9000F007C117D /* main.m */,
);
name = "Supporting Files";
sourceTree = "";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
97C146ED1CF9000F007C117D /* Runner */ = {
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
);
buildRules = (
);
dependencies = (
);
name = Runner;
productName = Runner;
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 4ZACZ79DU9;
};
};
};
buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 97C146E51CF9000F007C117D;
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
97C146ED1CF9000F007C117D /* Runner */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
97C146EC1CF9000F007C117D /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Thin Binary";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Run Script";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
97C146EA1CF9000F007C117D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
97C146F31CF9000F007C117D /* main.m in Sources */,
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
97C146FA1CF9000F007C117D /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
97C146FB1CF9000F007C117D /* Base */,
);
name = Main.storyboard;
sourceTree = "";
};
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
97C147001CF9000F007C117D /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
97C147031CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
97C147041CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
97C147061CF9000F007C117D /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 4ZACZ79DU9;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.yubo.flutterTetris;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
};
97C147071CF9000F007C117D /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 4ZACZ79DU9;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.yubo.flutterTetris;
PRODUCT_NAME = "$(TARGET_NAME)";
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = {
isa = XCConfigurationList;
buildConfigurations = (
97C147031CF9000F007C117D /* Debug */,
97C147041CF9000F007C117D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = {
isa = XCConfigurationList;
buildConfigurations = (
97C147061CF9000F007C117D /* Debug */,
97C147071CF9000F007C117D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
================================================
FILE: ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
================================================
================================================
FILE: ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
================================================
================================================
FILE: ios/Runner.xcworkspace/contents.xcworkspacedata
================================================
================================================
FILE: ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
================================================
IDEDidComputeMac32BitWarning
================================================
FILE: lib/constants/Constants.dart
================================================
class Constants {
static const double cellWidth = 20.0;
static const double bodyPadding = 2.0;
}
================================================
FILE: lib/constants/Global.dart
================================================
import 'package:event_bus/event_bus.dart';
class Global {
static EventBus eventBus = new EventBus();
}
================================================
FILE: lib/event/MoveEvent.dart
================================================
enum MoveEventType {
moveLeft, moveRight, moveDown, transform
}
class MoveEvent {
MoveEventType type;
MoveEvent({this.type});
}
================================================
FILE: lib/event/ScoreEvent.dart
================================================
enum ScoreEventType {
newScore
}
class ScoreEvent {
ScoreEventType type;
int newScore;
ScoreEvent({this.type, this.newScore});
}
================================================
FILE: lib/event/StatusEvent.dart
================================================
import 'package:flutter_tetris/view/Shape.dart';
enum Status {
// shape死掉的事件
shapeDie,
// 生产新的图形
newShape,
// shape马上落到最底下
shapeDieNow,
// 下一个图形的数据
nextShapeData,
// 游戏结束
gameOver,
// 游戏暂停
gamePause,
// 重玩游戏
replay
}
class StatusEvent {
Status type;
Shape shape;
List>> nextShapeData;
bool isPause;
StatusEvent({this.type, this.shape, this.nextShapeData, this.isPause});
}
================================================
FILE: lib/main.dart
================================================
import 'package:flutter/material.dart';
import 'splash.dart';
import 'view/ControllerBar.dart';
import 'view/GameView.dart';
import 'dart:async';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
State createState() => new MyAppState();
}
class MyAppState extends State {
bool showSplash = true;
@override
Widget build(BuildContext context) {
if (showSplash) {
new Timer(new Duration(seconds: 2), () {
setState(() {
showSplash = false;
});
});
return SplashPage();
}
return new MaterialApp(
title: "Tetris",
home: new Scaffold(
appBar: new AppBar(
title: new Text("俄罗斯方块"),
),
body: new Column(
children: [
new GameView(),
new ControllerBar()
],
)
),
);
}
}
================================================
FILE: lib/splash.dart
================================================
import 'package:flutter/material.dart';
class SplashPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Splash",
home: new Scaffold(
body: new Body()
)
);
}
}
class Body extends StatelessWidget {
@override
Widget build(BuildContext context) {
MediaQueryData data = MediaQuery.of(context);
return new Container(
width: data.size.width,
height: data.size.height,
color: Colors.blue,
child: new Center(
child: new Text(
"Flutter Tetris",
textDirection: TextDirection.ltr,
style: new TextStyle(
fontSize: 30.0,
color: Colors.white
),
)
)
);
}
}
================================================
FILE: lib/util/Point.dart
================================================
class Point {
int x, y;
Point(this.x, this.y);
}
================================================
FILE: lib/util/ShapeFactory.dart
================================================
import 'dart:math' show Random;
class ShapeFactory {
List>>> shapes = [];
ShapeFactory() {
var shape1 = [[
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 1],
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 1],
[0, 0, 1, 1],
[0, 0, 0, 1],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 1, 1],
[0, 0, 0, 0]
]];
var shape2 = [[
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]
], [
[0, 0, 0, 0],
[1, 1, 1, 1],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]
], [
[0, 0, 0, 0],
[1, 1, 1, 1],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape3 = [[
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape4 = [[
[0, 0, 1, 0],
[0, 0, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[1, 0, 0, 0],
[1, 1, 1, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 0]
], [
[1, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape5 = [[
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[1, 1, 1, 0],
[1, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 1, 0],
[1, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape6 = [[
[0, 1, 1, 0],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
], [
[1, 1, 1, 0],
[1, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
], [
[1, 0, 1, 0],
[1, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape7 = [[
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 0, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
var shape8 = [[
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]
], [
[0, 1, 1, 0],
[1, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[1, 1, 1, 0],
[1, 1, 0, 0],
[0, 0, 0, 0]
]];
var shape9 = [[
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 1, 1, 0],
[1, 1, 0, 0],
[0, 0, 0, 0]
], [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 1, 1, 0],
[1, 1, 0, 0],
[0, 0, 0, 0]
]];
shapes.add(shape1);
shapes.add(shape2);
shapes.add(shape3);
shapes.add(shape4);
shapes.add(shape5);
shapes.add(shape6);
shapes.add(shape7);
shapes.add(shape8);
shapes.add(shape9);
}
List>> getRandomShapeData() {
Random random = new Random();
int index = random.nextInt(shapes.length * 3) % shapes.length;
return shapes[index];
}
List>> getEmptyShapeData() {
return [[
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
], [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]];
}
}
================================================
FILE: lib/view/Cell.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/constants/Constants.dart';
import 'package:flutter_tetris/util/Point.dart';
// Cell代表一个正方形的小方块,一个Shape是由多个小方块组成的
class Cell extends StatefulWidget {
Color color = Colors.blue; // 小方块的颜色
Point point; // 表示Shape内这个Cell的坐标
bool isFill; // 是否填充
List> shapeOrGroundData;
BorderSide _borderThin = new BorderSide(width: 0.5, color: Colors.grey);
BorderSide _borderBold = new BorderSide(width: 1.0, color: Colors.grey);
int hCount;
int vCount;
Cell({Key key, this.color, this.point, this.isFill, this.shapeOrGroundData, this.hCount = 4, this.vCount = 4}) : super(key: key);
Border generateBorder() {
int x = this.point.x;
int y = this.point.y;
BorderSide leftBorder = _borderThin;
BorderSide topBorder = _borderThin;
BorderSide rightBorder = _borderThin;
BorderSide bottomBorder = _borderThin;
if (isFill) {
if (x == 0 || (this.shapeOrGroundData[x - 1][y] == 0)) {
topBorder = _borderBold;
}
if (x == vCount - 1 || (this.shapeOrGroundData[x + 1][y] == 0)) {
bottomBorder = _borderBold;
}
if (y == 0 || (this.shapeOrGroundData[x][y - 1] == 0)) {
leftBorder = _borderBold;
}
if (y == hCount - 1 || (this.shapeOrGroundData[x][y + 1] == 0)) {
rightBorder = _borderBold;
}
}
return new Border(
left: leftBorder,
top: topBorder,
right: rightBorder,
bottom: bottomBorder
);
}
@override
State createState() => new CellState();
}
class CellState extends State {
@override
Widget build(BuildContext context) {
if (this.widget.isFill) {
return new Container(
width: Constants.cellWidth,
height: Constants.cellWidth,
decoration: new BoxDecoration(
color: this.widget.color,
border: this.widget.generateBorder()
),
);
}
return new Container(
width: Constants.cellWidth,
height: Constants.cellWidth,
color: Colors.transparent
);
}
}
================================================
FILE: lib/view/ControllerBar.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/event/MoveEvent.dart';
class CustomButton extends StatelessWidget {
double width, height;
VoidCallback onPress;
String iconPath;
CustomButton({Key key, this.width, this.height, this.onPress, this.iconPath}) : super(key: key);
@override
Widget build(BuildContext context) {
return new InkWell(
onTap: this.onPress,
child: new Container(
padding: const EdgeInsets.all(10.0),
width: this.width,
height: this.height,
child: new Center(
child: new Image.asset(this.iconPath, fit: BoxFit.contain),
),
decoration: new BoxDecoration(
color: const Color(0xffcccccc),
border: new Border.all(
width: 1.0,
color: Colors.white,
),
borderRadius: new BorderRadius.all(new Radius.circular(6.0))
),
),
);
}
}
class ControllerBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
Row row = new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new CustomButton(
width: 80.0,
height: 50.0,
iconPath: 'images/arrow_left.png',
onPress: () {
Global.eventBus.fire(new MoveEvent(type: MoveEventType.moveLeft));
},
),
new CustomButton(
width: 120.0,
height: 50.0,
iconPath: 'images/arrow_up.png',
onPress: () {
Global.eventBus.fire(new MoveEvent(type: MoveEventType.transform));
},
),
new CustomButton(
width: 80.0,
height: 50.0,
iconPath: 'images/arrow_right.png',
onPress: () {
Global.eventBus.fire(new MoveEvent(type: MoveEventType.moveRight));
},
)
],
);
Padding padding = new Padding(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
child: row,
);
return new Container(
child: padding,
color: Colors.blue,
);
}
}
================================================
FILE: lib/view/GameOverPanel.dart
================================================
import 'package:flutter/material.dart';
class GameOverPanel extends StatelessWidget {
double width, height;
TextStyle style = new TextStyle(
fontSize: 32.0,
color: Colors.blue,
fontWeight: FontWeight.bold
);
GameOverPanel({Key key, this.width, this.height}) : super(key: key);
@override
Widget build(BuildContext context) {
return new Container(
width: this.width,
height: this.height,
color: const Color(0x90000000),
child: new Center(
child: new Text("GAME OVER", style: style)
),
);
}
}
================================================
FILE: lib/view/GameView.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/view/PlayPanel.dart';
import 'package:flutter_tetris/view/InfoPanel.dart';
import 'package:flutter_tetris/constants/Constants.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/event/StatusEvent.dart';
import 'dart:async';
class GameView extends StatefulWidget {
@override
State createState() => new GameViewState();
}
class GameViewState extends State {
bool measured = false;
GlobalKey _key = new GlobalKey();
int hCount, vCount; // 水平和垂直方向上格子的个数
Size containerSize;
double hPadding = 12.0;
double vPadding = 6.0;
double playPanelWidth, infoPanelWidth, panelHeight;
measure() {
new Timer(new Duration(milliseconds: 10), () {
RenderObject obj = _key.currentContext.findRenderObject();
while (obj == null) {
obj = _key.currentContext.findRenderObject();
}
containerSize = obj.semanticBounds.size;
hCount = (containerSize.width - hPadding) ~/ Constants.cellWidth;
vCount = (containerSize.height - vPadding) ~/ Constants.cellWidth;
print('hCount: $hCount, vCount: $vCount');
panelHeight = containerSize.height;
infoPanelWidth = 4 * Constants.cellWidth + Constants.bodyPadding * 2;
playPanelWidth = containerSize.width - infoPanelWidth;
setState(() {
measured = true;
});
});
}
@override
Widget build(BuildContext context) {
if (!measured) {
this.measure();
return new Expanded(
child: new Container(
key: _key,
color: Colors.white,
),
);
} else {
return new Expanded(
flex: 1,
child: new Row(
children: [
new GestureDetector(
child: new PlayPanel(width: playPanelWidth, height: panelHeight, hCount: hCount - 4, vCount: vCount),
onVerticalDragEnd: (detail) {
double speedY = detail.velocity.pixelsPerSecond.dy;
if (speedY > 1500) {
// 向下滑动屏幕,让shape马上落下
Global.eventBus.fire(new StatusEvent(type: Status.shapeDieNow));
}
},
),
new InfoPanel(width: infoPanelWidth, height: panelHeight, vCount: vCount)
],
)
);
}
}
}
================================================
FILE: lib/view/Ground.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/view/Cell.dart';
import 'package:flutter_tetris/util/Point.dart';
import 'package:flutter_tetris/view/Shape.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/event/StatusEvent.dart';
import 'package:flutter_tetris/event/ScoreEvent.dart';
class Ground extends StatefulWidget {
int hCount, vCount;
List> data;
Ground({Key key, this.hCount, this.vCount}) : super(key: key) {
this.data = generateEmptyData(vCount, hCount);
}
List generateEmptyRow(int count) {
List list = [];
for (int i = 0; i < count; i++) {
list.add(0);
}
return list;
}
List> generateEmptyData(int rowCount, int colCount) {
List> list = [];
for (int row = 0; row < rowCount; row++) {
list.add(generateEmptyRow(colCount));
}
return list;
}
@override
State createState() => GroundState();
}
class GroundState extends State {
@override
void initState() {
super.initState();
Global.eventBus.on().listen((event) {
if (event.type == Status.shapeDie) {
Shape shape = event.shape;
eatShape(shape);
} else if (event.type == Status.replay) {
// 重新开始游戏
setState(() {
this.widget.data = this.widget.generateEmptyData(this.widget.vCount, this.widget.hCount);
});
}
});
}
// 将shape的数据变为自身的一部分
eatShape(Shape shape) {
setState(() {
int x = shape.posX;
int y = shape.posY;
List> shapeData = new List>();
shapeData.addAll(shape.data);
// 这里将shape的数据清空,否则ground吃掉shape后还会短暂出现shape的数据
shape.setEmptyData();
for (int col = 0; col < 4; col++) {
for (int row = 0; row < 4; row++) {
if (shapeData[col][row] == 1) {
this.widget.data[col + y][row + x] = 1;
}
}
}
clearFullRows();
});
}
// 判断某一行是否是满行
bool isFullRow(int rowIndex) {
bool full = true;
for (int i = 0; i < this.widget.hCount; i++) {
if (this.widget.data[rowIndex][i] == 0) {
full = false;
break;
}
}
return full;
}
// 移动数据
moveRows(int fullRowIndex) {
for (int row = fullRowIndex; row >= 0; row--) {
for (int col = 0; col < this.widget.hCount; col++) {
if (row > 0) {
this.widget.data[row][col] = this.widget.data[row - 1][col];
} else {
this.widget.data[row][col] = 0;
}
}
}
}
// 消除满行,从下到上检查
clearFullRows() {
int fullRowCount = 0;
for (int row = this.widget.vCount - 1; row >= 0; row--) {
if (isFullRow(row)) {
++fullRowCount;
// 当前是满行,消除此行并将上面的数据依次往下移一行
moveRows(row);
// 消除满行后,从前面一行重新开始检查
row += 1;
}
}
if (fullRowCount > 0) {
// 获得分数
int score = fullRowCount * 10;
// 通知InfoPanel刷新分数
Global.eventBus.fire(new ScoreEvent(type: ScoreEventType.newScore, newScore: score));
}
}
@override
Widget build(BuildContext context) {
List rows = new List();
for (int row = 0; row < this.widget.vCount; row++) { // 行
List rowData = new List();
for (int col = 0; col < this.widget.hCount; col++) { // 列
Point point = new Point(row, col);
rowData.add(new Cell(
color: const Color(0xffcc3366),
point: point,
isFill: this.widget.data[row][col] == 1,
shapeOrGroundData: this.widget.data,
hCount: this.widget.hCount,
vCount: this.widget.vCount,
));
}
rows.add(new Row(
children: rowData
));
}
return new Column(children: rows);
}
}
================================================
FILE: lib/view/InfoPanel.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/view/Shape.dart';
import 'package:flutter_tetris/util/ShapeFactory.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/event/StatusEvent.dart';
import 'package:flutter_tetris/constants/Constants.dart';
import 'package:flutter_tetris/event/ScoreEvent.dart';
import 'dart:async';
class InfoPanel extends StatefulWidget {
double width, height;
int vCount;
Shape nextShape;
InfoPanel({Key key, this.width, this.height, this.vCount}) : super(key: key) {
nextShape = new Shape.withData(new ShapeFactory().getEmptyShapeData());
}
@override
State createState() => InfoPanelState();
}
class InfoPanelState extends State {
TextStyle valueTextStyle = new TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
color: Colors.blue
);
// 得分字符串
String scoreStr = '0分';
// 已游戏时间(字符串)
String playTimeStr = '0秒';
// 已游戏的时间(秒)
int playTime = 0;
// 定时器,1秒更新一次数据
Timer timer;
// 总分数
int totalScore = 0;
// 游戏是否暂停
bool isPause = false;
// 游戏是否结束
bool isGameOver = false;
String btnText = '暂停';
@override
void initState() {
super.initState();
Global.eventBus.on().listen((event) {
if (event.type == Status.nextShapeData) {
setState(() {
this.widget.nextShape.shapeData = event.nextShapeData;
this.widget.nextShape.data = event.nextShapeData[0];
});
} else if (event.type == Status.gameOver) {
setState(() {
btnText = '重玩';
isGameOver = true;
});
// 游戏结束,停止计时
if (this.timer != null) {
this.timer.cancel();
}
}
});
Global.eventBus.on().listen((event) {
if (event.type == ScoreEventType.newScore) {
int newScore = event.newScore;
totalScore += newScore;
setState(() {
scoreStr = '$totalScore分';
});
}
});
startTimer();
}
// 开始计时
startTimer() {
this.timer = new Timer.periodic(new Duration(seconds: 1), (timer) {
this.playTime++;
String timeStr = '';
if (this.playTime <= 60) {
timeStr = '${this.playTime}秒';
} else if (this.playTime <= 3600) {
int minutes = this.playTime ~/ 60;
int secs = this.playTime - minutes * 60;
timeStr = '${minutes}分${secs}秒';
}
setState(() {
this.playTimeStr = timeStr;
});
});
}
// 暂停游戏,暂停计时
pauseGame() {
String s = '暂停';
if (isPause) {
s = '继续';
if (this.timer != null) {
this.timer.cancel();
}
} else {
startTimer();
}
setState(() {
btnText = s;
});
}
@override
Widget build(BuildContext context) {
var nextShapeView = new Column(
children: [
new Text("下一个:"),
this.widget.nextShape.getShapeView()
],
);
var timeView = new Column(
children: [
new Text("耗时:"),
new Text(playTimeStr, style: valueTextStyle)
],
);
var scoreView = new Column(
children: [
new Text("得分:"),
new Text(scoreStr, style: valueTextStyle)
],
);
var pauseBtn = new RaisedButton(
onPressed: () {
if (isGameOver) {
// 重新开始游戏
setState(() {
totalScore = 0;
scoreStr = '0分';
isPause = false;
isGameOver = false;
btnText = '暂停';
});
Global.eventBus.fire(new StatusEvent(type: Status.replay));
return;
}
// 发送游戏暂停的通知
isPause = !isPause;
pauseGame();
Global.eventBus.fire(new StatusEvent(type: Status.gamePause, isPause: isPause));
},
child: new Text(btnText),
);
var rankBtn = new RaisedButton(
onPressed: () {},
child: new Text("排行榜"),
);
return new Container(
margin: const EdgeInsets.fromLTRB(0.0, Constants.bodyPadding, Constants.bodyPadding, Constants.bodyPadding),
width: this.widget.width - Constants.bodyPadding,
height: this.widget.height - Constants.bodyPadding * 2,
color: Colors.blue,
child: new Center(
child: new Container(
padding: const EdgeInsets.fromLTRB(0.0, 30.0, 0.0, 30.0),
width: 4 * Constants.cellWidth,
height: this.widget.vCount * Constants.cellWidth,
color: Colors.white,
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
nextShapeView,
timeView,
scoreView,
pauseBtn,
rankBtn
],
),
),
),
);
}
}
================================================
FILE: lib/view/PausePanel.dart
================================================
import 'package:flutter/material.dart';
class PausePanel extends StatelessWidget {
double width, height;
TextStyle textStyle;
PausePanel({Key key, this.width, this.height}) : super(key: key) {
textStyle = new TextStyle(
fontSize: 28.0,
color: Colors.white,
fontWeight: FontWeight.bold
);
}
@override
Widget build(BuildContext context) {
return new Container(
width: this.width,
height: this.height,
color: Color(0x50000000),
child: new Center(
child: new Text("游戏已暂停", style: textStyle)
),
);
}
}
================================================
FILE: lib/view/PlayPanel.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/constants/Constants.dart';
import 'package:flutter_tetris/view/Shape.dart';
import 'package:flutter_tetris/view/Ground.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/event/StatusEvent.dart';
import 'package:flutter_tetris/view/PausePanel.dart';
import 'package:flutter_tetris/view/GameOverPanel.dart';
class PlayPanel extends StatefulWidget {
int hCount, vCount;
double width, height;
Shape shape;
Ground ground;
PausePanel pausePanel;
GameOverPanel gameOverPanel;
PlayPanel({Key key, this.width, this.height, this.hCount, this.vCount}) : super(key: key) {
this.ground = new Ground(hCount: hCount, vCount: vCount);
this.shape = new Shape(hCount: hCount, vCount: vCount, ground: this.ground);
this.pausePanel = new PausePanel(width: hCount * Constants.cellWidth, height: vCount * Constants.cellWidth);
this.gameOverPanel = new GameOverPanel(width: hCount * Constants.cellWidth, height: vCount * Constants.cellWidth);
}
@override
State createState() => PlayPanelState();
}
class PlayPanelState extends State {
bool isPause = false;
bool isGameOver = false;
@override
void initState() {
super.initState();
Global.eventBus.on().listen((event) {
if (event.type == Status.gamePause) {
setState(() {
this.isPause = event.isPause;
});
} else if (event.type == Status.gameOver) {
setState(() {
this.isGameOver = true;
});
} else if (event.type == Status.replay) {
setState(() {
this.isGameOver = false;
this.isPause = false;
});
}
});
}
@override
Widget build(BuildContext context) {
List items = [
this.widget.shape,
this.widget.ground
];
if (isPause) {
items.add(this.widget.pausePanel);
}
if (isGameOver) {
items.add(this.widget.gameOverPanel);
}
return new Container(
margin: const EdgeInsets.all(Constants.bodyPadding),
width: this.widget.width - Constants.bodyPadding * 2,
height: this.widget.height - Constants.bodyPadding * 2,
color: Colors.blue,
child: new Center(
child: new Container(
width: this.widget.hCount * Constants.cellWidth,
height: this.widget.vCount * Constants.cellWidth,
color: Colors.white,
child: new Stack(children: items)
),
),
);
}
}
================================================
FILE: lib/view/Shape.dart
================================================
import 'package:flutter/material.dart';
import 'package:flutter_tetris/view/Cell.dart';
import 'package:flutter_tetris/util/Point.dart';
import 'package:flutter_tetris/event/MoveEvent.dart';
import 'package:flutter_tetris/event/StatusEvent.dart';
import 'package:flutter_tetris/constants/Global.dart';
import 'package:flutter_tetris/view/Ground.dart';
import 'package:flutter_tetris/util/ShapeFactory.dart';
import 'dart:async';
// 代表一个图形
class Shape extends StatefulWidget {
int autoMoveDownDuration = 300;
int curIndex = 0;
bool isShapeDie = true;
ShapeFactory factory = new ShapeFactory();
List>> shapeData, nextShapeData;
// 当前图形的数据,为4x4的矩阵
List> data;
final int initPosY = 0;
// 图形右上角在游戏区域的坐标
int posX, posY;
// 图形所在的游戏区域,水平和垂直方向的方格数
int hCount, vCount;
Ground ground;
Shape({Key key, this.hCount, this.vCount, this.ground}) : super(key: key) {
this.shapeData = factory.getRandomShapeData();
this.data = shapeData[0];
this.posX = hCount ~/ 2 - 2;
this.posY = initPosY;
initNextShapeData();
}
Shape.withData(List>> withData) {
this.shapeData = withData;
this.data = withData[0];
}
initNextShapeData() {
nextShapeData = factory.getRandomShapeData();
new Timer(new Duration(seconds: 1), () {
Global.eventBus.fire(new StatusEvent(type: Status.nextShapeData, nextShapeData: nextShapeData));
});
}
resetShape() {
this.shapeData = this.nextShapeData;
this.data = shapeData[0];
this.posX = hCount ~/ 2 - 2;
this.posY = initPosY;
initNextShapeData();
}
setEmptyData() {
this.shapeData = factory.getEmptyShapeData();
this.data = shapeData[0];
}
// 获取4*4的图形
Widget getShapeView() {
List rows = new List();
for (int row = 0; row < 4; row++) {
List rowData = new List();
for (int col = 0; col < 4; col++) {
Point point = new Point(col, row);
rowData.add(new Cell(color: Colors.blue, point: point, isFill: data[row][col] == 1, shapeOrGroundData: data));
}
rows.add(new Row(children: rowData));
}
return new Column(children: rows);
}
@override
State createState() => ShapeState();
}
class ShapeState extends State {
Timer shapeTimer;
bool isPause = false;
// 判断图形的某一列是否存在实心Cell
bool colContainFillCell(int colIndex, {List> data}) {
List> list = this.widget.data;
if (data != null) {
list = data;
}
for (int i = 0; i < 4; i++) {
if (list[i][colIndex] == 1) {
return true;
}
}
return false;
}
// 判断图形的某一行是否存在实心Cell
bool rowContainFillCell(int rowIndex, {List> data}) {
List> list = this.widget.data;
if (data != null) {
list = data;
}
for (int i = 0; i < 4; i++) {
if (list[rowIndex][i] == 1) {
return true;
}
}
return false;
}
// 向下移动图形
void moveDown() {
setState(() {
this.widget.posY += 1;
});
}
// 向左移动图形
void moveLeft() {
if (!this.widget.isShapeDie && !isPause && canMoveLeft()) {
setState(() {
this.widget.posX -= 1;
});
}
}
// 是否能左移
bool canMoveLeft() {
int x = this.widget.posX - 1;
for (int col = 0; col < 4; col++) {
if (colContainFillCell(col) && x + col < 0) {
return false;
}
}
List> groundData = this.widget.ground.data;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (this.widget.data[row][col] == 1 && groundData[row + this.widget.posY][col + x] == 1) {
return false;
}
}
}
return true;
}
// 向右移动图形
void moveRight() {
if (!this.widget.isShapeDie && !isPause && canMoveRight()) {
setState(() {
this.widget.posX += 1;
});
}
}
// 是否能右移
bool canMoveRight() {
int x = this.widget.posX + 1;
for (int col = 3; col >= 0; col--) {
if (colContainFillCell(col) && x + col + 1 > this.widget.hCount) {
return false;
}
}
List> groundData = this.widget.ground.data;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (this.widget.data[row][col] == 1 && groundData[row + this.widget.posY][col + x] == 1) {
return false;
}
}
}
return true;
}
// 是否能下落
bool canMoveDown() {
// 判断是否有触底的
for (int row = 3; row >= 0; row--) {
if (rowContainFillCell(row) && this.widget.posY + row + 1 >= this.widget.vCount) {
return false;
}
}
// 判断是否有跟ground相交的
List> groundData = this.widget.ground.data;
int x = this.widget.posX;
int y = this.widget.posY + 1;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (this.widget.data[row][col] == 1 && groundData[row + y][col + x] == 1) {
return false;
}
}
}
return true;
}
// 旋转图形
void transform() {
if (!isPause && canTransform()) {
setState(() {
this.widget.curIndex = (this.widget.curIndex + 1) % 4;
this.widget.data = this.widget.shapeData[this.widget.curIndex];
});
}
}
// 是否能切换到下一个形状
bool canTransform() {
List> nextShapeData = this.widget.shapeData[(this.widget.curIndex + 1) % 4];
// 是否超出左边界
for (int i = 0; i < 4; i++) {
if (colContainFillCell(i, data: nextShapeData) && this.widget.posX + i < 0) {
return false;
}
}
// 是否超出右边界
for (int i = 3; i >= 0; i--) {
if (colContainFillCell(i, data: nextShapeData) && this.widget.posX + i + 1 > this.widget.hCount) {
return false;
}
}
// 是否超出下边界
for (int i = 3; i >= 0; i--) {
if (rowContainFillCell(i, data: nextShapeData) && this.widget.posY + i + 1 > this.widget.vCount) {
return false;
}
}
// 是否和ground重合
List> groundData = this.widget.ground.data;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (nextShapeData[row][col] == 1 && groundData[row + this.widget.posY][col + this.widget.posX] == 1) {
return false;
}
}
}
return true;
}
// 判断坐标是否落在Shape图形中
bool isPosInShapeArea(Point p) { // Point, x表示col, y表示row
return (p != null) && (p.x >= this.widget.posX && p.x <= this.widget.posX + 3
&& p.y >= this.widget.posY && p.y <= this.widget.posY + 3);
}
@override
void initState() {
super.initState();
Global.eventBus.on().listen((event) {
switch (event.type) {
case MoveEventType.moveLeft:
moveLeft();
break;
case MoveEventType.moveRight:
moveRight();
break;
case MoveEventType.moveDown:
moveDown();
break;
case MoveEventType.transform:
transform();
break;
}
});
Global.eventBus.on().listen((event) {
if (event.type == Status.shapeDieNow && !this.widget.isShapeDie && !isPause) {
// 让shape立即落下到最底部成为ground的一部分
setShapeDieNow();
} else if (event.type == Status.gamePause) {
isPause = event.isPause;
if (event.isPause) {
// 暂停
if (this.shapeTimer != null) {
this.shapeTimer.cancel();
}
} else {
// 继续
startAutoMoveDown();
}
} else if (event.type == Status.replay) {
// 重新开始游戏
setState(() {
isPause = false;
this.widget.resetShape();
startAutoMoveDown();
});
}
});
startAutoMoveDown();
}
gameOver() {
print("fire event, game over...");
Global.eventBus.fire(new StatusEvent(type: Status.gameOver));
}
// 让shape立刻落下
setShapeDieNow() {
// 停止shape的自动下落
if (this.shapeTimer != null) {
this.shapeTimer.cancel();
}
int y = this.widget.posY;
while (canMoveDown()) {
y = ++this.widget.posY;
}
setState(() {
this.widget.posY = y;
});
this.widget.isShapeDie = true;
// 通知Ground图形死掉
Global.eventBus.fire(new StatusEvent(type: Status.shapeDie, shape: this.widget));
if (this.widget.posY == this.widget.initPosY) {
// game over
print('game over...');
gameOver();
return;
}
// 创建新的shape
new Timer(new Duration(milliseconds: 100), () {
this.widget.resetShape();
startAutoMoveDown();
});
}
// 图形自动下落
startAutoMoveDown() {
shapeTimer = new Timer.periodic(new Duration(milliseconds: this.widget.autoMoveDownDuration), (timer) {
if (canMoveDown()) {
this.widget.isShapeDie = false;
moveDown();
} else {
this.widget.isShapeDie = true;
// 通知Ground图形死掉
Global.eventBus.fire(new StatusEvent(type: Status.shapeDie, shape: this.widget));
timer.cancel();
if (this.widget.posY == this.widget.initPosY) {
// game over
print('game over...');
gameOver();
return;
}
// 创建新的shape
new Timer(new Duration(milliseconds: 500), () {
this.widget.resetShape();
startAutoMoveDown();
});
}
});
}
@override
Widget build(BuildContext context) {
List rows = new List();
for (int row = 0; row < this.widget.vCount; row++) { // 行
List rowData = new List| ();
for (int col = 0; col < this.widget.hCount; col++) { // 列
Point point = new Point(col, row);
if (isPosInShapeArea(point)) {
// 如果坐标在图形内,就根据图形的数据生成Cell
rowData.add(new Cell(
color: Colors.blue,
point: new Point(col - this.widget.posX, row - this.widget.posY),
isFill: this.widget.data[row - this.widget.posY][col - this.widget.posX] == 1,
shapeOrGroundData: this.widget.data
));
} else {
// 如果坐标不在图形内,则生成透明的Cell
rowData.add(new Cell(color: Colors.blue, point: new Point(0, 0), isFill: false, shapeOrGroundData: this.widget.data));
}
}
rows.add(new Row(
children: rowData
));
}
return new Column(children: rows);
}
}
================================================
FILE: pubspec.yaml
================================================
name: flutter_tetris
description: a flutter tetris game.
dependencies:
flutter:
sdk: flutter
event_bus: ^1.0.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- images/arrow_left.png
- images/arrow_right.png
- images/arrow_up.png
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
================================================
FILE: test/widget_test.dart
================================================
// This is a basic Flutter widget test.
// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter
// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to
// find child widgets in the widget tree, read text, and verify that the values of widget properties
// are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_tetris/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
| | | | | | |