]> git.seodisparate.com - EN605.607.81.SP22_ASDM_Project/commitdiff
Reorder code to print winning move sprint_02_day_4
authorStephen Seo <seo.disparate@gmail.com>
Thu, 10 Mar 2022 09:16:30 +0000 (18:16 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 10 Mar 2022 09:16:30 +0000 (18:16 +0900)
Previously, the winning move was not printed at the bottom info_text.

front_end/src/yew_components.rs

index d9d3e91f307b519fc74bdc20a3c6f8d98a9a663f..ab54a16460d8be142e89ee40acec6cf7b1c506ce 100644 (file)
@@ -337,6 +337,40 @@ impl Component for Wrapper {
                     placed = true;
                 }
 
+                // info text below the grid
+                {
+                    let output_str = match placed {
+                        true => format!("{} placed into slot {}", current_player, bottom_idx),
+                        false => "Invalid place to insert".into(),
+                    };
+
+                    let text_append_result = append_to_info_text(
+                        &document,
+                        "info_text0",
+                        &output_str,
+                        INFO_TEXT_MAX_ITEMS,
+                    );
+                    if let Err(e) = text_append_result {
+                        log::warn!("ERROR: text append to info_text0 failed: {}", e);
+                    }
+                }
+
+                // info text right of the grid
+                {
+                    let turn = shared.turn.get();
+                    let output_str = format!(
+                        "<b class=\"{}\">It is {}'s turn</b>",
+                        turn.get_color(),
+                        turn
+                    );
+
+                    let text_append_result =
+                        append_to_info_text(&document, "info_text1", &output_str, 1);
+                    if let Err(e) = text_append_result {
+                        log::warn!("ERROR: text append to info_text1 failed: {}", e);
+                    }
+                }
+
                 // check for win
                 let check_win_draw_opt = check_win_draw(&shared.board);
                 if let Some((endgame_state, win_type)) = check_win_draw_opt {
@@ -683,43 +717,7 @@ impl Component for Wrapper {
                     shared
                         .game_state
                         .replace(GameState::PostGameResults(endgame_state));
-                } else {
-                    // game is still ongoing
-
-                    // info text below the grid
-                    {
-                        let output_str = match placed {
-                            true => format!("{} placed into slot {}", current_player, bottom_idx),
-                            false => "Invalid place to insert".into(),
-                        };
-
-                        let text_append_result = append_to_info_text(
-                            &document,
-                            "info_text0",
-                            &output_str,
-                            INFO_TEXT_MAX_ITEMS,
-                        );
-                        if let Err(e) = text_append_result {
-                            log::warn!("ERROR: text append to info_text0 failed: {}", e);
-                        }
-                    }
-
-                    // info text right of the grid
-                    {
-                        let turn = shared.turn.get();
-                        let output_str = format!(
-                            "<b class=\"{}\">It is {}'s turn</b>",
-                            turn.get_color(),
-                            turn
-                        );
-
-                        let text_append_result =
-                            append_to_info_text(&document, "info_text1", &output_str, 1);
-                        if let Err(e) = text_append_result {
-                            log::warn!("ERROR: text append to info_text1 failed: {}", e);
-                        }
-                    }
-                } // else: game is still ongoing after logic check
+                } // if: check for win or draw
 
                 // check if it is AI's turn
                 if let GameState::SinglePlayer(player_type, ai_difficulty) = shared.game_state.get()