void makeMove(TILE t1, TILE t2, TILE board[]) { board[getIndex(t2)].piece = t1.piece; board[getIndex(t1)].piece = 0; for (int i = 0; i < 4; i++) { // loop over the directions if (hasEnemy(i, board, getIndex(t2)) > 0) { TILE r = getRelativeTile(i, board[getIndex(t2)], board); if (hasEnemy(i, board, getIndex(r)) > 0 && r.piece != 3) { board[getIndex(r)].piece = 0; } } } }
char hasWinner(TILE board[], TILE last) { if (last.attr == 1) return 2; int i; for (i = 0; i < 11*11; i++) { if (board[i].piece==3) break; } if (hasEnemy(LEFT, board, i) && hasEnemy(RIGHT, board, i) && hasEnemy(UP, board, i) && hasEnemy(DOWN, board, i)) { if (bordersKing(last, board[i])) { return 1; } } return 0; }
void Tile::resolveEvent(sf::Event event) { spriteUpdate(1); if (isPolluted()) { currentSprite = 2; spriteUpdate(currentSprite); } else if (!hasEnemy()) { if (event.type == sf::Event::MouseButtonPressed) { isClicking = true; if (currentSprite == 0) { currentSprite = 1; spriteUpdate(currentSprite); } } if (event.type == sf::Event::MouseButtonReleased) { isClicked = true; if (currentSprite == 0) { currentSprite = 1; spriteUpdate(currentSprite); } if (hasTower()) { openTowerMenu(); } else { hasTw = true; if (LevelManager::getLevelManager()->getField().tryCross(LevelManager::getLevelManager()->getField().getTile(NUM_START_TILE), LevelManager::getLevelManager()->getField().getTile(NUM_END_TILE))) { openBuildMenu(); } hasTw = false; } } } }
int Monster::mobileCrt() { BaseRoom *newRoom=0; AreaRoom *caRoom = getAreaRoomParent(); int i=0, num=0, ret=0; bool mem=false; if( !flagIsSet(M_MOBILE_MONSTER) || flagIsSet(M_PERMENANT_MONSTER) || flagIsSet(M_PASSIVE_EXIT_GUARD) ) return(0); if(nearEnemy()) return(0); for(Exit* exit : getRoomParent()->exits) { // count up exits if(mobileEnter(exit)) i += 1; } if(!i) return(0); num = mrand(1, i); i = 0; for(Exit* exit : getRoomParent()->exits) { if(mobileEnter(exit)) i += 1; if(i == num) { // get us out of this room if(!Move::getRoom(this, exit, &newRoom)) return(0); if(newRoom->isAreaRoom()) { mem = newRoom->getAsAreaRoom()->getStayInMemory(); newRoom->getAsAreaRoom()->setStayInMemory(true); } // make sure there are no problems with the new room if(!newRoom) return(0); if(newRoom->countCrt() >= newRoom->getMaxMobs()) return(0); // no wandering between live/construction areas if(newRoom->isConstruction() != getRoomParent()->isConstruction()) return(0); if(exit->flagIsSet(X_CLOSED) && !exit->flagIsSet(X_LOCKED)) { broadcast(nullptr, getRoomParent(), "%M just opened the %s.", this, exit->getCName()); exit->clearFlag(X_CLOSED); } if(flagIsSet(M_WILL_SNEAK) && flagIsSet(M_HIDDEN)) setFlag(M_SNEAKING); if( flagIsSet(M_SNEAKING) && mrand (1,100) <= (3+dexterity.getCur())*3) { broadcast(::isStaff, getSock(), getRoomParent(), "*DM* %M just snuck to the %s.", this,exit->getCName()); } else { Creature* lookingFor = nullptr; if(flagIsSet(M_CHASING_SOMEONE) && hasEnemy() && ((lookingFor = getTarget(false)) != nullptr) ) { broadcast(nullptr, getRoomParent(), "%M %s to the %s^x, looking for %s.", this, Move::getString(this).c_str(), exit->getCName(), lookingFor->getCName()); } else broadcast(nullptr, getRoomParent(), "%M just %s to the %s^x.", this, Move::getString(this).c_str(), exit->getCName()); clearFlag(M_SNEAKING); } // see if we can recycle this room deleteFromRoom(); if(caRoom && newRoom == caRoom && newRoom->isAreaRoom()) { newRoom = Move::recycle(newRoom->getAsAreaRoom(), exit); } addToRoom(newRoom); // reset stayInMemory if(newRoom->isAreaRoom()) newRoom->getAsAreaRoom()->setStayInMemory(mem); lasttime[LT_MON_WANDER].ltime = time(0); lasttime[LT_MON_WANDER].interval = mrand(5,60); ret = 1; break; } } if(mrand(1,100) > 80) clearFlag(M_MOBILE_MONSTER); return(ret); }