void LinkedList<T>::deleteList() { ComponentPtr currPtr = head; while(currPtr != nullptr) { //cout<<"Count is: "<<x<<endl; removeShip(currPtr); currPtr = head; } head = nullptr; tail = nullptr; }
int startGame(){ int posX, posY; /* User coordinates input */ system("clear"); /* Initialize some positions for enemy ships */ enemyShipTable[0][0]=1; enemyShipTable[1][1]=1; enemyShipTable[2][2]=1; enemyShipTable[3][3]=1; enemyShipTable[4][4]=1; do{ printf("Digite a posicao que deseja atirar (x y):\n"); printf("*Para sair digite (-1 -1)\n"); scanf("%i %i", &posX, &posY); while(!coordIsValid(posX, posY)){ printf("Coordenadas invalidas! Tente novamente\n"); scanf("%i" "%i", &posX, &posY); } system("clear"); if(posX!=-1 && posY!=-1){ if(isAHit(posX, posY)==1){ removeShip(posX, posY); printf("Acertou um navio!\n"); } else printf("Errou! Tente novamente\n"); if(gameIsOver()) printf("Acertou todos os navios\nParabens voce venceu!\n"); } else /* Back to main menu if (-1 -1)*/ return 0; }while((posX!=-1 && posY!=-1) && gameIsOver()==0); printf("\n[Pressione ENTER para voltar ao menu]\n"); getchar(); getchar(); return 0; }
// Ship tick format: (5) // x * 10 | y * 10 | thruster angle * 100 | force * 100 | energy * 10 void ReplayBuilder::addShipStates(Ship **ships, int time) { for (int x = 0; x < numShips_; x++) { Ship *ship = ships[x]; if (shipsAlive_[x] != ship->alive) { if (ship->alive) { addShip(ship->index, time); } else { removeShip(ship->index, time); } shipsAlive_[x] = ship->alive; } if (shipsShowName_[x] != ship->showName) { if (ship->showName) { addShipShowName(ship->index, time); } else { addShipHideName(ship->index, time); } shipsShowName_[x] = ship->showName; } if (shipsShowEnergy_[x] != ship->energyEnabled) { if (ship->energyEnabled) { addShipShowEnergy(ship->index, time); } else { addShipHideEnergy(ship->index, time); } shipsShowEnergy_[x] = ship->energyEnabled; } } for (int x = 0; x < numShips_; x++) { Ship *ship = ships[x]; if (ship->alive) { shipTickData_->addInt(round(ship->x * 10)); shipTickData_->addInt(round(ship->y * 10)); shipTickData_->addInt( round(normalAbsoluteAngle(ship->thrusterAngle) * 100)); shipTickData_->addInt(round(limit(0, ship->thrusterForce, 1) * 100)); shipTickData_->addInt(round(std::max(0., ship->energy) * 10)); } } }