@@ -35,7 +35,7 @@ std::string formatTime(sf::Time time) {
3535// 게임 루프 함수 선언
3636void gameLoop (
3737 sf::RenderWindow& window,
38- sf::Font& font, // 폰트는 UI 요소들이 이미 참조하고 있지만, 혹시 몰라 전달
38+ sf::Font& font,
3939 sf::RectangleShape& tile,
4040 sf::Color& lightColor,
4141 sf::Color& darkColor,
@@ -57,12 +57,13 @@ void gameLoop(
5757 std::vector<sf::Vector2i>& possibleMoves,
5858 PieceColor& currentTurn,
5959 std::string& gameMessageStr,
60- std::map<std::string, sf::Texture>& textures, // place_piece 람다 때문에 필요할 수 있음 (actualResetGame 통해)
60+ std::map<std::string, sf::Texture>& textures,
6161 std::array<std::array<std::optional<Piece>, 8 >, 8 >& board_state,
6262 sf::Time& whiteTimeLeft,
6363 sf::Time& blackTimeLeft,
6464 sf::Clock& frameClock,
65- std::function<void ()> actualResetGame // resetGame 람다 전달
65+ std::function<void ()> actualResetGame,
66+ float timerPadding // timerPadding 파라미터 추가
6667) {
6768 // --- 메인 게임 루프 ---
6869 while (window.isOpen ()) {
@@ -96,9 +97,9 @@ void gameLoop(
9697 whiteTimerText.setString (" White: " + formatTime (whiteTimeLeft));
9798 blackTimerText.setString (" Black: " + formatTime (blackTimeLeft));
9899
99- sf::FloatRect wt_bounds_loop = whiteTimerText.getLocalBounds (); // 루프 내에서 사용될 변수명
100- whiteTimerText.setPosition ({ BOARD_WIDTH + (BUTTON_PANEL_WIDTH - wt_bounds_loop.size .x ) / 2 .f - wt_bounds_loop.position .x , timerPadding - wt_bounds_loop.position .y });
101- sf::FloatRect bt_bounds_loop = blackTimerText.getLocalBounds (); // 루프 내에서 사용될 변수명
100+ sf::FloatRect wt_bounds_loop = whiteTimerText.getLocalBounds ();
101+ whiteTimerText.setPosition ({ BOARD_WIDTH + (BUTTON_PANEL_WIDTH - wt_bounds_loop.size .x ) / 2 .f - wt_bounds_loop.position .x , timerPadding - wt_bounds_loop.position .y }); // 전달받은 timerPadding 사용
102+ sf::FloatRect bt_bounds_loop = blackTimerText.getLocalBounds ();
102103 blackTimerText.setPosition ({ BOARD_WIDTH + (BUTTON_PANEL_WIDTH - bt_bounds_loop.size .x ) / 2 .f - bt_bounds_loop.position .x , whiteTimerText.getPosition ().y + wt_bounds_loop.size .y + wt_bounds_loop.position .y + 5 .f - bt_bounds_loop.position .y });
103104
104105 // 이벤트 처리
@@ -188,7 +189,7 @@ void gameLoop(
188189 } else { selectedPiecePos.reset (); possibleMoves.clear (); }
189190 } else if (currentGameState == GameState::GameOver) {
190191 if (homeButtonShape.getGlobalBounds ().contains (static_cast <sf::Vector2f>(mousePos))) {
191- actualResetGame (); // 전달받은 람다 호출
192+ actualResetGame ();
192193 }
193194 }
194195 }
@@ -299,12 +300,7 @@ int main() {
299300 sf::Text blackTimerText (font, " 00:00" , 22 );
300301 blackTimerText.setFillColor (sf::Color::Black);
301302
302- // float timerPadding = 15.f; // gameLoop 함수 내에서 지역 변수로 사용
303- // sf::FloatRect wt_bounds = whiteTimerText.getLocalBounds(); // gameLoop 함수 내에서 지역 변수로 사용
304- // whiteTimerText.setPosition(...); // gameLoop 함수 내에서 업데이트
305- // sf::FloatRect bt_bounds = blackTimerText.getLocalBounds(); // gameLoop 함수 내에서 지역 변수로 사용
306- // blackTimerText.setPosition(...); // gameLoop 함수 내에서 업데이트
307-
303+ float timerPadding = 15 .f ; // main 함수에 timerPadding 정의
308304
309305 float buttonWidth = BUTTON_PANEL_WIDTH - 80 ;
310306 float buttonHeight = 50 .f ;
@@ -381,7 +377,7 @@ int main() {
381377 sf::Time blackTimeLeft = sf::seconds (INITIAL_TIME_SECONDS);
382378 sf::Clock frameClock;
383379
384- auto place_piece = [&](int r, int c, PieceType type, PieceColor piece_color, const std::string& name_str) { // name -> name_str
380+ auto place_piece = [&](int r, int c, PieceType type, PieceColor piece_color, const std::string& name_str) {
385381 std::string key = (piece_color == PieceColor::White ? " w_" : " b_" ) + name_str;
386382 if (textures.count (key) == 0 || textures[key].getSize ().x == 0 ) {
387383 std::cerr << " Texture for key '" << key << " ' not found or invalid!" << std::endl; return ;
@@ -398,12 +394,12 @@ int main() {
398394 auto actualSetupBoard = [&]() {
399395 board_state = {};
400396 place_piece (7 ,0 ,PieceType::Rook,PieceColor::White," rook" ); place_piece (7 ,1 ,PieceType::Knight,PieceColor::White," knight" ); place_piece (7 ,2 ,PieceType::Bishop,PieceColor::White," bishop" ); place_piece (7 ,3 ,PieceType::Queen,PieceColor::White," queen" ); place_piece (7 ,4 ,PieceType::King,PieceColor::White," king" ); place_piece (7 ,5 ,PieceType::Bishop,PieceColor::White," bishop" ); place_piece (7 ,6 ,PieceType::Knight,PieceColor::White," knight" ); place_piece (7 ,7 ,PieceType::Rook,PieceColor::White," rook" );
401- for (int c_idx=0 ;c_idx<8 ;++c_idx)place_piece (6 ,c_idx,PieceType::Pawn,PieceColor::White," pawn" ); // c -> c_idx
397+ for (int c_idx=0 ;c_idx<8 ;++c_idx)place_piece (6 ,c_idx,PieceType::Pawn,PieceColor::White," pawn" );
402398 place_piece (0 ,0 ,PieceType::Rook,PieceColor::Black," rook" ); place_piece (0 ,1 ,PieceType::Knight,PieceColor::Black," knight" ); place_piece (0 ,2 ,PieceType::Bishop,PieceColor::Black," bishop" ); place_piece (0 ,3 ,PieceType::Queen,PieceColor::Black," queen" ); place_piece (0 ,4 ,PieceType::King,PieceColor::Black," king" ); place_piece (0 ,5 ,PieceType::Bishop,PieceColor::Black," bishop" ); place_piece (0 ,6 ,PieceType::Knight,PieceColor::Black," knight" ); place_piece (0 ,7 ,PieceType::Rook,PieceColor::Black," rook" );
403- for (int c_idx=0 ;c_idx<8 ;++c_idx)place_piece (1 ,c_idx,PieceType::Pawn,PieceColor::Black," pawn" ); // c -> c_idx
399+ for (int c_idx=0 ;c_idx<8 ;++c_idx)place_piece (1 ,c_idx,PieceType::Pawn,PieceColor::Black," pawn" );
404400 };
405401
406- auto actualResetGame_lambda = [&]() { // 람다 이름 변경 (gameLoop에 전달할 것이므로)
402+ auto actualResetGame_lambda = [&]() {
407403 actualSetupBoard ();
408404 currentGameState = GameState::ChoosingPlayer;
409405 currentTurn = PieceColor::None;
@@ -426,7 +422,8 @@ int main() {
426422 popupBackground, popupMessageText, homeButtonShape, homeButtonText,
427423 currentGameState, selectedPiecePos, possibleMoves, currentTurn, gameMessageStr,
428424 textures, board_state, whiteTimeLeft, blackTimeLeft, frameClock,
429- actualResetGame_lambda // 람다 전달
425+ actualResetGame_lambda,
426+ timerPadding // timerPadding 전달
430427 );
431428
432429 return 0 ;
0 commit comments