update gradle
This commit is contained in:
2
2048[HarmonyOS_Js_Full]/entry/.gitignore
vendored
Normal file
2
2048[HarmonyOS_Js_Full]/entry/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build
|
||||
/node_modules
|
26
2048[HarmonyOS_Js_Full]/entry/build.gradle
Normal file
26
2048[HarmonyOS_Js_Full]/entry/build.gradle
Normal file
@@ -0,0 +1,26 @@
|
||||
apply plugin: 'com.huawei.ohos.hap'
|
||||
apply plugin: 'com.huawei.ohos.decctest'
|
||||
//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510
|
||||
ohos {
|
||||
compileSdkVersion 6
|
||||
defaultConfig {
|
||||
compatibleSdkVersion 6
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
proguardOpt {
|
||||
proguardEnabled false
|
||||
rulesFiles 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.200'
|
||||
}
|
||||
decc {
|
||||
supportType = ['html', 'xml']
|
||||
}
|
1
2048[HarmonyOS_Js_Full]/entry/package.json
Normal file
1
2048[HarmonyOS_Js_Full]/entry/package.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
1
2048[HarmonyOS_Js_Full]/entry/proguard-rules.pro
vendored
Normal file
1
2048[HarmonyOS_Js_Full]/entry/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
84
2048[HarmonyOS_Js_Full]/entry/src/main/config.json
Normal file
84
2048[HarmonyOS_Js_Full]/entry/src/main/config.json
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"app": {
|
||||
"apiVersion": {
|
||||
"compatible": 6
|
||||
},
|
||||
"bundleName": "com.xcl20481.myapplication",
|
||||
"vendor": "2048",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.1.2"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {
|
||||
"default": {
|
||||
"keepAlive": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"package": "com.xcl20481.myapplication",
|
||||
"name": "com.xcl20481.myapplication.MyApplication",
|
||||
"mainAbility": "com.xcl20481.myapplication.MainAbility",
|
||||
"reqPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.VIBRATE",
|
||||
"reason": "用于长按振动反馈"
|
||||
}
|
||||
],
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"tv",
|
||||
"wearable"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry",
|
||||
"installationFree": false
|
||||
},
|
||||
"metaData": {
|
||||
"customizeData": [
|
||||
{
|
||||
"name": "hwc-theme",
|
||||
"extra": "",
|
||||
"value": "androidhwext:style/Theme.Emui.Translucent.NoTitleBar"
|
||||
}
|
||||
]
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"visible": true,
|
||||
"name": "com.xcl20481.myapplication.MainAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"label": "$string:xcl2048",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/page0/page0",
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.xcl20481.myapplication;
|
||||
import ohos.ace.ability.AceAbility;
|
||||
import ohos.aafwk.content.Intent;
|
||||
public class MainAbility extends AceAbility {
|
||||
@Override
|
||||
public void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package com.xcl20481.myapplication;
|
||||
|
||||
import ohos.aafwk.ability.AbilityPackage;
|
||||
|
||||
public class MyApplication extends AbilityPackage {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
super.onInitialize();
|
||||
}
|
||||
}
|
7
2048[HarmonyOS_Js_Full]/entry/src/main/js/default/app.js
Normal file
7
2048[HarmonyOS_Js_Full]/entry/src/main/js/default/app.js
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
export default {
|
||||
onCreate() {
|
||||
},
|
||||
onDestroy() {
|
||||
}
|
||||
};
|
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World"
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界"
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
.container{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.score{
|
||||
text-align: center;
|
||||
width: 30.5%;
|
||||
height: 7.4%;
|
||||
letter-spacing: 0px;
|
||||
font-size: 11.5px;
|
||||
margin-top: 0.5%;
|
||||
margin-bottom:1%;
|
||||
color: #eb0bc7f6;
|
||||
}
|
||||
.best{
|
||||
text-align: center;
|
||||
width: 26%;
|
||||
height: 7.4%;
|
||||
font-size: 12.5px;
|
||||
letter-spacing: 0px;
|
||||
margin-top: 3.6%;
|
||||
color: #64f6f3;
|
||||
}
|
||||
.tile-wrap{
|
||||
width: 75%;
|
||||
height: 86.5%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
.tile{
|
||||
width: 24.4%;
|
||||
height: 24.4%;
|
||||
margin-top: 0.5%;
|
||||
margin-left: 0.5%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.btn{
|
||||
width: 26.7%;
|
||||
height: 9%;
|
||||
background-color: #155ddc;
|
||||
margin-top: 2%;
|
||||
margin-bottom:10%;
|
||||
font-size: 13px;
|
||||
}
|
||||
.text{
|
||||
font-size: 13px;
|
||||
color: #000000;
|
||||
}
|
||||
.stack{
|
||||
width: 75%;
|
||||
height: 86.5%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.subcontainer{
|
||||
width: 75%;
|
||||
height: 86.5%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: black;
|
||||
}
|
||||
.gameover{
|
||||
font-size: 32px;
|
||||
color: #FF7500;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<div class="container">
|
||||
<text class="best">
|
||||
Best:{{best}}
|
||||
</text>
|
||||
<text class="score">
|
||||
Score:{{score}}
|
||||
</text>
|
||||
<stack class="stack">
|
||||
<div class="tile-wrap" onswipe="onSwipe" onlongpress="ToAbout">
|
||||
<div class="tile" for="{{tiles}}" style="background-color:#000000">
|
||||
<text class="text" style="color:#FFFFFF">
|
||||
{{$item.text}}
|
||||
</text>
|
||||
</div>
|
||||
</div>
|
||||
<div class="subcontainer" show="{{isShow}}">
|
||||
<text class="gameover">
|
||||
Gameover!
|
||||
</text>
|
||||
</div>
|
||||
</stack>
|
||||
<input class="btn" type="button" value="Restart!" onclick="onInit" ></input>
|
||||
</div>
|
@@ -0,0 +1,162 @@
|
||||
import brightness from '@system.brightness';
|
||||
import vibrator from '@system.vibrator';
|
||||
import prompt from '@system.prompt';
|
||||
let numbers,newNumbers;
|
||||
export default{
|
||||
data:{
|
||||
score:0,
|
||||
best:0,
|
||||
tiles:[],
|
||||
isShow:false,
|
||||
},
|
||||
onInit() {
|
||||
this.isShow=false;
|
||||
this.score=0;
|
||||
this.tiles=[{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""},{text:""}];
|
||||
numbers=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
||||
newNumbers=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
||||
vibrator.vibrate({
|
||||
mode: 'short',
|
||||
success: function(ret) {
|
||||
console.log('tzx vibrate is successful');
|
||||
},
|
||||
fail: function(ret) {
|
||||
console.log('tzx vibrate is failed');
|
||||
},
|
||||
complete: function(ret) {
|
||||
console.log('tzx vibrate is completed');
|
||||
}
|
||||
});
|
||||
this.supplyNumber();
|
||||
this.supplyNumber();
|
||||
this.updateView();
|
||||
brightness.setKeepScreenOn({keepScreenOn: true,});
|
||||
brightness.setMode({mode: 1,});
|
||||
},
|
||||
supplyNumber(){
|
||||
let positions=[];
|
||||
for(let i=0;i<=15;i++){
|
||||
if(!newNumbers[i]) positions.push(i);
|
||||
}
|
||||
let h=Math.floor(Math.random()*positions.length);
|
||||
if (Math.random()<=0.8){
|
||||
newNumbers[positions[h]]=2;
|
||||
}else{
|
||||
newNumbers[positions[h]]=4;
|
||||
}
|
||||
},
|
||||
ToAbout(){
|
||||
prompt.showToast({
|
||||
message: '这是小草林开发的2048小游戏',
|
||||
duration: 4567,
|
||||
});
|
||||
},
|
||||
onSwipe(e) {
|
||||
newNumbers=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
||||
let start=0,differ=0,step=0;
|
||||
switch(e.direction){
|
||||
case 'left':
|
||||
start=0;
|
||||
differ=1;
|
||||
step=4;
|
||||
break;
|
||||
case 'right':
|
||||
start=3;
|
||||
differ=-1;
|
||||
step=4;
|
||||
break;
|
||||
case 'up':
|
||||
start=0;
|
||||
differ=4;
|
||||
step=1;
|
||||
break;
|
||||
case 'down':
|
||||
start=12;
|
||||
differ=-4;
|
||||
step=1;
|
||||
break;
|
||||
}
|
||||
let ids;
|
||||
for (let j=0;j<=3;j++){
|
||||
ids=this.getIds(start, differ);
|
||||
let before=null;
|
||||
let noZeros=0;
|
||||
for(let k=0;k<=3;k++){
|
||||
let id=ids[k];
|
||||
let number=numbers[id];
|
||||
if (number!=0){
|
||||
if(number==before){
|
||||
this.score+=number*2;
|
||||
newNumbers[ids[noZeros-1]]*=2;
|
||||
before=null;
|
||||
}else{
|
||||
newNumbers[ids[noZeros]]=number;
|
||||
before=number;
|
||||
noZeros+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
start+=step;
|
||||
}
|
||||
if(this.best>=this.score){
|
||||
this.best=this.best;
|
||||
}else{
|
||||
this.best=this.score;}
|
||||
if(numbers.toString()!=newNumbers.toString()){
|
||||
this.supplyNumber();
|
||||
this.updateView();
|
||||
newNumbers=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
||||
if(this.isGameOver()==true){this.isShow=true;}
|
||||
}
|
||||
},
|
||||
getIds(start, differ){
|
||||
let ids=[];
|
||||
for (let z=4;z>=1;z--){
|
||||
ids.push(start);
|
||||
start+=differ;
|
||||
}
|
||||
return ids;
|
||||
},
|
||||
updateView() {
|
||||
for (let x=0;x<=15;x++) {
|
||||
if (newNumbers[x]!=0){
|
||||
this.tiles[x].text=newNumbers[x].toString();
|
||||
}else{
|
||||
this.tiles[x].text="";
|
||||
}
|
||||
}
|
||||
numbers=newNumbers;
|
||||
},
|
||||
isGameOver(){
|
||||
if(this.isGridsFull()==true && this.isGridsNotMergeable()==true){
|
||||
vibrator.vibrate({
|
||||
mode: 'long',
|
||||
success: function(ret) {
|
||||
console.log('vibrate is successful');
|
||||
},
|
||||
fail: function(ret) {
|
||||
console.log('vibrate is failed');
|
||||
},
|
||||
complete: function(ret) {
|
||||
console.log('vibrate is completed');
|
||||
}
|
||||
});
|
||||
console.info('游戏结束');
|
||||
return true;
|
||||
}
|
||||
},
|
||||
isGridsFull(){
|
||||
if(numbers.indexOf(0)==-1){return true;}
|
||||
},
|
||||
isGridsNotMergeable(){
|
||||
for(let l=0;l<=15;l++){
|
||||
if(l<=14){
|
||||
if(numbers[l]==numbers[l+1]&&(l+1)%4!=0) return false;
|
||||
}
|
||||
if(l<=11){
|
||||
if(numbers[l]==numbers[l+4]) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
.container{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.title {
|
||||
text-align: center;
|
||||
width: 62%;
|
||||
height: 22%;
|
||||
letter-spacing: 0px;
|
||||
font-size: 19px;
|
||||
margin-top: 20%;
|
||||
margin-bottom:2%;
|
||||
color: #eb0750cb;
|
||||
}
|
||||
.title1 {
|
||||
text-align: center;
|
||||
width: 78%;
|
||||
height: 65%;
|
||||
font-size: 15.5px;
|
||||
margin-top: 2%;
|
||||
margin-bottom:1%;
|
||||
color: #eb0597bb;
|
||||
}
|
||||
.btn{
|
||||
width: 28.5%;
|
||||
height: 15.5%;
|
||||
background-color: #155ddc;
|
||||
margin-top: 20%;
|
||||
font-size: 13px;
|
||||
margin-bottom: 15%;
|
||||
}
|
||||
.btn1{
|
||||
width: 28.5%;
|
||||
height: 15.5%;
|
||||
background-color: #155ddc;
|
||||
margin-top: 15%;
|
||||
font-size: 13px;
|
||||
margin-bottom: 35%;
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<div class="container">
|
||||
<text class="title">
|
||||
《2048小游戏》
|
||||
</text>
|
||||
<text class="title1">
|
||||
开始游戏即默认同意我的隐私声明:www.xuegao-tzx.top/g2048h.html
|
||||
</text>
|
||||
<input class="btn" type="button" value="开始" onclick="ToStart"></input>
|
||||
<input class="btn1" type="button" value="退出" onclick="ToClose"></input>
|
||||
</div>
|
@@ -0,0 +1,59 @@
|
||||
import router from '@system.router'
|
||||
import app from '@system.app'
|
||||
import brightness from '@system.brightness';
|
||||
import vibrator from '@system.vibrator';
|
||||
import prompt from '@system.prompt';
|
||||
export default {
|
||||
onInit() {
|
||||
brightness.setKeepScreenOn({keepScreenOn: true,});
|
||||
brightness.setMode({mode: 1,});
|
||||
},
|
||||
onSwipe(e) {
|
||||
switch (e.direction) {
|
||||
case 'left':
|
||||
break;
|
||||
case 'right':
|
||||
break;
|
||||
case 'up':
|
||||
break;
|
||||
case 'down':
|
||||
break;
|
||||
}
|
||||
},
|
||||
ToStart(){
|
||||
vibrator.vibrate({
|
||||
mode: 'short',
|
||||
success: function(ret) {
|
||||
console.log('tzx vibrate is successful');
|
||||
},
|
||||
fail: function(ret) {
|
||||
console.log('tzx vibrate is failed');
|
||||
},
|
||||
complete: function(ret) {
|
||||
console.log('tzx vibrate is completed');
|
||||
}
|
||||
});
|
||||
prompt.showToast({
|
||||
message: '开始成功,By Xcl!',
|
||||
duration: 3579,
|
||||
});
|
||||
router.replace({
|
||||
uri: "pages/index/index",
|
||||
});
|
||||
},
|
||||
ToClose(){
|
||||
vibrator.vibrate({
|
||||
mode: 'short',
|
||||
success: function(ret) {
|
||||
console.log('tzx vibrate is successful');
|
||||
},
|
||||
fail: function(ret) {
|
||||
console.log('tzx vibrate is failed');
|
||||
},
|
||||
complete: function(ret) {
|
||||
console.log('tzx vibrate is completed');
|
||||
}
|
||||
});
|
||||
app.terminate();
|
||||
},
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "xcl2048",
|
||||
"value": "xcl2048"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "JS_Empty Ability"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
@@ -0,0 +1,14 @@
|
||||
package com.xcl20481.myapplication;
|
||||
|
||||
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ExampleOhosTest {
|
||||
@Test
|
||||
public void testBundleName() {
|
||||
final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
|
||||
assertEquals("com.xcl20481.myapplication", actualBundleName);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
export default {
|
||||
onCreate() {
|
||||
console.info('TestApplication onCreate');
|
||||
},
|
||||
onDestroy() {
|
||||
console.info('TestApplication onDestroy');
|
||||
}
|
||||
};
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
.container {
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 100px;
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<div class="container">
|
||||
<text class="title">
|
||||
{{ $t('strings.hello') }} {{ title }}
|
||||
</text>
|
||||
</div>
|
@@ -0,0 +1,41 @@
|
||||
import file from '@system.file'
|
||||
import app from '@system.app'
|
||||
import device from '@system.device'
|
||||
import router from '@system.router'
|
||||
import {Core, Constant, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index'
|
||||
|
||||
export default {
|
||||
data: {
|
||||
title: ""
|
||||
},
|
||||
onInit() {
|
||||
this.title = this.$t('strings.world');
|
||||
},
|
||||
onShow() {
|
||||
console.info('onShow finish')
|
||||
const core = Core.getInstance()
|
||||
const expectExtend = new ExpectExtend({
|
||||
'id': 'extend'
|
||||
})
|
||||
const reportExtend = new ReportExtend(file)
|
||||
const instrumentLog = new InstrumentLog({
|
||||
'id': 'report',
|
||||
'version': '1.0.3'
|
||||
})
|
||||
core.addService('expect', expectExtend)
|
||||
core.addService('report', reportExtend)
|
||||
core.addService('report', instrumentLog)
|
||||
core.init()
|
||||
core.subscribeEvent('spec', instrumentLog)
|
||||
core.subscribeEvent('suite', instrumentLog)
|
||||
core.subscribeEvent('task', instrumentLog)
|
||||
|
||||
const configService = core.getDefaultService('config')
|
||||
configService.setConfig(this)
|
||||
|
||||
require('../../../test/List.test')
|
||||
core.execute()
|
||||
},
|
||||
onReady() {
|
||||
},
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
import app from '@system.app'
|
||||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
|
||||
|
||||
describe('appInfoTest', function () {
|
||||
it('app_info_test_001', 0, function () {
|
||||
var info = app.getInfo()
|
||||
expect(info.versionName).assertEqual('1.0')
|
||||
expect(info.versionCode).assertEqual('3')
|
||||
})
|
||||
})
|
@@ -0,0 +1 @@
|
||||
require('./ExampleJsunit.test.js')
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "MyApplication"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "hap sample empty page"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
Reference in New Issue
Block a user