Exemplo n.º 1
0
void clickOnScreen(Interface *interfaces, int x,int y){
	FieldInterface *field = interfaces->field;
	Menu *menu = interfaces->menu;
	if(menu->currentItem != NULL){
		field->hasChanged = placeTower(interfaces, x, y);
	}
}
Exemplo n.º 2
0
bool WorldScene::event(QEvent *event)
{
    //Allowing hovered item to display differently.
    if (event->type() == QEvent::GraphicsSceneMouseMove)
    {
        QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
        QGraphicsItem * itemHovered = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
        if(itemHovered != m_hoveredItem )
        {
	    if(m_hoveredItem)
                static_cast<HexTile *>(m_hoveredItem)->hoverLeaveEvent(e);
	    if(itemHovered)
                static_cast<HexTile *>(itemHovered)->hoverEnterEvent(e);

            m_hoveredItem = itemHovered;
        }
        e->accept();
        return true;
    }
    //Handling clicks to create/remove towers
    else if(event->type() == QEvent::GraphicsSceneMousePress)
    {
        QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
        if(e->button() == Qt::LeftButton)
        {
	    QGraphicsItem * item = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
	    if(item)
		emit placeTower(item);
        }
        else if(e->button() == Qt::RightButton)
        {
	    QGraphicsItem * item = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
	    if(item)
		emit removeTower(item);
        }
    }

    return QGraphicsScene::event(event);
    //return true;
}
Exemplo n.º 3
0
int game_host::performUpdate(string upd)
{
	int updateType = 0;
	UpdMess update(upd);
	updateType = update.getType();

	if(updateType == TOWER)
	{
		int subType = update.getVal(0);
		//Tower Placement:		UpdMess(Player[1], TOWER, TOWERPLACE[2], TowerX[2], Tower[Y]);
		if(subType == TOWERPLACE)
		{
			// placeTower(int playerNumber, int towerType, int x, int y);
			if(isEmptyLocation(update.getVal(1), update.getVal(2)))
			{
				placeTower(update.getPlayer(), STRUCTURE, update.getVal(1), update.getVal(2));
			}
		}	
		else if(subType == MINEPLACE)
		{
			if(isEmptyLocation(update.getVal(1), update.getVal(2)))
			{
				placeTower(update.getPlayer(), MINETOWER, update.getVal(1), update.getVal(2));
			}
		}
		//Tower Upgrade:			UpdMess(Player[1], TOWER, TOWERUPGRADE[2], TowerID[4]);
		else if(subType == TOWERUPGRADE)
		{
			if(towerList.checkForObjectWithID(update.getId1()) == true)
			{
				if(towerList.getNodeWithID(update.getId1())->getData()->getType() != STRUCTURE)
				{
					if(towerList.getNodeWithID(update.getId1())->getData()->upgrade())
					{
						sendMessageToQueue(UpdMess(update.getPlayer(), TOWER, TOWERUPGRADE, update.getId1()).getMT());
					}
				}
			}
		}
		//Tower ChangeType:		UpdMess(Player[1], TOWER, TOWERCHANGE[2], TowerID[4], newType[2]);	
		else if(subType == TOWERCHANGE)
		{
			if(towerList.checkForObjectWithID(update.getId1()) == true)
			{
				if(towerList.getNodeWithID(update.getId1())->getData()->getType() == STRUCTURE)
				{
					return changeStructure(update.getId1(), update.getVal(1));
				}
				else if(towerList.getNodeWithID(update.getId1())->getData()->getType() == NORMCREEPTOWER)
				{
					if(towerList.getNodeWithID(update.getId1())->getData()->changeType(update.getVal(1)))
					{
						sendMessageToQueue(UpdMess(update.getPlayer(), TOWER, TOWERCHANGE, update.getId1(),update.getVal(1)).getMT());
					}
				}
			}
		}
		//Tower Toggle Pause:		UpdMess(Player[1], TOWER, TOWERTOGGLE[2], TowerID[4], newValue);
		else if(subType == TOWERTOGGLE)
		{
			if(towerList.checkForObjectWithID(update.getId1()))
			{
				int towerTypeRec = towerList.getNodeWithID(update.getId1())->getData()->getType();
				if(towerList.getNodeWithID(update.getId1())->getData()->getType() >= NORMCREEPTOWER && towerList.getNodeWithID(update.getId1())->getData()->getType() <= FATTYCREEPTOWER)
				{
					if(update.getVal(1) == 1)
						towerList.getNodeWithID(update.getId1())->getData()->pause();
					else if(update.getVal(1) == 0)
						towerList.getNodeWithID(update.getId1())->getData()->unpause();
					sendMessageToQueue(UpdMess(towerList.getNodeWithID(update.getId1())->getData()->getPlayer(), TOWER, TOWERTOGGLE, update.getId1(), towerList.getNodeWithID(update.getId1())->getData()->isPaused()).getMT());
				}
			}
		}
		else if(subType == TOWERDELETE)
		{	
			if(towerList.checkForObjectWithID(update.getId1()))
			{
				removeTower(update.getId1(), update.getPlayer());
			}
		}

	}
	else if(updateType == BASE)
	{
		int subType = update.getVal(0);
		if(subType == UPGRADE)
		{
			if(this->getPlayer(update.getPlayer())->getMoney() >= BASEUPGRADECOST)
			{
				if(update.getPlayer() == 1)
				{
					if(this->p1Spawner->getLevel() < 5 && players[0].getMoney() >= (p1Spawner->getLevel() + 1) * BASEUPGRADECOST)
					{
						players[0].spendMoney((p1Spawner->getLevel() + 1) * BASEUPGRADECOST);
						this->p1Spawner->setLevel(this->p1Spawner->getLevel() + 1);
						sendMessageToQueue(UpdMess(1, BASE, UPGRADE).getMT());
					}
				}
				else if(update.getPlayer() == 2)
				{
					if(this->p2Spawner->getLevel() < 5 && players[1].getMoney() >= (p2Spawner->getLevel() + 1) * BASEUPGRADECOST)
					{
						players[1].spendMoney((p2Spawner->getLevel() + 1) * BASEUPGRADECOST);
						this->p2Spawner->setLevel(this->p2Spawner->getLevel() + 1);
						sendMessageToQueue(UpdMess(2, BASE, UPGRADE).getMT());
					}
				}
			}
		}
		else if(subType == ADDTYPE)
		{
			int addType = update.getVal(1);
			if(!(addType >= FAST && addType <= FATTY))
				return -1;
			if(update.getPlayer() == 1)
			{
				if(this->p1Spawner->isInSpawner(addType))
					return -1;	// Already in the spawner
			}
			else if(update.getPlayer() == 2)
			{
				if(this->p2Spawner->isInSpawner(addType))
					return -1;  // Already in the spawner
			}
			else
				return -1;
			if(this->getPlayer(update.getPlayer())->getMoney() >= addSpawnArr[addType])
			{
				this->getPlayer(update.getPlayer())->spendMoney(addSpawnArr[addType]);
				if(update.getPlayer() == 1)
				{
					this->p1Spawner->addCreepType(addType);
					sendMessageToQueue(UpdMess(1, BASE, ADDTYPE, addType).getMT());
				}
				else
				{
					this->p2Spawner->addCreepType(addType);
					sendMessageToQueue(UpdMess(2, BASE, ADDTYPE, addType).getMT());
				}
			}
		}
		else
			return -1;
	}
	else 
		return -1;
	sendMessageToQueue(UpdMess(1, PLAYERUPDATE, getPlayer(1)->getHealth(), getPlayer(1)->getMoney()).getMT());
	sendMessageToQueue(UpdMess(2, PLAYERUPDATE, getPlayer(2)->getHealth(), getPlayer(2)->getMoney()).getMT());
	return 0;
}