void ScreenMap::init(Map *pMap, bool pHasGrid, bool pHasBuildings) { map = pMap; hasGrid = pHasGrid; hasBuildings = pHasBuildings; imageSize = 64; imagesFolder = "images"; updateSize(); resetFieldSelection(); resetMove(); Uint16 terrainNamesCount = map->getTerrainNamesCount(); Uint16 itemNamesCount = map->getItemNamesCount(); terrainSurfaces = new SDL_Surface*[terrainNamesCount]; itemSurfaces = new SDL_Surface*[itemNamesCount]; Uint16 buildingNamesCount = 0; if (hasBuildings == true) { buildingNamesCount = map->getBuildingNamesCount(); buildingSurfaces = new SDL_Surface*[buildingNamesCount]; } int i; string file; for (i = 0; i < terrainNamesCount; i++) { file = imagesFolder + "/terrain/" + map->getTerrainName(i) + "_" + to_string(imageSize) + ".png"; terrainSurfaces[i] = loadImage(file); } for (i = 0; i < itemNamesCount; i++) { file = imagesFolder + "/items/" + map->getItemName(i) + "_" + to_string(imageSize) + ".png"; itemSurfaces[i] = loadImage(file); } if (buildingNamesCount > 0) { for (i = 0; i < buildingNamesCount; i++) { file = imagesFolder + "/buildings/" + map->getBuildingName(i) + "_" + to_string(imageSize) + ".png"; buildingSurfaces[i] = loadImage(file); } } }
void GameStateOnline::input(float dt){ sf::Event event; while(this->game->window.pollEvent(event)){ if (event.type == sf::Event::Closed) game->window.close(); std::string signal; for(auto& button : buttons){ signal = button->onEvent(event); if(signal == "main menu"){ game->changeState(new GameStateMainMenu(game)); break; } else if(signal == "quit"){ game->window.close(); break; } } //klikniecie escape if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape){ printf("escape closing\n"); this->game->window.close(); } //klikniece lmb if (currentPlayer == 1) { if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left){ //jezeli fromAdress jest pusty if(board.isFromAdressEmpty()){ //jezeli kliknieto wewnatrz planszy if(board.isAdressWithinBoard(board.mouseToAdress(&this->game->window))){ //jezeli gracz klika na swoj pionek if(( board.returnState(board.mouseToAdress(&this->game->window)) == BLACK_PIECE || board.returnState(board.mouseToAdress(&this->game->window)) == BLACK_KING ) && currentPlayer == 1) { board.fromAdress = board.mouseToAdress(&this->game->window); //zapisz klikniety adres we fromAdress board.highlightField(board.fromAdress, 1); //podswietl pole z ktorego chcemy ruszyc pionek } } } //jezeli fromAdress nie jest pusty else{ //jezeli toAdress jest pusty if(board.isToAdressEmpty()){ //jezeli kliknieto wewnatrz planszy if(board.isAdressWithinBoard(board.mouseToAdress(&this->game->window))){ //jezeli pole w ktore chcemy sie ruszyc jest puste if(board.returnState(board.mouseToAdress(&this->game->window)) == BLACK){ board.toAdress = board.mouseToAdress(&this->game->window); //zapisz klikniety adres w toAdress board.highlightField(board.toAdress, 2); //podswietl pole do ktorego chcemy ruszyc pionek if(!board.isMoveLegal(currentPlayer)) resetMove(); //jezeli dany ruch jest nielegalny to zresetuj ruch if(board.possibleCapture(currentPlayer) && !captureCheck()) resetMove(); //jezeli mozliwe jest bicie dany ruch nie jest biciem to zresetuj ruch } else resetMove(); //jezeli pole do ktorego chcemy sie ruszyc jest niepuste to zresetuj } else resetMove();//jezeli klikniemy poza plansza to zresetuj } //jezeli toAdress nie jest pusty else{ //jezeli kliknelismy ponownie na pole do ktorego chcemy sie ruszyc if(board.mouseToAdress(&this->game->window) == board.toAdress){ //jezeli mozliwe jest bicie if(board.possibleCapture(currentPlayer)){ capture(); //wykonaj bicie movesSinceLastCapture = 0; board.movePiece(board.fromAdress, board.toAdress); movePieceSound.play(); //jezeli niemozliwe jest wieloktotne bicie if(!board.possibleCapture(board.toAdress, currentPlayer)){ isEndOfLocalPlayerTurn = true; } } //jezeli niemozliwe jest bicie else{ board.movePiece(board.fromAdress, board.toAdress); //rusz pionek z fromAdress do toAdress movesSinceLastCapture++; movePieceSound.play(); isEndOfLocalPlayerTurn = true; } } resetMove(); //klikniecie gdzie indziej niz na zadeklarowane pole do ktorego chcemy sie ruszyc lub wykonanie ruchu resetuje dane o ruchu } } } } } }