diff --git a/Classes/GameDefinitions.h b/Classes/GameDefinitions.h index 422d95e..d76783e 100644 --- a/Classes/GameDefinitions.h +++ b/Classes/GameDefinitions.h @@ -6,8 +6,9 @@ const float movingTime = 0.3f;//移动用时 const int maxMovementTimes = 5;//最大移动数量 const int timeLimit = 20;//超时时间 +const float aiThinkingTime = 0.8f; const float boardScaleTime = 0.2f;//缩放动画时间 -const float boardFilpTime = 0.8f;//翻转动画时间 +const float boardFilpTime = 0.4f;//翻转动画时间 const float nextChessmanChangeTime = 0.5f;//切换下一个棋子提示的时间 enum Side { left, right }; diff --git a/Classes/GameScene.cpp b/Classes/GameScene.cpp index 3daf25f..1ef87ef 100644 --- a/Classes/GameScene.cpp +++ b/Classes/GameScene.cpp @@ -77,8 +77,9 @@ void GameScene::setNextChessman(Chessman chessman) auto old = this->getChildByName("next"); auto moveAction = MoveBy::create(nextChessmanChangeTime, Vec2(0, -20)); if (old) { + old->setName(""); auto fadeOutAction = FadeOut::create(nextChessmanChangeTime); - auto callAction = CallFunc::create([this]() {this->removeChildByName("next"); }); + auto callAction = CallFunc::create([this, old]() {this->removeChild(old); }); auto sequenceAction = Sequence::create(fadeOutAction, callAction, NULL); old->runAction(moveAction); old->runAction(sequenceAction); @@ -225,7 +226,7 @@ Sprite* GameScene::createSpriteByChessman(Chessman type) bool GameScene::ejectorTouchBeganCallback(Touch * touch, Event * event) { - if (controllable) { + if (controllable && state != ActionState::moving) { //遍历当前边的发射器 for (int i = 0; i < (turn == left ? lCol : rCol); i++) { //判断鼠标是否处于发射器内(45°倾斜的正方形) @@ -255,37 +256,39 @@ void GameScene::ejectorTouchEndedCallback(Touch * touch, Event * event) bool GameScene::setBoardSize(int lCol, int rCol) { - if (lCol > maxLCol || lColmaxRCol || rCol < minRCol) - return false; - //如果棋盘变大,把多出来的那部分清空 - if (this->lCol < lCol) { - for (int i = this->lCol; i < lCol; i++) { - for (int j = 0; j < rCol; j++) { - chessmen[i][j] = Chessman::common; + if (lCol <= maxLCol && lCol >= minLCol && rCol <= maxRCol && rCol >= minRCol) + { + //如果棋盘变大,把多出来的那部分清空 + if (this->lCol < lCol) { + for (int i = this->lCol; i < lCol; i++) { + for (int j = 0; j < rCol; j++) { + chessmen[i][j] = Chessman::common; + } } } - } - if (this->rCol < rCol) { - for (int i = 0; i < lCol; i++) { - for (int j = this->rCol; j < rCol; j++) { - chessmen[i][j] = Chessman::common; + if (this->rCol < rCol) { + for (int i = 0; i < lCol; i++) { + for (int j = this->rCol; j < rCol; j++) { + chessmen[i][j] = Chessman::common; + } } } + board->setScale((float)(lCol + rCol) / (this->lCol + this->rCol)); + auto scaleAction = ScaleTo::create(boardScaleTime, 1); + board->runAction(scaleAction); + this->lCol = lCol; + this->rCol = rCol; } - board->setScale((float)(lCol + rCol) / (this->lCol + this->rCol)); - auto scaleAction = ScaleTo::create(boardScaleTime, 1); - board->runAction(scaleAction); - this->lCol = lCol; - this->rCol = rCol; + buildChessboard(); return true; } void GameScene::flip() { - for (int i = 0; i < lCol; i++) + for (int i = 0; i < maxLCol; i++) { - for (int j = i + 1; j < rCol; j++) + for (int j = i + 1; j < maxRCol; j++) { std::swap(chessmen[i][j], chessmen[j][i]); } @@ -330,7 +333,7 @@ void GameScene::beginMoving(int col) for (int i = 0; i < (turn == left ? rCol : lCol); i++) { chessmanNode->getChildByTag(turn == left ? movingCol*rCol + i : i*rCol + movingCol)->runAction(movingAction->clone()); } - newChessman->runAction(movingAction->clone()); + newChessman->runAction(movingAction); scheduleOnce(CC_CALLBACK_0(GameScene::endMoving, this), movingTime, "move"); totalMovements++; } @@ -338,7 +341,6 @@ void GameScene::beginMoving(int col) void GameScene::endMoving() { - Chessman lastChessman;//暂存最底下的棋子 if (turn == left) { lastChessman = chessmen[movingCol][rCol - 1]; for (int i = rCol - 1; i > 0; i--) { @@ -389,20 +391,23 @@ void GameScene::endMoving() } if (controllable) { - if (touching && totalMovements < maxMovementTimes) { - scheduleOnce(CC_CALLBACK_0(GameScene::beginMoving, this, movingCol), movingCooling, "cool"); - state = ActionState::cooling; + if (lastChessman == Chessman::flip) { + changeTurn(); } else { - changeTurn(); - if (lastChessman != Chessman::flip) { - setTurnFlag(); + if (touching && totalMovements < maxMovementTimes) { + scheduleOnce(CC_CALLBACK_0(GameScene::beginMoving, this, movingCol), movingCooling, "cool"); + state = ActionState::cooling; + } + else { + changeTurnAndSetTurnFlag(); } } } else { state = ActionState::nothing; } + } void GameScene::setTurn(Side turn) diff --git a/Classes/GameScene.h b/Classes/GameScene.h index f00f2b8..50df173 100644 --- a/Classes/GameScene.h +++ b/Classes/GameScene.h @@ -29,6 +29,7 @@ class GameScene :public cocos2d::Scene ActionState state; int movingCol;//移动中的列 bool controllable = false; + Chessman lastChessman;//暂存最底下的棋子 void setNames(std::string left, std::string right); Chessman getNextChessman() { return nextChessman; }; diff --git a/Classes/MainScene.cpp b/Classes/MainScene.cpp index e8590f1..29c19c5 100644 --- a/Classes/MainScene.cpp +++ b/Classes/MainScene.cpp @@ -114,7 +114,7 @@ bool MainScene::init() updatePlayerLabel(); } - auto versionLabel = MyCreator::createLabel("Alpha 0.3", 25, Color4B(0, 0, 0, 255)); + auto versionLabel = MyCreator::createLabel("Alpha 0.3.1", 25, Color4B(0, 0, 0, 255)); versionLabel->setPosition(visibleSize.width - versionLabel->getContentSize().width / 2, versionLabel->getContentSize().height / 2); this->addChild(versionLabel); return true; diff --git a/Classes/PvaGameScene.cpp b/Classes/PvaGameScene.cpp index a73bb7a..ce63dba 100644 --- a/Classes/PvaGameScene.cpp +++ b/Classes/PvaGameScene.cpp @@ -25,11 +25,17 @@ void PvaGameScene::endMoving() GameScene::endMoving(); if (originalTurn == right) { if (AIMovementTimes > 0) { + if (chessmen[lCol - 1][movingCol] == Chessman::flip) { + AIMovementTimes = 1; + } AIMovementTimes--; scheduleOnce([this](float) {beginMoving(movingCol); }, movingCooling, "cool"); } else { - changeTurnAndSetTurnFlag(); + changeTurn(); + if (lastChessman != Chessman::flip) { + setTurnFlag(); + } } } } @@ -40,7 +46,7 @@ void PvaGameScene::changeTurn() if (turn == right) { controllable = false; //切换回合后冷却一下再让AI下(否则看起来太突然) - scheduleOnce(CC_CALLBACK_0(PvaGameScene::AIMove, this), movingCooling, "changeCool"); + scheduleOnce(CC_CALLBACK_0(PvaGameScene::AIMove, this), aiThinkingTime, "changeCool"); } else { controllable = true; diff --git a/Classes/PvoGameScene.cpp b/Classes/PvoGameScene.cpp index cb0f104..d119807 100644 --- a/Classes/PvoGameScene.cpp +++ b/Classes/PvoGameScene.cpp @@ -145,6 +145,7 @@ void PvoGameScene::onStart(SIOClient * client, const std::string & data) Json j(data); if (j.getInt("side") == right) { setTurn(right); + setTurnFlag(); controllable = false; } else { diff --git a/README.md b/README.md index 0e27664..10fb0ae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Myomyw -**Myomyw Alpha 0.3 宸插彂甯!** +**Myomyw Alpha 0.3.1 宸插彂甯!** ## 娓告垙瑙勫垯 娓告垙鐣岄潰涓袱杈规槸鍙戝皠鍣紝涓棿鏄鐩橈紝杞埌浣犳椂浣犲彲浠ョ偣鍑讳綘鐨勪竴涓彂灏勫櫒锛岃繖鏍峰氨鍙互鎶婄悆鎺ㄥ嚭鍘伙紝鎸変綇鍙戝皠鍣ㄥ彲浠ヨ繛缁彂灏勭悆锛屼絾鏈澶氬彧鑳藉彂灏勪簲娆° @@ -28,3 +28,4 @@ * 2016/2/28 鍙戝竷Alpha 0.1.1 * 2016/3/27 鍙戝竷Alpha 0.2 * 2016/6/28 鍙戝竷Alpha 0.3 +* 2016/6/30 鍙戝竷Alpha 0.3.1 diff --git a/Server/Server/src/Room.js b/Server/Server/src/Room.js index 61463c3..ded758d 100644 --- a/Server/Server/src/Room.js +++ b/Server/Server/src/Room.js @@ -115,7 +115,6 @@ Room.prototype.createAndTellNextChessman = function () { this.nextChessman = this.getRandomChessman(); this.leftPlayer.emit('nextChessman', { chessman: this.nextChessman }); this.rightPlayer.emit('nextChessman', { chessman: this.nextChessman }); - console.log('told'); } Room.prototype.getRandomChessman = function () { @@ -200,12 +199,15 @@ Room.prototype.move = function (col, chessman) { break; } } + if (lastChessman == Chessman.flip) { + this.totalMovementTimes = config.maxMovementTimes; + } return false; } Room.prototype.flip = function () { - for (var i = 0; i < this.lCol; i++) { - for (var j = i + 1; j < this.rCol; j++) { + for (var i = 0; i < config.maxLCol; i++) { + for (var j = i + 1; j < config.maxRCol; j++) { this.chessmen[i][j] ^= this.chessmen[j][i]; this.chessmen[j][i] ^= this.chessmen[i][j]; this.chessmen[i][j] ^= this.chessmen[j][i];