From eb7bb5ed64b6202e8a52adcb875af951d3e8dd4c Mon Sep 17 00:00:00 2001 From: David Leal Date: Mon, 23 Oct 2023 14:12:20 -0600 Subject: [PATCH] Document the functions and variables (#10) --- src/TicTacToe.h | 3 ++- src/game.cpp | 13 +++++++++++-- src/game.hpp | 4 ++-- src/menu.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/TicTacToe.h b/src/TicTacToe.h index 307e405..69ec390 100644 --- a/src/TicTacToe.h +++ b/src/TicTacToe.h @@ -438,7 +438,8 @@ namespace TicTacToe { } #pragma endregion - array^ buttons = gcnew array(11); // Array of buttons + // Array containing the buttons to place O and X. + array^ buttons = gcnew array(11); private: System::Void button_click(System::Object^ sender, System::EventArgs^ e) { // Buttons to place O and X is_match(sender, buttons, label2); diff --git a/src/game.cpp b/src/game.cpp index 7f56381..4e45b6b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -28,9 +28,18 @@ using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; -int turn = 0; // Whether to choose if the X or the O will place. -bool match_ended = false; // If the match has ended or not. +int turn = 0; +bool match_ended = false; +/** + * @brief The function to determine if it's a match or not + * Also updates the text of the buttons when clicking on them, + * the current turn, and a label that shows who's the winner. + * @param sender The item that triggered the event + * @param buttons An array containing various buttons + * @param label2 The label that shows who's the winner + * @return void +*/ void is_match(System::Object^ sender, array^ buttons, Label^ label2) { Button^ button = safe_cast(sender); diff --git a/src/game.hpp b/src/game.hpp index 8e40dba..0c0e1cb 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -19,8 +19,8 @@ #ifndef GAME_HPP #define GAME_HPP -extern int turn; -extern bool match_ended; +extern int turn; // Whether to choose if the X or the O will place. +extern bool match_ended; // If the match has ended or not. void is_match(System::Object^, array^, System::Windows::Forms::Label^); diff --git a/src/menu.cpp b/src/menu.cpp index f722a45..c0ff868 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -25,6 +25,17 @@ using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; +/** + * @brief Shows the necessary buttons and labels that + * lets the user choose who's going to start first. + * This function can also hide those elements. + * @param turn_o The button that lets the user choose the O to start first + * @param turn_x The button that lets the user choose the X to start first + * @param label3 A label with the text "Who's going to start first?" + * @param backmodeselect A button that lets the user go back to the mode selection + * @param mode A boolean that determines if the elements should be shown or not + * @return void +*/ void choose_turn(Button^ turn_o, Button^ turn_x, Label^ label3, Button^ backmodeselect, bool mode) { if (mode == true) { turn_o->Enabled = true; @@ -46,6 +57,21 @@ void choose_turn(Button^ turn_o, Button^ turn_x, Label^ label3, Button^ backmode } } +/** + * @brief Shows the necessary buttons and labels that + * lets the user choose the mode of the game. + * This function can also hide those elements, and show or hide + * the elements called in the `choose_turn` function. + * @param multiplayer_mode The button that will choose multiplayer as the current mode + * @param ai_mode The button that will choose A.I. as the current mode + * @param label4 A label with the text "Choose the mode of the game" + * @param turn_o The button that lets the user choose the O to start first + * @param turn_x The button that lets the user choose the X to start first + * @param backmodeselect A button that lets the user go back to the mode selection + * @param label3 A label with the text "Who's going to start first?" + * @param mode A boolean that determines if the elements should be shown or not + * @return void +*/ void choose_mode(Button^ multiplayer_mode, Button^ ai_mode, Label^ label4, Button^ turn_o, Button^ turn_x, Button^ backmodeselect, Label^ label3, bool mode) { if (mode == true) { multiplayer_mode->Enabled = true;