Commit 0073dffd authored by 范雪寒's avatar 范雪寒

feat:

parent 857b0688
// 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 NewClass extends cc.Component {
@property
letter: string = '';
@property
idx: string = '';
@property
word: string = '';
}
{
"ver": "1.0.8",
"uuid": "95f09492-075f-4331-ae66-6c5934703419",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -43,17 +43,14 @@ export class NetworkHelper {
const gameInfo: MGOBE.types.GameInfoPara = {
gameId: gameId,
openId: openId,
secretKey: "060d81c7abaf24c8ce2afc5a725c152062676d35",
// createSignature: (callback) => {
// this.callNetworkApiGet('http://192.168.3.142:8081', '/getSign', {
// gameId: gameId,
// openId: openId,
// }, (data) => {
// const signature = JSON.parse(data);
// console.log(JSON.stringify(signature));
// callback(signature);
// });
// }
createSignature: (callback) => {
this.callNetworkApiGet('http://staging-teach.ireadabc.com', '/api/oxford/game/v1/config', {
gameid: gameId,
openid: openId,
}, (data) => {
callback(JSON.parse(data));
});
}
};
const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名
......
This diff is collapsed.
import { asyncDelay, onHomeworkFinish, RandomInt } from "../script/util";
import { asyncDelay, asyncTweenTo, onHomeworkFinish, RandomInt } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { NetworkHelper } from "./NetworkHelper";
......@@ -28,14 +28,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initListener();
}
gameData;
playerId;
networkHelper: NetworkHelper;
async initData() {
this.networkHelper = new NetworkHelper();
// this.networkHelper.initListener();
await this.networkHelper.initRoom();
this.playerId = await this.networkHelper.joinRoom('op_16', 2);
this.gameData = { Red: 0, Blue: 0, current: 'Blue' };
this.playerId = await this.networkHelper.init('op_16', 2);
const roomInfo = this.networkHelper.getRoomInfo();
if (roomInfo.playerList.length == roomInfo.maxPlayers) {
......@@ -89,6 +88,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
initView() {
this.initBg();
this.initPiece();
}
initBg() {
......@@ -100,11 +100,88 @@ export default class SceneComponent extends MyCocosSceneComponent {
bg.scale = Math.min(canvas.width / bg.width, canvas.height / bg.height);
}
// update (dt) {},
initPiece() {
const offsetX = { Red: -45, Blue: 45 };
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const pieceNodeRed = cc.find(`Canvas/bg/chessBoard/pieceRed`)
const startIdxRed = this.gameData['Red'];
const boardNodeRed = board.children[startIdxRed];
pieceNodeRed.x = boardNodeRed.x + offsetX.Red;
pieceNodeRed.y = boardNodeRed.y;
const pieceNodeBlue = cc.find(`Canvas/bg/chessBoard/pieceBlue`)
const startIdxBlue = this.gameData['Blue'];
const boardNodeBlue = board.children[startIdxBlue];
pieceNodeBlue.x = boardNodeBlue.x + offsetX.Blue;
pieceNodeBlue.y = boardNodeBlue.y;
}
// update (dt) {},
initListener() {
const btn = cc.find('Canvas/bg/New Button');
btn.on('click', async () => {
const idx = RandomInt(6);
await this.rollTheDice(idx);
this.movePiece(
['A', 'B', 'C', 'D', 'E', 'F'][idx],
this.gameData.current
);
});
}
async movePiece(letter, color) {
const offsetX = { Red: -45, Blue: 45 };
const pieceNode = cc.find(`Canvas/bg/chessBoard/piece${color}`)
const board = cc.find('Canvas/bg/chessBoard/boardItems');
const startIdx = this.gameData[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent('ItemData');
const prograssbar = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`);
const mask = cc.find(`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`);
const targetHeight = (i / board.children.length) * prograssbar.height;
cc.tween(mask)
.to(1, { height: targetHeight }, { easing: 'cubicInOut' })
.start();
await asyncTweenTo(pieceNode, 1, { x: targetNode.x + offsetX[color], y: targetNode.y }, { easing: 'cubicInOut' });
if (itemData.letter.toLowerCase() == letter.toLowerCase()) {
this.gameData[color] = i;
return;
}
}
this.finish();
}
finish() {
onHomeworkFinish();
}
rollTheDice(num) {
return new Promise((resolve, reject) => {
const dice = cc.find('Canvas/bg/chessBoard/diceBg/dice');
const targetAngle = Math.ceil(dice.angle / 360 + 1) * 360;
const time = (targetAngle - 360 - dice.angle) / 360;
cc.tween(dice)
.by(3, { angle: 360 }, { easing: "cubicIn" })
.to(time, { angle: targetAngle })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1, { angle: 360 })
.by(1 / 6 * num, { angle: 60 * num })
.by(3, { angle: 360 }, { easing: "cubicOut" })
.call(() => {
resolve(null);
})
.start();
});
}
playLocalAudio(audioName) {
......
{
"ver": "2.3.5",
"uuid": "b5d3e426-80a2-4f05-ab2d-c152235d3300",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 165,
"height": 141,
"platformSettings": {},
"subMetas": {
"house": {
"ver": "1.0.4",
"uuid": "dca8ea51-178a-4b32-a3d9-db19abe537ce",
"rawTextureUuid": "b5d3e426-80a2-4f05-ab2d-c152235d3300",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 0,
"trimY": 1,
"width": 165,
"height": 140,
"rawWidth": 165,
"rawHeight": 141,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
......@@ -7,8 +7,8 @@
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1432,
"height": 1698,
"width": 864,
"height": 1024,
"platformSettings": {},
"subMetas": {
"chessBoard": {
......@@ -22,10 +22,10 @@
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1432,
"height": 1698,
"rawWidth": 1432,
"rawHeight": 1698,
"width": 864,
"height": 1024,
"rawWidth": 864,
"rawHeight": 1024,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
......
......@@ -3,6 +3,7 @@ const os = require('os');
const readline = require('readline');
const Base64 = require('js-base64');
const CryptoJS = require("crypto-js");
const http = require("http");
const { build, buildAndroid, buildIos } = require('./buildCocos');
const networkInfo = os.networkInterfaces();
......@@ -46,6 +47,33 @@ app.get('/getSign', function (req, res) {
res.send(JSON.stringify({ nonce, timestamp, sign }));
});
// app.get('/jump', function (req, res) {
// res.header("Access-Control-Allow-Origin", "*");
// const gameId = req.query.gameId;
// const openId = req.query.openId;
// http.get({
// hostname: 'staging-teach.ireadabc.com',
// port: 80,
// path: `/api/oxford/game/v1/config?gameid=${gameId}&openid=${openId}`,
// agent: false // 仅为这个请求创建新代理
// }, (getres) => {
// getres.setEncoding('utf8');
// let rawData = '';
// getres.on('data', (chunk) => { rawData += chunk; });
// getres.on('end', () => {
// const secretKey = "060d81c7abaf24c8ce2afc5a725c152062676d35"; //替换为控制台上的 游戏 Key
// const data = JSON.parse(rawData);
// const str = `game_id=${gameId}&nonce=${data.nonce}&open_id=${openId}&timestamp=${data.timestamp}`;
// const sign = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(str, secretKey));
// console.log('sign = ' + sign);
// res.send(rawData)
// });
// });
// });
let port = '';
var server = app.listen(8081, function () {
......
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