Skip to content

Commit

Permalink
Merge branch '0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rand-fly committed Jun 30, 2016
2 parents cbc20c3 + 8cd7e64 commit fd6ed6e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Classes/GameDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
63 changes: 34 additions & 29 deletions Classes/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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°倾斜的正方形)
Expand Down Expand Up @@ -255,37 +256,39 @@ void GameScene::ejectorTouchEndedCallback(Touch * touch, Event * event)

bool GameScene::setBoardSize(int lCol, int rCol)
{
if (lCol > maxLCol || lCol<minLCol || rCol>maxRCol || 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]);
}
Expand Down Expand Up @@ -330,15 +333,14 @@ 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++;
}
}

void GameScene::endMoving()
{
Chessman lastChessman;//暂存最底下的棋子
if (turn == left) {
lastChessman = chessmen[movingCol][rCol - 1];
for (int i = rCol - 1; i > 0; i--) {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Classes/GameScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down
2 changes: 1 addition & 1 deletion Classes/MainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions Classes/PvaGameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Classes/PvoGameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Myomyw
**Myomyw Alpha 0.3 已发布!**
**Myomyw Alpha 0.3.1 已发布!**
## 游戏规则
游戏界面中两边是发射器,中间是棋盘,轮到你时你可以点击你的一个发射器,这样就可以把球推出去,按住发射器可以连续发射球,但最多只能发射五次。

Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions Server/Server/src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit fd6ed6e

Please sign in to comment.