add 2021
This commit is contained in:
2
2048l/entry/.gitignore
vendored
Normal file
2
2048l/entry/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build
|
||||
/node_modules
|
27
2048l/entry/build.gradle
Normal file
27
2048l/entry/build.gradle
Normal file
@@ -0,0 +1,27 @@
|
||||
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 7
|
||||
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:1.0.0.200'
|
||||
}
|
||||
decc {
|
||||
supportType = ['html','xml']
|
||||
}
|
1
2048l/entry/proguard-rules.pro
vendored
Normal file
1
2048l/entry/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1 @@
|
||||
# config module specific ProGuard rules here.
|
29
2048l/entry/src/main/config.json
Normal file
29
2048l/entry/src/main/config.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.xcl2048.myapplication",
|
||||
"vendor": "xcl2048",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"deviceType": [
|
||||
"Wearable"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
8
2048l/entry/src/main/js/default/app.js
Normal file
8
2048l/entry/src/main/js/default/app.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export default {
|
||||
onCreate() {
|
||||
console.info("Application onCreate");
|
||||
},
|
||||
onDestroy() {
|
||||
console.info("Application onDestroy");
|
||||
}
|
||||
};
|
6
2048l/entry/src/main/js/default/i18n/en-US.json
Normal file
6
2048l/entry/src/main/js/default/i18n/en-US.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World"
|
||||
}
|
||||
}
|
6
2048l/entry/src/main/js/default/i18n/zh-CN.json
Normal file
6
2048l/entry/src/main/js/default/i18n/zh-CN.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界"
|
||||
}
|
||||
}
|
62
2048l/entry/src/main/js/default/pages/index/index.css
Normal file
62
2048l/entry/src/main/js/default/pages/index/index.css
Normal file
@@ -0,0 +1,62 @@
|
||||
.container{
|
||||
width: 454px;
|
||||
height: 454px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.score{
|
||||
text-align: center;
|
||||
width: 234px;
|
||||
height: 30px;
|
||||
letter-spacing: 0px;
|
||||
margin-top: 4px;
|
||||
margin-bottom:6px;
|
||||
}
|
||||
.best{
|
||||
text-align: center;
|
||||
width: 234px;
|
||||
height: 30px;
|
||||
letter-spacing: 0px;
|
||||
margin-top: 19px;
|
||||
}
|
||||
.tile-wrap{
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
flex-wrap: wrap;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
.tile{
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
margin-top: 4px;
|
||||
margin-left: 4px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.btn{
|
||||
width: 135px;
|
||||
height: 45px;
|
||||
background-color: #1F71FF;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.text{
|
||||
font-size: 30px;
|
||||
color: #000000;
|
||||
}
|
||||
.stack{
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
}
|
||||
.subcontainer{
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: transparent;
|
||||
}
|
||||
.gameover{
|
||||
font-size: 40px;
|
||||
color: #FF7500;
|
||||
}
|
23
2048l/entry/src/main/js/default/pages/index/index.hml
Normal file
23
2048l/entry/src/main/js/default/pages/index/index.hml
Normal file
@@ -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">
|
||||
<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>
|
127
2048l/entry/src/main/js/default/pages/index/index.js
Normal file
127
2048l/entry/src/main/js/default/pages/index/index.js
Normal file
@@ -0,0 +1,127 @@
|
||||
import brightness from '@system.brightness';
|
||||
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];
|
||||
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;
|
||||
}
|
||||
},
|
||||
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) 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;
|
||||
},
|
||||
}
|
8
2048l/entry/src/main/resources/base/element/string.json
Normal file
8
2048l/entry/src/main/resources/base/element/string.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "xcl2048",
|
||||
"value": "xcl2048"
|
||||
}
|
||||
]
|
||||
}
|
BIN
2048l/entry/src/main/resources/base/media/icon.png
Normal file
BIN
2048l/entry/src/main/resources/base/media/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
2048l/entry/src/main/resources/base/media/icon_small.png
Normal file
BIN
2048l/entry/src/main/resources/base/media/icon_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Reference in New Issue
Block a user