1
0

Add files via upload

This commit is contained in:
tzx 2021-06-17 08:49:29 +08:00 committed by GitHub
parent d640b62eef
commit 70b5475d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 270 additions and 0 deletions

42
src/main/config.json Normal file
View File

@ -0,0 +1,42 @@
{
"app": {
"apiVersion": {
"compatible": 3,
"target": 4,
"releaseType": "Release"
},
"bundleName": "my.game20481.myapplication",
"vendor": "game20481",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"deviceType": [
"liteWearable"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"name": "default",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"type": "page"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default"
}
]
}
}

View File

@ -0,0 +1,8 @@
export default {
onCreate() {
console.info("Application onCreate");
},
onDestroy() {
console.info("Application onDestroy");
}
};

View 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;
}

View 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>

View 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;
},
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB