{"id":6075,"date":"2025-01-22T04:55:46","date_gmt":"2025-01-22T04:55:46","guid":{"rendered":"https:\/\/obsidiansofteducation.com\/?page_id=6075"},"modified":"2026-03-06T18:37:31","modified_gmt":"2026-03-06T18:37:31","slug":"tic-tac-toe-in-mit-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/tic-tac-toe-in-mit-app-inventor\/","title":{"rendered":"Tic Tac Toe in MIT App Inventor"},"content":{"rendered":"\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong>Hello friends and welcome to Obsidian Soft.<\/strong><\/h3>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Today, I will teach how to make a tic tac toe game in mit app inventor. Go to<a href=\"https:\/\/appinventor.mit.edu\/\" target=\"_blank\" rel=\"noopener\"> MIT App Inventor<\/a> and start a new project. Name it TicTacToeGame.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong>Design the Game Interface<\/strong><\/h3>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make screen orientation portrait and change the title to Tic Tac Toe<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop a horizontal arrangement from layouts onto the viewer. Make height 28% and width fill parent. Drag and drop a button from the user interface inside this viewer. Make the background color: light grey. Make font bold and font size 60. Make height fill parent. Width 33%. Remove text from it.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Select button. Duplicate by pressing Ctrl + C &amp; Ctrl + V on the keyboard for Windows or Command + C and Command + V on the keyboard for MacOS.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Duplicate button again. There should be 3 buttons in the horizontal arrangement.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, select the horizontal arrangement. Duplicate it. Duplicate it again.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag another horizontal arrangement. Make align horizontal and align vertical both center. Make width full parent and height 10%. Drag and drop a label from the user interface inside this arrangement. Name it statusLbl.Set its properties:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Text: <strong>&#8220;Turn: X&#8221;, <\/strong>FontSize: <strong>20, <\/strong>Font: bold<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag a button on the right of this label. Make font bold, font size 20 and background color: yellow. Rename button to resetBtn. Make width 40% and shape rounded. And change the text to Reset.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Our screen is done so let\u2019s go to the blocks sectio<strong>n.<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make global variables for the current player with the initial value \u201cX\u201d, a status boolean variable whether the game is active. It will become inactive after a win or a draw. We will also make a list of game buttons that will contain all the buttons that are part of our 3&#215;3 game grid. We also need a list for storing our winning combinations.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXcRGxpaJadY_EPcQCO308ML7S6iLibvTddhcLXt1oNTadIJJrjSelLnHYtZ-NSHzC3fsBlQtM8BimaZQ3KawyeXsHnGNjdysAvAEBTUXjxkuswoiJofCRA-b1RBrXuS_wSY_Z-aEAkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Get the screen1. Initialize event. We need to load our lists. Winning combos are lists too: [1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7] so store them as lists in winning combos list. Last, but not least, fill up the gameButtons list with our buttons: the order of adding is super important so be careful.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXftgA9W3uH4fUeuZYDKDv4yX1AUJv85ZXpyoRDqHRM8UIg3FQzgX48tXOn9xNDB5erHie-gLicVE_wQU4zHcHFmzuZXQNNH2uKg73MkNlHPvQ23TKjEshptmTwiXlL4XRhuNv_UCwkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">As we have made our own game buttons list, we can use <strong>any component\u2018s <\/strong>any button click event to handle game logic. We don&#8217;t need to make a separate button click event for our game buttons. But we do need to check if the button clicked in any button click event is the reset button or some other button. Some other button will mean the game button. In case you add another button when you make this game such as a back button, make sure to handle it appropriately.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXeeIBZ85VdQuGKyYKxGhLo2VAYhTLLuMwVqyKZvZBJ8WuGc4k6ZBAbcl43afOixk6oKLnOxSHFARMgSHHARy7-cdwBeuY3FRfBMfMxHmc8QqbkX6OqTOAUbxx6XO8CsdvFVFbsHYgkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If the button clicked is the reset button, we need to put all our variables back to the initial state.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXfntmrRPB4leL2tM3YMdi0DGDUiHWhmlh4ejnavyixg5SuwMftWJNGspSXpvB76PTYNqBDt42j5iqfERHmimhmCFG2m43uQqkMPdovEJcBys0jQcqAxN643F9YXvNr2kgV067iIEAkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">In the else condition is our game logic:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">But before working on that, let\u2019s make two procedures for checking for the game draw and checking for the winner.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We check for the winner by checking if our game buttons has text with the current player (X or O) at the winning combos: the 3 rows or the 3 columns or the 2 diagonals.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If yes, we will set those winning buttons background yellow. We will also set gameActive to false and update the status to the player who has won.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXd7uUSS9NrmGAwqqMUHFLNzabUy1pV5mj7njs76YX9WaKB22_oeRs6PMd4Uz1dwp9CrFC5kXrnlrW1t5IKxpojbwFfAJeXGRWsUkjdQGP3e_msk_EPgDWTEEbWWc08Rze9Z-KHtyAkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, we need a procedure to check for a draw. A game is a draw if the text on all game buttons is <strong>not <\/strong>empty (all buttons have been used). We can check by making gameActive false in the beginning and making it true only if a single button is found that has empty text (this means that at least one play position is still left). We will break out of the loop if empty slot found after making gameActive true. And in the end, we will check if gameActive is not true and if isn\u2019t, we will set status to draw (This means that not a single empty slot was found)<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXdoj9hmhO1H9vPHjlg-1yx2ALqFZXQcO3qunhx4bz7rgVSGAVkIt6JfMWAj0BOkW-N-nh_yjMickyzTUV4wDKeyyMUM0R2rN6EKBhSxPAiGuDHmM9NwkcCNhLyPv2wuVEXT5VlBPgkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\" style=\"width:682px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, let&#8217;s come back to the else condition in our any button click event.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We will first check if the game is active i.e. gameActive status variable is true and also, the game button that the user has clicked on is still empty and still needs to be filled:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2025\/01\/AD_4nXdtdK0c2qPM6oOtkGjf2asouSIkb7PJjlMIk9f7yqZBc7Tin3_YMzcwY8zU3-bVyPXaU05383MMlRDsQ2OHo7fSivyKmL83zTF9QoaLqssvaJ51cg2YKuojvILRi-5mPMTjSJ2GTgkeyXqrd4qvHDSShTNRl6hN4mLnV.png\" alt=\"\" style=\"width:750px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If the button is still playable, then we will set its text to the current player which can be either X or O. Then, we will check for the winner by calling our custom procedure. If a winner is found, the gameActive status will be set to false in that procedure. So, before checking for the game draw, check that the game is still active. If the game draw condition is not met, the game will still be active so check again that the game is still active and then change the current player and set the status label appropriately.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">And this is done. I hope you are getting used to any component block by now as we used it in our memory i.e. picture matching game too. It might look a little difficult in the beginning but once you get the hang of it, it will make our code much readable with less lines and it will be easier to change too.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">AIA project file: <a href=\"https:\/\/obsidiansoft.gumroad.com\/l\/hapqn\" target=\"_blank\" rel=\"noopener\">https:\/\/obsidiansoft.gumroad.com\/l\/hapqn<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I hope you liked this tutorial. Please consider supporting me:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/obsidiansoft.gumroad.com\/l\/cxdft\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"196\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png\" alt=\"\" class=\"wp-image-5381\" style=\"width:229px;height:auto\" srcset=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png 372w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1-300x158.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can have a look at the video tutorial here:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"Tic Tac Toe in MIT App Inventor (No Extensions) | MIT App Inventor Tic Tac Toe Game (Full Tutorial)\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/kGdcbYSvhnY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my video and share it with your friends and family. Also, subscribe to my channel and press the bell icon so that you don\u2019t miss any of the great projects that I have planned for you.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/c\/obsidiansofteducation\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/c\/obsidiansofteducation<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For links to free educational apps, have a look at the&nbsp;<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/mobile-apps\/\" target=\"_blank\" rel=\"noreferrer noopener\">educational apps page<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my Facebook page and Instagram page for more educational resources and tips.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Facebook:<\/strong>&nbsp;<strong><a href=\"https:\/\/www.facebook.com\/ObsidianSoft\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.facebook.com\/ObsidianSoft\/<\/a><\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Instagram:<\/strong>&nbsp;<a href=\"https:\/\/www.instagram.com\/obsidiansoftapps\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>https:\/\/www.instagram.com\/obsidiansoftapps\/<\/strong><\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Pinterest:<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-pinterest wp-block-embed-pinterest\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"oceanwp-oembed-wrap clr\"><iframe loading=\"lazy\" title=\"Obsidian Soft\" src=\"https:\/\/assets.pinterest.com\/ext\/embed.html?grid=obsidiansoft&#038;src=oembed\" height=\"900\" width=\"450\" frameborder=\"0\" scrolling=\"no\" ><\/iframe><\/div>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends and welcome to Obsidian Soft. Today, I will teach how to make a tic tac toe game in mit app inventor. Go to MIT App Inventor and start a new project. Name it TicTacToeGame. Design the Game Interface Make screen orientation portrait and change the title to Tic Tac Toe Drag and drop [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6075","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/comments?post=6075"}],"version-history":[{"count":3,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6075\/revisions"}],"predecessor-version":[{"id":6884,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/6075\/revisions\/6884"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=6075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}