@@ -97,14 +97,22 @@ const ImageSlider = () => {
9797 } ;
9898
9999 const startGame = ( ) => {
100- if ( currentIndex === 0 ) {
101- setShowStage1 ( true ) ; // Show Stage1 for map1
102- } else if ( currentIndex === 1 ) {
103- setShowStage2 ( true ) ; // Show Stage2 for map2
104- } else if ( currentIndex === 2 ) {
105- setShowStage3 ( true ) ; // Show Stage3 for map3
100+ if ( showStage1 || showStage2 || showStage3 ) {
101+ // If any stage is already open, close all stages
102+ setShowStage1 ( false ) ;
103+ setShowStage2 ( false ) ;
104+ setShowStage3 ( false ) ;
106105 } else {
107- navigate ( `/game/stage${ currentIndex + 1 } ` , { state : { stageIndex : currentIndex } } ) ;
106+ // Otherwise, start the game based on the current index
107+ if ( currentIndex === 0 ) {
108+ setShowStage1 ( true ) ; // Show Stage1 for map1
109+ } else if ( currentIndex === 1 ) {
110+ setShowStage2 ( true ) ; // Show Stage2 for map2
111+ } else if ( currentIndex === 2 ) {
112+ setShowStage3 ( true ) ; // Show Stage3 for map3
113+ } else {
114+ navigate ( `/game/stage${ currentIndex + 1 } ` , { state : { stageIndex : currentIndex } } ) ;
115+ }
108116 }
109117 } ;
110118
@@ -242,7 +250,7 @@ const ImageSlider = () => {
242250 </ map >
243251 </ div >
244252 < button onClick = { startGame } style = { { marginTop : '10px' , marginBottom : '10px' } } >
245- 미니 게임 시작
253+ { showStage1 || showStage2 || showStage3 ? ' 미니 게임 닫기' : '미니 게임 시작' }
246254 </ button >
247255 { currentIndex > 0 && (
248256 < button
0 commit comments