Exemplo n.º 1
0
//汉字掉落状态捕捉函数,当新汉字掉落完,并清除出新汉字盒子时,掉落完毕
void ChrsGrid::onChrsDropping(float dt) 
{
	//如果新汉字都掉落完,停止该捕捉函数,并恢复触摸
	if (m_NewChrs.empty())
	{
		unschedule(schedule_selector(ChrsGrid::onChrsDropping));

		//判断是否是死图
		while (isDeadMap())
		{
			//这里稍后做一个更新的算法
			//1.根据布局大小创建出汉字阵列
			//2.布局坐标以左下角为原点,x右y上为正方向
			for (int x = 0; x < m_col; x++)
			{
				for (int y = 0; y < m_row; y++)
				{ 
					m_ChrsBox[x][y]->removeFromParent();
					m_ChrsBox[x][y] = createAChr(x, y); 
				}
			}
		}

		//游戏步数减去1,并加分
		auto gamescene = getGameScene();
		int cur_step = gamescene->subStep();
		int cur_score = gamescene->addScore(m_bonus);
		m_bonus = 0;

		int step_need = gamescene->getStepNeed();
		int score_need = gamescene->getScoreNeed();

		//判断游戏是否结束
		if (cur_step == 0)
		{
			if (cur_score < score_need)
			{
				gamescene->gameover(false);
			}
			else
			{
				gamescene->gameover(true);
			}
			this->unscheduleAllSelectors();
		}
		else
		{
			if (cur_score >= score_need)
			{
				gamescene->gameover(true);
				this->unscheduleAllSelectors();
			}
			else
			{
				//游戏没有结束,恢复触摸
				_eventDispatcher->resumeEventListenersForTarget(this);
			}
		}
	}
}
Exemplo n.º 2
0
void ChrsGrid::onTouchEnded(Touch*, Event*)
{
	//如果能消除,那么清除已选文字
	if (m_canCrush)
	{
		//首先暂停触摸
		_eventDispatcher->pauseEventListenersForTarget(this);

		//对已选汉字盒子内的元素进行消除
		goCrush();

		//捕捉消除动作是否完成,完成后继续下一个动作
		schedule(schedule_selector(ChrsGrid::onChrsCrushing), 0.02);
	}
	else
	{
		//如果不能,改变回背景颜色,其箭头也隐藏
		for (auto &chr : m_SelectedChrs)
		{
			chr->getBg()->setTexture(chr->getNormalBG().c_str());
			chr->hideArrow();
		}

		//清空临时已选汉字集合
		m_SelectedChrs.clear();
		//更改主界面的letter label的显示
		getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), false);
	}

	//开启倒计时捕捉,即开启提示功能
	resetCountdown();
	schedule(schedule_selector(ChrsGrid::onCountdownCallBack), 1);
}
Exemplo n.º 3
0
void EnemySpriteBase::onRemove() {
    SpriteBase::onRemove();
    removeHpBar();
    auto scene = dynamic_cast<GameScene1Player*>(getGameScene());
    if (scene) {
        scene->decreaseEnemyCnt();
    }
}
Exemplo n.º 4
0
void ChrsGrid::crushLastChr()
{
	//得到消除后,应该生成的特殊类型
	int special_type = getSpecial(m_SelectedChrs.size() - 1);

	auto last_chr = m_SelectedChrs.back();
	if (special_type != 0)
	{
		auto new_chr = createAChr(last_chr->getX(), last_chr->getY());
		new_chr->setSpecial(special_type);
		m_ChrsBox[last_chr->getX()][last_chr->getY()] = new_chr;

		//进入动作,完成后在添加新元素,开始掉落
		new_chr->setScale(0.01);
		auto scalebigger = ScaleTo::create(0.1, 1.2);
		auto scalesmaller = ScaleTo::create(0.2, 1);
		auto call = CallFunc::create([this]() {
			//清空临时已选汉字集合, 更改主界面的letter label的显示
			m_SelectedChrs.clear();	
			getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), false);

			//根据阵列空余添加新汉字元素至新汉字盒子,位于顶部,等待掉落
			addNewChrs();

			//使汉字掉落,同时开启掉落状态捕捉函数,掉落完后判断步数是否结束
			dropChrs();
			schedule(schedule_selector(ChrsGrid::onChrsDropping), 0.1);
		});
		auto action = Sequence::create(scalebigger, scalesmaller, call, nullptr);
		new_chr->runAction(action);
	}
	else
	{
		//清空临时已选汉字集合, 更改主界面的letter label的显示
		m_SelectedChrs.clear();	
		getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), false);

		//根据阵列空余添加新汉字元素至新汉字盒子,位于顶部,等待掉落
		addNewChrs();

		//使汉字掉落,同时开启掉落状态捕捉函数,掉落完后判断步数是否结束
		dropChrs();
		schedule(schedule_selector(ChrsGrid::onChrsDropping), 0.1);
	}
}
Exemplo n.º 5
0
bool ChrsGrid::onTouchBegan(Touch* pTouch, Event*)
{
	//如果已经选择了汉字元素,那么不接受新的触摸
	if (!m_SelectedChrs.empty())
	{
		return false;
	}

	//重置系统提示汉字元素盒子,停止倒计时捕捉,即停止提示功能
	resetAnswerChrs();
	unschedule(schedule_selector(ChrsGrid::onCountdownCallBack));

	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否有按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前选中的汉字元素,设置选中颜色
		auto chr = m_ChrsBox[x][y];
		chr->getBg()->setTexture("char_bg_selected.png");

		//执行按住后动作
		chr->chrAciton();

		//加入临时选定汉字集合,然后更改游戏主界面的letter label显示
		m_SelectedChrs.pushBack(chr);
		getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), false);

		//得到能否消除的状态
		m_canCrush = canCrush();

		//log("touch coordinate: x=%d,y=%d", x, y);

		return true;
	}
	else
	{
		return false;
	}
}
Exemplo n.º 6
0
void Controller::runGameScene()
{
	Director::getInstance()->pushScene(getGameScene());
}
Exemplo n.º 7
0
/**
*函数说明:移动触摸,将触摸到的新汉字元素放进已选汉字盒子
*如果是倒退,那么将最后一个汉字元素从已选汉字盒子中删除
*每一次增加/删除汉字元素,都会判断当前已选的汉字是否能消除
*/
void ChrsGrid::onTouchMoved(Touch* pTouch, Event*)
{
	//移动时也可选择
	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前触摸点的汉字元素,以及最后一次选择的汉字
		auto chr = m_ChrsBox[x][y];
		auto last_chr = m_SelectedChrs.back();

		//判断当前触摸点的汉字是否与最后一次选择的相邻
		int dx = abs(chr->getX() - last_chr->getX());
		int dy = abs(chr->getY() - last_chr->getY());
		int d = dx + dy;
		if (dx < 2 && dy < 2 && d <= 2 && d > 0)
		{
			//如果符合情况,那么将其加入临时选择汉字盒子,并设置选中颜色
			//只有当临时选择汉字集合中没有该汉字元素时,才添加
			if (!m_SelectedChrs.contains(chr))
			{
				//判断哪个箭头显示
				last_chr->showArrow(chr);

				m_SelectedChrs.pushBack(chr);
				chr->getBg()->setTexture("char_bg_selected.png");

				//执行按住后动作
				chr->chrAciton();

				//得到能否消除的状态
				m_canCrush = canCrush();
				if (m_canCrush)
				{
					for (auto &chr : m_SelectedChrs)
					{
						chr->chrAciton();
					}
				}
			}
		}

		//如果当前触摸点是已选汉字盒子中倒数第二个汉字,说明是后退操作
		//将倒数第一个元素删除出已选汉字盒子
		if (m_SelectedChrs.size() >= 2)
		{
			//得到倒数第二个元素,判断是否和触摸点的元素一致
			auto secondlast_chr = m_SelectedChrs.at(m_SelectedChrs.size()-2);
			if (secondlast_chr == chr)
			{
				//对最后一个元素执行释放后动作
				m_SelectedChrs.back()->chrAciton();

				//将最后一个元素删除出去
				m_SelectedChrs.back()->getBg()->setTexture(m_SelectedChrs.back()->getNormalBG());
				m_SelectedChrs.popBack();

				//然后将现有最后一个的汉字的箭头隐藏
				auto chr = m_SelectedChrs.back();
				auto arrow = chr->getArrow();
				for (int i = 0; i < 8; i++) { if (arrow[i]->isVisible()) arrow[i]->setVisible(false); }

				m_canCrush = canCrush();
				/*
				if (m_canCrush)
				{
				for (auto &chr : m_SelectedChrs)
				{
				chr->chrAciton();
				}
				}
				*/
			}

			//更改主界面的letter label的显示
			getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), m_canCrush);
		}
	}
}