Commit 2a109b3d authored by 杨一航's avatar 杨一航

feat: v0.9

parent 9fe63b50
This source diff could not be displayed because it is too large. You can view the blob instead.
import LoadingLayer from "../script/LoadingLayer_PK_Game";
import EndLayer from "../script/layers/endLayer_PK_Game";
import GameLayer from "../script/layers/gameLayer_PK_Game";
import HomeLayer from "../script/layers/homeLayer_PK_Game";
import MatchLayer from "../script/layers/matchLayer_PK_Game";
import MyInfo from "../script/layers/myInfo_PK_Game";
import RankLayer from "../script/layers/rankLayer_PK_Game";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent_PK_Game";
import { NetworkHelper } from "../script/NetworkHelper_PK_Game";
import { GameServer } from "../script/Server_PK_Game";
import { asyncTweenTo, asyncDelay, onHomeworkFinish } from "../script/util_PK_Game";
import BoardCardItem from "./boardCardItem_PK_Game";
import { asyncDelay, getLv } from "../script/util_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Prefab)
loadingLayerPrefab = null;
excellent: any;
_nowData: any;
private _myData: any;
private _loadingDone: boolean = false;
private _redOriginPos: any;
private _blueOriginPos: any;
private _playingAudio: boolean;
private _canClick: any;
private _recordBefore: boolean = false;
_duck1To: number;
private _duck1Now: number;
private _duck2To: number;
private _duck2Now: number;
private _status: any;
@property(cc.Node)
homeLayer = null;
@property(cc.Node)
matchLayer = null;
@property(cc.Node)
gameLayer = null;
@property(cc.Node)
endLayer = null;
@property(cc.Node)
rankLayer = null;
@property(cc.Node)
myInfoNode = null;
@property(cc.Button)
btn_back = null;
@property(cc.Button)
btn_rule = null;
@property(cc.Button)
btn_single = null;
private _status: any;
homeLayerCom: HomeLayer;
matchLayerCom: MatchLayer;
gameLayerCom: GameLayer;
endLayerCom: EndLayer;
rankLayerCom: RankLayer;
myInfoCom: MyInfo;
layerIndex: number;
headUrl: "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png"
userName: "test"
otherData: any;
rankData: any;
myrank: number;
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
......@@ -52,6 +71,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
onLoadEnd() {
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
cc.log("============")
cc.log(this.data);
this.log("onLoadEnd");
this.initData();
this.initView();
......@@ -59,18 +80,148 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
//------------
initData() {
this.data.url = this.data.url || this.headUrl;
this.data.name = this.data.name || this.userName;
this.rankData = this.data.rank;
this.rankData.sort((a, b) => {
return b.score - a.score;
})
}
initView() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
this.homeLayerCom = this.homeLayer.getComponent(HomeLayer);
this.matchLayerCom = this.matchLayer.getComponent(MatchLayer);
this.gameLayerCom = this.gameLayer.getComponent(GameLayer);
this.endLayerCom = this.endLayer.getComponent(EndLayer);
this.rankLayerCom = this.rankLayer.getComponent(RankLayer);
this.myInfoCom = this.myInfoNode.getComponent(MyInfo);
this.gameLayerCom.mainCom = this;
this.endLayerCom.mainCom = this;
this.rankLayerCom.mainCom = this;
this.homeLayer.active = true;
this.matchLayer.active = false;
this.gameLayer.active = false;
this.endLayer.active = false;
this.rankLayer.active = false;
this.myInfoNode.active = true;
this.myInfoCom.mainCom = this;
this.layerIndex = 0;
this.rankLayerCom.init(this.rankData);
this.data.myInfo.rank = this.rankLayerCom.setMyInfo(this.data.myInfo)
this.myInfoCom.init(this.data.myInfo)
this.homeLayerCom.initCup(this.data.myInfo.score)
this.homeLayerCom.startCallBack = this.onStartGame.bind(this);
// this.btn_back.node.on("click", this.onClickBack, this)
// this.btn_rule.node.on("click", this.onClickBack, this)
// this.btn_single.node.on("click", this.onClickBack, this)
}
onClickBack() {
this.playLocalAudio("btn")
switch (this.layerIndex) {
case 0:
// 推到大厅
break;
case 1:
// 推到home 界面
this.myInfoCom.show()
this.homeLayer.active = true;
this.matchLayer.active = false;
break;
case 2:
break;
}
}
backHome() {
this.homeLayer.active = true;
this.matchLayer.active = false;
this.gameLayer.active = false;
this.endLayer.active = false;
this.rankLayer.active = false;
this.myInfoCom.show();
}
async onStartGame() {
this.layerIndex = 1;
this.playLocalAudio("btn")
this.homeLayer.active = false;
this.matchLayer.active = true;
this.myInfoCom.hide()
this.matchLayerCom.startMatch(this.data.myInfo);
await asyncDelay(1)
this.openNetSever();
}
openGameLayer() {
this.layerIndex = 2;
this.homeLayer.active = false;
this.matchLayer.active = false;
this.gameLayer.active = true;
this.gameLayerCom.init(this.data.myInfo, this.otherData, () => {
this.networkHelper.sendFrame({
type: "gamePrepare",
uuid: this.playerId,
});
});
}
showRank() {
this.myInfoCom.openMask();
this.rankLayer.active = true;
this.rankLayerCom.show();
}
hideRank() {
this.myInfoCom.hideMask();
}
showRish() {
}
initListener() {
}
playerId;
isRoomOwner;
server: GameServer;
networkHelper: NetworkHelper;
async initData() {
// this.initCards();
async openNetSever() {
this.networkHelper = new NetworkHelper();
this.initNetworkListener();
do {
this.playerId = await this.networkHelper.init("op_16_2", 2);
this.playerId = await this.networkHelper.init("pk_game", 2);
if (this.playerId === null) {
this.log("onDestroy");
this.networkHelper.onDestroy();
......@@ -86,20 +237,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
// this.server.jumpList = this.getJumpList();
// this.server.randomList = this._randomList;
// this.server.TotalStep = this._cardList.length;
await this.networkHelper.startFrameSync();
this.server.addPlayer({
uuid: this.playerId,
isAI: false,
lv: this.data.myInfo.lv,
score: this.data.myInfo.score,
rank: this.data.myInfo.rank,
});
this.server.startMatch();
this.server.initQuestion(this.data.question);
let lv = getLv(this.data.myInfo.score)
this.server.startMatch(lv);
}
await this.initHeadImgAndName();
}
async initHeadImgAndName() {
const playerInfo: any = {
playerHeadUrl: "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
playerName: "test",
playerHeadUrl: this.data.url || this.headUrl,
playerName: this.data.name || this.userName,
};
const middleLayer = cc.find("middleLayer");
if (middleLayer) {
......@@ -113,86 +270,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
playerInfo.playerName = kidInfo.nick_name || '拼读达人';
}
}
this.networkHelper.sendFrame({
type: "playerInfo",
playerId: this.playerId,
uuid: this.playerId,
playerName: playerInfo.playerName,
playerHeadUrl: playerInfo.playerHeadUrl,
});
}
initView() {
this.initBg();
this.initLoadingLayer();
}
initBg() {
const bgNode = cc.find('Canvas/bg');
bgNode.scale = this._mapScaleMax;
// this.cover.width = cc.winSize.width;
// this.cover.height = cc.winSize.height;
// this.cover.getChildByName("bg").scale = this._mapScaleMax;
const endRoot = cc.find("Canvas/endRoot")
endRoot.scale = this._mapScaleMax;
// const bg1 = cc.find("Canvas/bg1")
// bg1.width = cc.winSize.width;
// bg1.height = cc.winSize.height;
}
loadingLayer;
initLoadingLayer() {
const loadingLayerNode = cc.instantiate(this.loadingLayerPrefab);
loadingLayerNode.parent = this.node;
loadingLayerNode.zIndex = 100;
this.loadingLayer = loadingLayerNode.getComponent(LoadingLayer);
this.loadingLayer.setMaxPlayerNumber(2);
this.loadingLayer.onLoadFinished(() => {
this.playAudioByUrl(this.data.gameStartAudio);
this._loadingDone = true;
// this.updateStatus();
});
this.playAudioByUrl(this.data.gameLoadingAudio);
// this.networkHelper.sendFrame({
// type: "playerInfo",
// playerId: this.playerId,
// uuid: this.playerId,
// playerName: playerInfo.playerName,
// playerHeadUrl: playerInfo.playerHeadUrl,
// });
}
initListener() {
}
roundEndCheck(isRight?) {
this.networkHelper.sendFrame({
type: "stateUpdate",
uuid: this.myData.uuid,
});
// this.networkHelper.sendFrame({
// type: "stateUpdate",
// uuid: this.myData.uuid,
// });
}
......@@ -202,14 +298,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
get myData() {
if (!this._myData) {
const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId
);
this._myData = playerMe;
}
return this._myData;
return
}
......@@ -217,7 +307,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
initNetworkListener() {
this.networkHelper.on("playerJoin", (event) => {
if (this.server) {
this.server.onPlayerJoin({ data: { joinPlayerId: event.playerId } });
this.server.onPlayerJoin(
{
data:
{
joinPlayerId: event.playerId,
lv: event.lv,
score: event.score,
rank: event.rank,
}
});
}
this.log("playerJoin" + JSON.stringify(event, null, 2));
});
......@@ -260,49 +359,40 @@ export default class SceneComponent extends MyCocosSceneComponent {
color: player.color,
headUrl: player.headUrl,
});
}
this.otherData = player;
this.loadPlayerHeadImage();
this.playLocalAudio("match")
this.matchLayerCom.addOther(this.otherData, this.openGameLayer.bind(this));
}
this.loadingLayer.addPlayer(
player.name,
player.uuid == this.playerId,
player.headUrl,
player.uuid
);
});
} else if (item.data.type == "SERVER_updateStatus") {
this._status = JSON.parse(JSON.stringify(item.data.status));
// this.updateStatus();
} else if (item.data.type == "SERVER_playerRoll") {
} else if (item.data.type == "SERVER_gameEv") {
this._status = JSON.parse(JSON.stringify(item.data.status));
if (this._status?.state == 1) {
let question = JSON.parse(JSON.stringify(item.data.question));
this.gameLayerCom.initQuestion(question, this._status?.index);
}
this.roundEndCheck();
}
else if (item.data.type == "SERVER_playerRight") {
else if (item.data.type == "SERVER_gameSettle") {
this.gameLayerCom.settle(item.data)
this.roundEndCheck(true);
} else if (item.data.type == "SERVER_gameSettleEnd") {
this.gameLayerCom.hide()
await asyncDelay(0.5);
} else if (item.data.type == "SERVER_playerWrong") {
this.myInfoCom.init(this.data.myInfo);
this.myInfoCom.show();
this.endLayer.active = true;
this.endLayerCom.init(item.data, this.data.myInfo, this.otherData);
await asyncDelay(2);
this.roundEndCheck();
} else if (item.data.type == "SERVER_playerWin") {
this._status = JSON.parse(JSON.stringify(item.data.status));
const node = cc.find(
`Canvas/road/root/piece${this._status.current}`
);
await this.toEnd()
// if (this.isMySide) {
// this.showWin();
// onHomeworkFinish({ isWin: true });
// } else {
// this.showLoss();
// onHomeworkFinish({ isWin: false });
// }
}
});
});
......@@ -332,21 +422,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.playLocalAudio("loss");
}
loadPlayerHeadImage() {
const red = cc.find("Canvas/road/redHead/icon");
const blue = cc.find("Canvas/road/blueHead/icon");
this.allPlayerList.forEach((player) => {
this.getSpriteFrimeByUrl(player.headUrl, (sf) => {
if (player.color == "Red") {
red.getComponent(cc.Sprite).spriteFrame = sf;
} else {
blue.getComponent(cc.Sprite).spriteFrame = sf;
}
});
});
}
......
......@@ -2,54 +2,65 @@
import { NetworkHelper } from "./NetworkHelper_PK_Game";
import { asyncDelay } from "./util_PK_Game";
const ansPro = [0.1, 0.2, 0.3, 0.4, 0.7, 0.8, 0.9]
export class AI {
networkHelper: NetworkHelper;
playerData: any;
_status = {
state: -1,// -1:未开始 0 准备阶段 1 roll 2 判定
Red: -1,
Blue: 0,
step: 0,
current: "Blue",
jump: null,
};
anspronum: number;
constructor(networkHelper: NetworkHelper, playerData: any) {
this.networkHelper = networkHelper;
this.playerData = playerData;
this.anspronum = ansPro[this.playerData.lv]
}
async onFrameEvent(data) {
console.log("AI get event: " + JSON.stringify(data));
if (data.type == "SERVER_updateStatus") {
if (data.type == "SERVER_allPlayerInfo") {
this.networkHelper.sendFrame({
type: "gamePrepare",
uuid: this.playerData.uuid,
});
this._status = JSON.parse(JSON.stringify(data.status));
}
if (data.type == "SERVER_gameEv") {
if (this.playerData.color != this._status.current) return
cc.log("ai on msg SERVER_gameEv")
if (!this._status.step) {
await asyncDelay(Math.random() * 3 + 2);
if (!data.question) {
console.log("AI rolling");
this.networkHelper.sendFrame({
type: "roll",
uuid: this.playerData.uuid,
});
} else {
await asyncDelay(Math.random() * 3 + 2);
if (Math.random() < 0.7) {
this.networkHelper.sendFrame({
type: "right",
uuid: this.playerData.uuid,
});
return;
cc.log(data);
}
let rigthIndex = data.question.rightIndex;
let time = 2 + Math.floor(Math.random() * 4)
await asyncDelay(time);
let index = 0;
if (Math.random() <= this.anspronum) {
index = rigthIndex;
} else {
index = Math.floor(Math.random() * 3.99);
while (index == rigthIndex) {
index = Math.floor(Math.random() * 3.99);
}
}
this.networkHelper.sendFrame({
type: "wrong",
type: "anserQues",
uuid: this.playerData.uuid,
index: index
});
}
}
}
}
......
......@@ -29,13 +29,27 @@ export class GameServer {
"http://staging-teach.cdn.ireadabc.com/f40ce4a8630039c4cf48a63fc1399c52.png",
];
jumpList = [
// { from: 2, rto: 11 ,wto:1},
];
lvData = {
0: { min: 0, max: 999, questionNun: 5, tiket: 5, award: 10 },
1: { min: 1000, max: 5000 - 1, questionNun: 5, tiket: 10, award: 20 },
2: { min: 5000, max: 20000 - 1, questionNun: 10, tiket: 20, award: 40 },
3: { min: 20000, max: 50000 - 1, questionNun: 10, tiket: 40, award: 80 },
4: { min: 50000, max: 2000000 - 1, questionNun: 10, tiket: 60, award: 120 },
5: { min: 2000000, max: 5000000 - 1, questionNun: 20, tiket: 120, award: 240 },
}
private _totalStep: any;
randomList = [];
private _useAI: boolean;
answerIndex: number;
prepareNum: number;
questionData: any;
answerData: any[];
matchLv: any;
answerCount: number;
settleTimer: number;
constructor(playerMaxNumber, networkHelper) {
this.playerMaxNumber = playerMaxNumber;
......@@ -56,9 +70,11 @@ export class GameServer {
name: this.nameList.splice(0, 1)[0],
uuid: player.uuid,
color:
player.uuid == this.networkHelper.room.roomInfo.owner ? "Red" : "Blue",
player.uuid == this.networkHelper.room.roomInfo.owner ? "Blue" : "Red",
isAI: player.isAI,
headUrl: this.headUrls.splice(0, 1)[0],
score: player.score,
lv: player.lv,
});
if (player.isAI) {
......@@ -78,14 +94,22 @@ export class GameServer {
}
gameStatus = {
state: 0,// -1:未开始 0 准备阶段 1 roll 2 判定
Red: -1,
Blue: -1,
step: 0,
current: "Red",
jump: false,
state: 0,// -1:未开始 0 准备阶段 1 开始
index: 0,
blueRight: 0,
redRight: 0,
total: 0
};
startGame() {
this.answerIndex = 0;
this.prepareNum = 0;
this.answerCount = 0
this.gameStatus.index = 0;
this.gameStatus.state = 0;
this.gameStatus.blueRight = 0;
this.gameStatus.redRight = 0;
this.gameStatus.total = this.lvData[this.matchLv].questionNun;
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
status: this.gameStatus,
......@@ -96,29 +120,44 @@ export class GameServer {
this.addPlayer({
uuid: event.data.joinPlayerId,
isAI: false,
lv: event.data.lv,
score: event.data.score,
rank: event.data.rank,
});
}
_aiPlayerList = [];
startMatch() {
startMatch(matchLv) {
this.matchLv = matchLv;
for (let i = 0; i < this.playerMaxNumber; i++) {
this._timeoutIds.push(
setTimeout(() => {
const count = this.playerMaxNumber - this.playerList.length;
if (count > 0) {
const playerInfo = {
uuid: "ai_" + i,
isAI: true,
color: "Blue",
};
const playerInfo = this.randomAiPlayer(i, matchLv);
this._aiPlayerList.push(new AI(this.networkHelper, playerInfo));
this.addPlayer(playerInfo);
}
}, RandomInt(10000, 15000))
}, RandomInt(5000, 1000))
);
}
}
randomAiPlayer(index, matchLv) {
let matchInfo = this.lvData[matchLv];
let randomScore = matchInfo.min + Math.floor(Math.random() * matchInfo.max - matchInfo.min);
let data = {
uuid: "ai_" + index,
isAI: true,
color: "Red",
lv: matchLv,
score: randomScore,
}
return data;
}
async onFrameEvent(data) {
if (this.gameStatus['gameOver']) {
return;
......@@ -145,93 +184,88 @@ export class GameServer {
this.startAI();
}
}
else if (data.type == "roll") {
else if (data.type == "gamePrepare") {
if (!data.uuid) {
console.warn("data no uuid");
return;
}
if (sender.color == this.gameStatus.current) {
let nowStep = this.gameStatus[this.gameStatus.current];
let index = Math.floor(Math.random() * this.randomList.length)
let step = this.randomList[index];
// if (nowStep < 5) {
// step = 3;
// } else {
// step = 1;
// }
this.prepareNum++;
if (this.prepareNum == 2) {
step = Math.min(step, this._totalStep - 1 - nowStep);
console.log("random step ===" + step);
this.gameStatus.step = step;
this.prepareNum = 0
this.gameStatus.index = 0;
this.gameStatus.state = 1;
this.answerIndex = 0;
this.answerCount = 0;
this.answerData = [];
let question = this.questionData[this.answerIndex];
this.networkHelper.sendFrame({
type: "SERVER_playerRoll",
type: "SERVER_gameEv",
status: this.gameStatus,
question: question
});
// 开始计时11秒
this.countToSettle(11);
}
}
else if (data.type == "anserQues") {
console.log("data = " + JSON.stringify(data));
this.answerCount++;
let quetion = this.questionData[this.answerIndex]
this.answerData = this.answerData || [];
this.answerData.push(data);
if (quetion.rightIndex == data.index) {
if (sender.color == "Red") {
this.gameStatus.redRight += 1;
} else {
console.warn("data uuid not match");
this.gameStatus.blueRight += 1;
}
}
else if (data.type == "right") {
let nowStep: number = this.gameStatus[this.gameStatus.current];
console.log("nowStep === " + nowStep);
const jump = this.jumpList.find(jump => parseInt(jump.from) == nowStep + this.gameStatus.step);
this.gameStatus[this.gameStatus.current] = jump?.rto ? parseInt(jump.rto) : nowStep + this.gameStatus.step;
if (jump) {
console.log("jump=============");
console.log(jump);
}
if (this.gameStatus[this.gameStatus.current] < this._totalStep - 1) {
this.gameStatus.step = null;
this.gameStatus.state = 2;
this.gameStatus.jump = !!jump?.rto;
this.networkHelper.sendFrame({
type: "SERVER_playerRight",
status: this.gameStatus,
});
this.changeSide();
} else {
this.gameStatus.state = 2;
this.gameStatus.step = null;
this.gameStatus.jump = !!jump;
if (this.answerCount == 2) {
clearTimeout(this.settleTimer)
this.networkHelper.sendFrame({
type: "SERVER_playerWin",
type: "SERVER_gameSettle",
status: this.gameStatus,
ans: this.answerData
});
this.gameStatus['gameOver'] = true;
}
} else if (data.type == "wrong") {
console.log("data = " + JSON.stringify(data));
let nowStep: number = this.gameStatus[this.gameStatus.current];
console.log("nowStep === " + nowStep);
const jump = this.jumpList.find(jump => parseInt(jump.from) == nowStep + this.gameStatus.step);
this.gameStatus[this.gameStatus.current] = jump?.wto ? parseInt(jump.wto) : nowStep;
this.gameStatus.step = null;
this.gameStatus.state = 2;
this.gameStatus.jump = !!jump?.wto;
if (this.answerIndex == this.gameStatus.total - 1) {
await asyncDelay(1);
this.networkHelper.sendFrame({
type: "SERVER_playerWrong",
type: "SERVER_gameSettleEnd",
status: this.gameStatus,
ans: this.answerData
});
this.changeSide();
} else if (data.type == "stateUpdate") {
if (this._useAI || sender.color == this.gameStatus.current) {
} else {
if (this.gameStatus.state == 2) {
this.gameStatus.state = 0;
}
await asyncDelay(1);
this.prepareNum = 0
this.answerIndex++;
this.gameStatus.state = 1;
this.gameStatus.index = this.answerIndex;
this.answerCount = 0;
this.answerData = [];
let question = this.questionData[this.answerIndex];
this.networkHelper.sendFrame({
type: "SERVER_updateStatus",
type: "SERVER_gameEv",
status: this.gameStatus,
question: question
});
this.gameStatus.jump = null;
// 开始计时11秒
this.countToSettle(11);
}
}
}
......@@ -247,21 +281,60 @@ export class GameServer {
}
changeSide() {
countToSettle(time) {
console.log("=====changeSide=======");
console.log("=====old =======" + this.gameStatus.current);
clearTimeout(this.settleTimer)
this.settleTimer = setTimeout(async () => {
if (this.answerIndex == this.gameStatus.total - 1) {
this.networkHelper.sendFrame({
type: "SERVER_gameSettle",
status: this.gameStatus,
ans: this.answerData
});
await asyncDelay(1);
this.networkHelper.sendFrame({
type: "SERVER_gameSettleEnd",
status: this.gameStatus,
ans: this.answerData
});
if (this.gameStatus.current == "Red") {
this.gameStatus.current = "Blue";
} else {
this.gameStatus.current = "Red";
this.networkHelper.sendFrame({
type: "SERVER_gameSettle",
status: this.gameStatus,
ans: this.answerData
});
await asyncDelay(1);
this.prepareNum = 0
this.answerIndex++;
this.gameStatus.state = 1;
this.gameStatus.index = this.answerIndex;
this.answerCount = 0;
this.answerData = [];
let question = this.questionData[this.answerIndex];
this.networkHelper.sendFrame({
type: "SERVER_gameEv",
status: this.gameStatus,
question: question
});
// 开始计时11秒
this.countToSettle(11);
}
console.log("=====now =======" + this.gameStatus.current);
}, time * 1000)
}
startAI() {
this.playerList
.filter((player) => player.isAI == true)
......@@ -279,4 +352,10 @@ export class GameServer {
clearInterval(id);
});
}
initQuestion(data) {
this.questionData = data;
}
}
export const defaultData = {
myInfo: {
lv: 0,
score: 1666,
rank: -1,
url: "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
name: "test"
},
question: [
{
info: "1+1=?",
type: 1,
ans: [1, 2, 3, 4],
rightIndex: 1
},
{
info: "1+1=?",
type: 2,
ans: ["http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
"http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
"http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
"http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",],
rightIndex: 1
},
{
info: "1+1=?",
type: 1,
ans: [1, 2, 3, 4],
rightIndex: 1
},
{
info: "1+1=?",
type: 2,
ans: ["http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
"http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
"http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
"http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",],
rightIndex: 1
},
{
info: "1+1=?",
type: 2,
ans: ["http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png",
"http://staging-teach.cdn.ireadabc.com/f596e586a31ac2813b1702557941c022.png",
"http://staging-teach.cdn.ireadabc.com/f0f396c52c42239913fd94523db979fa.png",
"http://staging-teach.cdn.ireadabc.com/9f2d2ef622fa33d4e2abcbdc4b40ab6a.png",],
rightIndex: 2
},
],
rank: [
{
name: "好奇宝宝4536",
score: 800,
},
{
name: "好奇宝宝773",
score: 1560,
},
{
name: "好奇宝宝656",
score: 550,
},
{
name: "好奇宝宝17",
score: 28830
},
{
name: "好奇宝宝44",
score: 39842
},
{
name: "好奇宝宝999",
score: 0
},
{
name: "",
score: 140
},
{
name: "",
score: 360
},
{
name: "博学笃志",
score: 1470
},
{
name: "小香菜",
score: 440
},
{
name: "Jess1e",
score: 1850
},
{
name: "鱼是野",
score: 5860
},
{
name: "莫尔er",
score: 9870
}, {
name: "泛舟",
score: 4550
}, {
name: "好奇宝宝580",
score: "5170",
}, {
name: "Tears.Smile",
score: 610
}, {
name: "懒猫小迪",
score: 570
}, {
name: "五颜六色的",
score: 1020
},
{
name: "可可",
score: 50
},
{
name: "浅蓝",
score: 1040
},
{
name: "小汤圆",
score: 900
},
{
name: "momo",
score: 8390
},
],
};
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "a099a409-00f0-447c-bc2b-e53489224d28",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getLv, getMinLv } from "../util_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Cup extends cc.Component {
@property(cc.SpriteFrame)
iconList = [];
@property(cc.SpriteFrame)
lvIconList = [];
@property(cc.Sprite)
icon: cc.Sprite = null;
@property(cc.Sprite)
lvIcon: cc.Sprite = null;
@property(cc.Label)
lb_minlv: cc.Label = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
init(score) {
let lv = getLv(score);
let minlv = getMinLv(score);
lv = Math.min(lv, 3);
minlv = Math.min(minlv, 4);
this.icon.spriteFrame = this.iconList[lv];
this.lvIcon.spriteFrame = this.lvIconList[lv];
this.lb_minlv.string = ["I", "II", "III", "IV", "V"][minlv];
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "f627f21c-b954-43c2-88f3-d443d80729ef",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Player from "./player_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class EndLayer extends cc.Component {
@property(cc.Node)
winRoot: cc.Node = null;
@property(cc.Node)
loseRoot: cc.Node = null;
@property(cc.Button)
btn_restart: cc.Button = null;
@property(cc.Node)
blueHead: cc.Node = null;
@property(cc.Label)
blueScore: cc.Label = null;
@property(cc.Label)
blueName: cc.Label = null;
@property(cc.Node)
redHead: cc.Node = null;
@property(cc.Label)
redScore: cc.Label = null;
@property(cc.Label)
redName: cc.Label = null;
mainCom: any;
onLoad() {
this.btn_restart.node.on("click", this.onClickRestart, this)
}
bind
onClickRestart() {
this.mainCom.backHome();
}
init(data, mydata, otherData) {
let root = this.loseRoot;
if (data.blueRight >= data.redRight) {
this.winRoot.active = true;
}
root.opacity = 0;
cc.tween(root).delay(0.5).to(1, { opacity: 255 }).start();
this.blueHead.getComponent(Player).init(mydata.url);
this.blueName.string = mydata.name;
this.blueScore.string = mydata.score;
this.redHead.getComponent(Player).init(otherData.headUrl);
this.redName.string = otherData.name;
this.redScore.string = otherData.score;
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "22f22490-dea9-4e88-b71d-1c675dfdb180",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { asyncDelay } from "../util_PK_Game";
import PicCell from "./picSelectCell_PK_Game";
import Player from "./player_PK_Game";
import TxtCell from "./txiSelectCell_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class GameLayer extends cc.Component {
@property(cc.Node)
questionBar: cc.Node = null;
@property(cc.Label)
questionTime: cc.Label = null;
@property(cc.Node)
blueBar: cc.Node = null;
@property(cc.Node)
redBar: cc.Node = null;
@property(cc.Node)
vsNode: cc.Node = null;
@property(cc.Node)
blueHead: cc.Node = null;
@property(cc.Node)
redHead: cc.Node = null;
@property(cc.Label)
blueScore: cc.Label = null;
@property(cc.Label)
blueName: cc.Label = null;
@property(cc.Label)
redScore: cc.Label = null;
@property(cc.Label)
redName: cc.Label = null;
@property(cc.Label)
lb_info: cc.Label = null;
@property(cc.Label)
lb_tips: cc.Label = null;
@property(cc.ProgressBar)
timeprobar: cc.ProgressBar = null;
@property(cc.ProgressBar)
blueprobar: cc.ProgressBar = null;
@property(cc.ProgressBar)
redprobar: cc.ProgressBar = null;
@property(cc.Node)
txtRoot: cc.Node = null;
@property(cc.Node)
rootCover: cc.Node = null;
@property(cc.Node)
cupStart: cc.Node = null;
@property(cc.Node)
cupEnd: cc.Node = null;
@property(cc.Node)
picRoot: cc.Node = null;
blueX: number;
redX: number;
rightIndex: any;
mainCom: any;
list: cc.Node[];
totaltime: number = -1;
countTime: number;
cupY: number;
cupX: number;
onLoad() {
this.blueX = this.blueBar.x;
this.redX = this.redBar.x;
this.cupX = this.cupStart.x;
this.cupY = this.cupStart.y;
this.lb_tips.node.active = false;
}
async init(mydata, otherData, callback) {
this.questionBar.active = false;
this.txtRoot.active = false;
this.cupEnd.active = false;
this.picRoot.active = false;
this.cupStart.active = true;
this.cupStart.opacity = 255;
this.blueBar.x = this.blueX - cc.winSize.width;
this.redBar.x = this.redX + cc.winSize.width;
this.cupStart.y = this.cupY + 500;
this.cupStart.x = this.cupX;
this.cupStart.scale = 1;
this.blueHead.getComponent(Player).init(mydata.url);
this.blueName.string = mydata.name;
this.blueScore.string = mydata.score;
this.redHead.getComponent(Player).init(otherData.headUrl);
this.redName.string = otherData.name;
this.redScore.string = otherData.score;
cc.tween(this.cupStart).to(0.15, { y: this.cupY }, { easing: "sineIn" }).start()
cc.tween(this.blueBar).to(0.35, { x: this.blueX }, { easing: "sineIn" }).start()
cc.tween(this.redBar).to(0.35, { x: this.redX }, { easing: "sineIn" }).start()
await asyncDelay(0.5)
callback && callback();
}
async initQuestion(question, index) {
this.rootCover.active = false;
this.questionBar.active = false;
this.rightIndex = question.rightIndex;
let ans = question.ans;
this.lb_tips.string = `第${index + 1}题`
this.lb_tips.node.active = true;
await asyncDelay(1);
this.totaltime = 10.2;
this.countTime = 0;
this.questionBar.active = true;
this.lb_tips.node.active = false;
this.lb_info.string = question.info;
if (question.type == 1) {
this.txtRoot.active = true;
this.picRoot.active = false;
this.list = this.txtRoot.children;
for (let i = 0; i < this.list.length; ++i) {
this.list[i].getComponent(TxtCell).init(i, ans[i], i == question.rightIndex, (index) => {
this.mainCom.playLocalAudio("btn");
this.mainCom.networkHelper.sendFrame({
type: "anserQues",
uuid: this.mainCom.playerId,
index: index
});
this.rootCover.active = true;
})
}
} else {
this.txtRoot.active = false;
this.picRoot.active = true;
this.list = this.picRoot.children;
for (let i = 0; i < this.list.length; ++i) {
this.list[i].getComponent(PicCell).init(i, ans[i], i == question.rightIndex, (index) => {
this.mainCom.playLocalAudio("btn");
this.mainCom.networkHelper.sendFrame({
type: "anserQues",
uuid: this.mainCom.playerId,
index: index
});
this.rootCover.active = true;
})
}
}
}
async settle(data) {
let ans = data.ans;
for (let i = 0; i < ans.length; ++i) {
let info = ans[i];
if (info.uuid != this.mainCom.playerId) {
this.list[info.index].getComponent(TxtCell)?.onClickItem(null, 2);
this.list[info.index].getComponent(PicCell)?.onClickItem(null, 2);
}
}
this.redprobar.progress = data.status.redRight / data.status.total;
this.blueprobar.progress = data.status.blueRight / data.status.total;
await asyncDelay(1);
this.lb_info.string = "";
this.txtRoot.active = false;
this.picRoot.active = false;
this.questionBar.active = false;
cc.log(data);
}
hide() {
this.redprobar.progress = 0;
this.blueprobar.progress = 0;
cc.tween(this.blueBar).to(0.35, { x: this.blueX - cc.winSize.width }, { easing: "sineIn" }).start()
cc.tween(this.redBar).to(0.35, { x: this.redX + cc.winSize.width }, { easing: "sineIn" }).start()
cc.tween(this.cupStart).to(0.5, { x: this.cupEnd.x, y: this.cupEnd.y, scale: this.cupEnd.scale }).call(() => {
this.node.active = false;
}).start();
}
update(dt) {
if (this.totaltime > 0) {
this.countTime += dt;
let left = this.totaltime - this.countTime;
if (left >= 0) {
this.timeprobar.progress = (this.totaltime - this.countTime) / this.totaltime;
this.questionTime.string = "" + Math.floor(this.totaltime - this.countTime)
} else {
this.totaltime = -1;
this.countTime = 0
this.rootCover.active = true;
}
}
}
}
{
"ver": "1.0.8",
"uuid": "a6b22835-57c0-488e-bb43-46113b11cf34",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Cup from "./cup_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class HomeLayer extends cc.Component {
@property(cc.Button)
btn_start = null;
@property(cc.Label)
lb_gold = null;
@property(cc.Label)
lb_lv = null;
@property(cc.Label)
lb_award = null;
@property(cc.Label)
lb_cost = null;
_startCallBack: Function;
onLoad() {
this.btn_start.node.on("click", this.onClickStart, this)
}
onClickStart() {
this._startCallBack && this._startCallBack();
}
initCup(score) {
this.node.getChildByName("cup").getComponent(Cup).init(score);
}
set startCallBack(callback: Function) {
this._startCallBack = callback;
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "a988384c-e0b9-49e7-ad09-9a1923676a8a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { asyncDelay, getLv, getMinLv } from "../util_PK_Game";
import Player from "./player_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class MatchLayer extends cc.Component {
@property(cc.Node)
blueBar: cc.Node = null;
@property(cc.Node)
redBar: cc.Node = null;
@property(cc.Node)
vsNode: cc.Node = null;
@property(cc.Node)
blueHead: cc.Node = null;
@property(cc.Node)
redHead: cc.Node = null;
@property(cc.Label)
blueLv: cc.Label = null;
@property(cc.Label)
blueName: cc.Label = null;
@property(cc.Label)
redLv: cc.Label = null;
@property(cc.Label)
redName: cc.Label = null;
@property(cc.Node)
searchNode: cc.Node = null;
@property(cc.Node)
matchNode: cc.Node = null;
@property(cc.Label)
matchlb: cc.Label = null;
blueX: number;
redX: number;
matchCount: number;
onLoad() {
this.blueBar.active = false;
this.redBar.active = false;
this.vsNode.active = false;
this.blueX = this.blueBar.x;
this.redX = this.redBar.x;
this.matchCount = 0;
this.schedule(() => {
this.matchlb.string = `寻找中${[".", "..", "..."][this.matchCount % 3]}`;
this.matchCount++
}, 0.4)
}
async startMatch(data) {
this.blueBar.active = false;
this.redBar.active = false;
this.vsNode.active = false;
this.blueHead.getComponent(Player).init(data.url);
let lv = getLv(data.score);
let minlv = getMinLv(data.score);
lv = Math.min(lv, 3);
minlv = Math.min(minlv, 4);
let lvstr = ["黑铁", "青铜", "白银", "黄金"][lv]
let minlvstr = ["I", "II", "III", "IV", "V"][minlv];
this.blueLv.string = lvstr + "" + minlvstr;
this.blueName.string = data.name;
this.blueBar.x = this.blueX - cc.winSize.width;
this.redBar.x = this.blueX + cc.winSize.width;
await asyncDelay(0.1);
this.blueBar.active = true;
cc.log(",,,,,,,,,,,,,," + cc.easeBackInOut.name)
cc.tween(this.blueBar).to(0.35, { x: this.blueX }, { easing: "sineIn" }).start()
await asyncDelay(1.5);
this.matchCount = 0;
this.searchNode.active = true;
this.matchNode.active = false;
this.redLv.node.active = false;
this.redName.node.active = false;
this.redBar.active = true;
cc.tween(this.redBar).to(0.3, { x: this.redX }, { easing: "sineIn" }).start()
}
async addOther(data, callback) {
this.redBar.active = true;
this.searchNode.active = false;
this.matchNode.active = true;
this.redLv.node.active = true;
this.redName.node.active = true;
this.redHead.getComponent(Player).init(data.headUrl);
// this.redLv.string = data.lv;
let lv = getLv(data.score);
let minlv = getMinLv(data.score);
lv = Math.min(lv, 3);
minlv = Math.min(minlv, 4);
let lvstr = ["黑铁", "青铜", "白银", "黄金"][lv]
let minlvstr = ["I", "II", "III", "IV", "V"][minlv];
this.redLv.string = lvstr + "" + minlvstr;
this.redName.string = data.name;
this.vsNode.active = true;
this.vsNode.scale = 1.5;
this.vsNode.opacity = 0;
cc.tween(this.vsNode).to(0.3, { opacity: 255, scale: 1 }).start();
await asyncDelay(0.6);
cc.tween(this.vsNode).to(0.1, { opacity: 0 }).start();
cc.tween(this.blueBar).by(0.3, { x: -cc.winSize.width }, { easing: "sineIn" }).start()
cc.tween(this.redBar).by(0.3, { x: cc.winSize.width }, { easing: "sineIn" }).start()
await asyncDelay(0.4);
callback && callback()
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "1a838b43-9811-4389-8bbd-6c63be7e7c9d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Cup from "./cup_PK_Game";
import Player from "./player_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class MyInfo extends cc.Component {
@property(cc.Node)
root: cc.Node = null;
@property(cc.Mask)
barMask: cc.Mask = null;
@property(cc.Node)
head: cc.Node = null;
@property(cc.Node)
btn_rank: cc.Node = null;
@property(cc.Node)
btn_rise: cc.Node = null;
@property(cc.Label)
lb_rank: cc.Label = null;
@property(cc.Label)
lb_score: cc.Label = null;
@property(cc.Label)
lb_name: cc.Label = null;
mainCom: any;
onLoad() {
this.btn_rise.on("click", this.onClickRisk, this)
this.btn_rank.on("click", this.onClickRank, this)
}
openMask() {
this.barMask.enabled = true;
}
hideMask() {
this.barMask.enabled = false;
}
onClickRank() {
this.mainCom.showRank();
}
onClickRisk() {
this.mainCom.showRisk();
}
hide() {
cc.tween(this.root).to(0.2, { y: -180 }, { easing: "sineOut" }).start();
}
show() {
cc.tween(this.root).to(0.2, { y: 180 }, { easing: "sineIn" }).start();
}
init(data) {
this.lb_score.string = data.score;
this.lb_name.string = data.name;
this.lb_rank.string = data.rank;
this.head.getComponent(Player).init(data.url);
this.root.getChildByName("cup").getComponent(Cup).init(data.score);
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "090fb3b3-f578-40d3-ae21-2074e4b7233c",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getSpriteFrimeByUrl } from "../util_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class PicCell extends cc.Component {
@property(cc.Node)
rightNode: cc.Node = null;
@property(cc.Node)
wrongNode: cc.Node = null;
@property(cc.Sprite)
icon: cc.Sprite = null;
@property(cc.Node)
leftRoot: cc.Node = null;
@property(cc.Node)
rightRoot: cc.Node = null;
@property(cc.SpriteFrame)
rightSp: cc.SpriteFrame = null;
@property(cc.SpriteFrame)
wrongSp: cc.SpriteFrame = null;
isRight: any;
index: any;
clickCall: Function;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
onLoad() {
this.node.on("click", this.onClickItem, this)
}
onClickItem(handle, side) {
let parent = side == 2 ? this.rightRoot : this.leftRoot;
if (this.isRight) {
this.rightNode.active = true;
let node = new cc.Node();
node.addComponent(cc.Sprite);
node.getComponent(cc.Sprite).spriteFrame = this.rightSp;
node.parent = parent;
} else {
this.wrongNode.active = true;
let node = new cc.Node();
node.addComponent(cc.Sprite);
node.getComponent(cc.Sprite).spriteFrame = this.wrongSp;
node.parent = parent;
}
if (handle) {
this.clickCall && this.clickCall(this.index);
}
}
init(index, url, isRight, callback: Function) {
this.rightNode.active = false;
this.wrongNode.active = false;
this.leftRoot.removeAllChildren();
this.rightRoot.removeAllChildren();
this.isRight = isRight;
this.clickCall = callback;
this.index = index;
getSpriteFrimeByUrl(url, (sf: cc.SpriteFrame) => {
this.icon.spriteFrame = sf;
this.icon.node.scale = Math.max(360 / this.node.width, 360 / this.node.height)
})
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "ba3c3aad-3f0d-4493-9e5c-b9817fe37d84",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getSpriteFrimeByUrl } from "../util_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Player extends cc.Component {
@property(cc.Sprite)
icon: cc.Sprite = null;
init(url?) {
let defaultUrl = "http://staging-teach.cdn.ireadabc.com/0751c28419a0e8ffb1f0e84435b081ce.png"
getSpriteFrimeByUrl(url || defaultUrl, (sf: cc.SpriteFrame) => {
this.icon.spriteFrame = sf;
this.icon.node.scale = Math.max(this.node.width / this.icon.node.width, this.node.height / this.icon.node.height)
})
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "e2fbaa3b-83c6-4b23-ada6-4d373384c8a3",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { getLv } from "../util_PK_Game";
import Player from "./player_PK_Game";
const { ccclass, property } = cc._decorator;
@ccclass
export default class RankLayer extends cc.Component {
@property(cc.Button)
btn_close: cc.Button = null;
@property(cc.Node)
rank1Root: cc.Node = null;
@property(cc.Node)
rank2Root: cc.Node = null;
@property(cc.Node)
rank3Root: cc.Node = null;
@property(cc.Node)
itemTemp: cc.Node = null;
@property(cc.ScrollView)
sviewt: cc.ScrollView = null;
@property(cc.SpriteFrame)
iconList = [];
private _data: any;
private _staticeData: any;
mainCom: any;
onLoad() {
this.itemTemp.active = false;
this.btn_close.node.on("click", this.onClickClose, this)
}
onClickClose() {
cc.tween(this.node).to(0.3, { y: - cc.winSize.height }, { easing: "sineOut" }).start();
this.mainCom.hideRank();
}
init(data) {
this._staticeData = data;
}
setMyInfo(data) {
let tempData = [...this._staticeData, { score: data.score, name: data.name, isMe: true }]
this._data = tempData.sort((a, b) => {
return b.score - a.score;
})
let rank = 0;
for (let i = 0; i < this._data.length; ++i) {
if (this._data[i].isMe) {
rank = i;
break;
}
}
return rank;
}
show() {
this.node.y = - cc.winSize.height;
cc.tween(this.node).to(0.3, { y: 0 }, { easing: "sineIn" }).start();
this.rank1Root.getChildByName("lb_score").getComponent(cc.Label).string = this._data[0].score;
this.rank1Root.getChildByName("lb_name").getComponent(cc.Label).string = this._data[0].name;
this.rank1Root.getChildByName("head").getComponent(Player).init();
this.rank2Root.getChildByName("lb_score").getComponent(cc.Label).string = this._data[1].score;
this.rank2Root.getChildByName("lb_name").getComponent(cc.Label).string = this._data[1].name;
this.rank2Root.getChildByName("head").getComponent(Player).init();
this.rank3Root.getChildByName("lb_score").getComponent(cc.Label).string = this._data[2].score;
this.rank3Root.getChildByName("lb_name").getComponent(cc.Label).string = this._data[2].name;
this.rank3Root.getChildByName("head").getComponent(Player).init();
this.sviewt.content.removeAllChildren();
for (let i = 3; i < this._data.length; ++i) {
let cell = cc.instantiate(this.itemTemp);
cell.active = true;
cell.parent = this.sviewt.content;
cell.getChildByName("head").getComponent(Player).init();
cell.getChildByName("lb_score").getComponent(cc.Label).string = this._data[i].score;
cell.getChildByName("lb_name").getComponent(cc.Label).string = this._data[i].name;
cell.getChildByName("lb_rank").getComponent(cc.Label).string = `${i + 1}`;
cell.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.iconList[getLv(this._data[i].score)];
}
}
}
{
"ver": "1.0.8",
"uuid": "ce59a32a-c4bc-4e12-919f-ee0dc18f0680",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class SeletctItem extends cc.Component {
@property(cc.Node)
right: cc.Node = null;
@property(cc.Node)
wrong: cc.Node = null;
@property(cc.Label)
txt: cc.Label = null;
@property(cc.Sprite)
icon: cc.Sprite = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "a43aa617-a5f3-4fd4-834c-f8b32596d289",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class TxtCell extends cc.Component {
@property(cc.Node)
bg: cc.Node = null;
@property(cc.Color)
rightColor: cc.Color = null;
@property(cc.Color)
wrongColr: cc.Color = null;
@property(cc.Label)
lb_info: cc.Label = null;
@property(cc.Node)
leftRoot: cc.Node = null;
@property(cc.Node)
rightRoot: cc.Node = null;
@property(cc.SpriteFrame)
rightSp: cc.SpriteFrame = null;
@property(cc.SpriteFrame)
wrongSp: cc.SpriteFrame = null;
isRight: any;
clickCall: Function;
index: any;
onLoad() {
this.node.on("click", this.onClickItem, this)
}
onClickItem(handle, side) {
let parent = side == 2 ? this.rightRoot : this.leftRoot;
if (this.isRight) {
this.bg.color = this.rightColor.clone();
let node = new cc.Node();
node.addComponent(cc.Sprite);
node.getComponent(cc.Sprite).spriteFrame = this.rightSp;
node.parent = parent;
} else {
this.bg.color = this.wrongColr.clone();
let node = new cc.Node();
node.addComponent(cc.Sprite);
node.getComponent(cc.Sprite).spriteFrame = this.wrongSp;
node.parent = parent;
}
if (handle) {
this.clickCall && this.clickCall(this.index);
}
}
init(index, info, isRight, clickCall: Function) {
this.leftRoot.removeAllChildren();
this.rightRoot.removeAllChildren();
this.bg.color = cc.Color.WHITE.clone();
this.lb_info.string = info;
this.isRight = isRight;
this.clickCall = clickCall;
this.index = index;
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "bfb8282f-e21c-4603-8261-3115914f6fb8",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
export enum gameState {
}
export function getPosByAngle(angle, len) {
const radian = angle * Math.PI / 180;
......@@ -375,3 +385,31 @@ export async function asyncPlayDragonBoneAnimation(node, animationName, time = 1
.playAnimation(animationName, time);
});
}
export function getLv(num) {
if (num < 1000) {
return 0;
} else if (num < 5000) {
return 1;
} else if (num < 20000) {
return 2;
} else {
return 3;
}
}
export function getMinLv(num) {
if (num < 1000) {
return Math.floor(num / 200);
} else if (num < 5000) {
return Math.floor((num - 1000) / 800);;
} else if (num < 20000) {
return Math.floor((num - 5000) / 3000);;
} else {
return Math.floor((num - 20000) / 6000);;
}
}
{
"ver": "2.3.5",
"uuid": "7b847b9a-71a2-4501-9c60-2388a53df47a",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 583,
"height": 475,
"platformSettings": {},
"subMetas": {
"img_jin": {
"ver": "1.0.4",
"uuid": "671d22ef-f6f6-4159-9319-8415e1c4ef72",
"rawTextureUuid": "7b847b9a-71a2-4501-9c60-2388a53df47a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 0,
"trimY": 1,
"width": 583,
"height": 474,
"rawWidth": 583,
"rawHeight": 475,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"title": "PK_Game",
"packageName": "org.cocos2d.demo",
"startScene": "0737ce42-24f0-45c6-8e1a-8bdab4f74ba3",
"excludeScenes": [],
"orientation": {
"landscapeRight": true,
"landscapeLeft": true,
"portrait": false,
"upsideDown": false
},
"webOrientation": "auto",
"inlineSpriteFrames": true,
"inlineSpriteFrames_native": true,
"mainCompressionType": "default",
"mainIsRemote": false,
"optimizeHotUpdate": false,
"md5Cache": true,
"nativeMd5Cache": true,
"encryptJs": true,
"xxteaKey": "5d6df4d4-9a15-4f",
"zipCompressJs": true,
"fb-instant-games": {},
"android": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": ""
},
"ios": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": "",
"ios_enable_jit": true
},
"mac": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": "",
"width": 1280,
"height": 720
},
"win32": {
"REMOTE_SERVER_ROOT": "",
"width": 1280,
"height": 720
},
"android-instant": {
"packageName": "org.cocos2d.demo",
"REMOTE_SERVER_ROOT": "",
"pathPattern": "",
"scheme": "https",
"host": "",
"skipRecord": false,
"recordPath": ""
},
"appBundle": false,
"agreements": {}
}
......@@ -11,10 +11,10 @@
"3D Physics/Builtin"
],
"preview-port": 7456,
"design-resolution-width": 640,
"design-resolution-height": 960,
"design-resolution-width": 1080,
"design-resolution-height": 1960,
"fit-width": true,
"fit-height": false,
"fit-height": true,
"use-project-simulator-setting": false,
"simulator-orientation": false,
"use-customize-simulator": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment