Tic Tac Toe Game in Java - Full Tutorial with Source

  Рет қаралды 75,605

Coding with John

Coding with John

Күн бұрын

Пікірлер: 84
@bodinian
@bodinian 3 жыл бұрын
The moment you showed me "Extract Method" as a feature of my IDE I immediately saved your video. That is EXTREMELY useful for most of my troubles coding in java.
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Awesome! I definitely remember all the simple OMG moments of learning all the great things IDEs can do - Extracting methods, auto-creating getters and setters, renaming everything. Might be a great subject for a future video. In the meantime, give it a right click and explore the menu to see what it can do for you!
@m77mo65
@m77mo65 2 жыл бұрын
I'm not a junior developer, but I don't know why I enjoy watching all your videos sir. Keep it up.
@abhishek-gu6qt
@abhishek-gu6qt Жыл бұрын
i learned many thing throughout this like most of is eclipse shortcuts! thanks!
@kxnyshk
@kxnyshk 3 жыл бұрын
Wow this was so awesome! And easy to learn. One don't need much of exposure to Java, to understand this. Also the shortcut for converting code directly into a method was pretty awesome! I wasn't aware of that. 💙
@thiagogaitkoski3562
@thiagogaitkoski3562 3 жыл бұрын
Thanks for helping with my college work. ❤️From Brazil
@aniruddhkhatri9834
@aniruddhkhatri9834 3 жыл бұрын
Thanks a lot for explaining, John. Because of you I am fully able to understand Java.
@CosmonautCoding
@CosmonautCoding 4 жыл бұрын
Awesome tutorial John! Thank you for sharing
@CodingWithJohn
@CodingWithJohn 4 жыл бұрын
Thank you sir!
@mrmichalification
@mrmichalification 3 жыл бұрын
I would like to thank You for this tutorial. It is focused to teach and show the idea. It helped me a lot. Thx.
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Thank you for the kind words! Glad it helped you out.
@mouloudguell2763
@mouloudguell2763 2 жыл бұрын
thank you for the tutorial that helps a lot with practicing .hopefully you will put more projects
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Let me know if you have ideas for any!
@mouloudguell2763
@mouloudguell2763 2 жыл бұрын
@@CodingWithJohn would it be possible please to do a tutorial on snake game that uses JFrame and JPanel ? or any more of this type of games as it really helps practicing . few youtubers actually do projects like this .
@SkAbdulSajeed
@SkAbdulSajeed 10 ай бұрын
I saw this and it was very helpful to me thank you very much
@ismaelmontenegro9600
@ismaelmontenegro9600 Жыл бұрын
You saved my friends life mate. ❤
@Rooswarden
@Rooswarden 3 жыл бұрын
Thank you from the Netherlands ❤️
@MTB_Bay_Area
@MTB_Bay_Area 2 жыл бұрын
If that game changes from 3x3 to n x n this program will have to be modified. I suggest for the testing of if user won to take the user selection say "1" and call a method to test after the placement if row 0 and col 0 are a win. You can only win after you place a value, hence, it is unnecessary to validate location where the user did not place a value. Just check the row, column and diagonal after a placement. This will allow you also to make the game for any size of a matrix. The for loop will simply run for zero to length of the matrix.
@pardeepdangi292
@pardeepdangi292 2 жыл бұрын
helped me a lot , thanx for your effort for making it look simple .
@inrealife9126
@inrealife9126 10 ай бұрын
This task came to me as an internship interview question
@prakashpatel104
@prakashpatel104 3 жыл бұрын
Thanks for sharing the very nice tutorial for Tic Tac Toe. But, I would appreciate it if you upgrade the same tutorial with more classes and objects to add the Object-Oriented Flavor. Thanks.
@salamistu
@salamistu Жыл бұрын
I just looked at this video and I made a slot game hahaha good stuff Sir! thank you!
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Nice!
@girishanker3796
@girishanker3796 2 жыл бұрын
Thanks John. Really loved it!
@richardlink7291
@richardlink7291 2 жыл бұрын
Learned a lot through this. Thanks!
@veereshchinna9934
@veereshchinna9934 3 жыл бұрын
It's really fun nd cool. ❤️ *From 🇮🇳 india*
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Thanks, glad you enjoyed it!
@piotrfengler7658
@piotrfengler7658 2 жыл бұрын
Thx John!
@ludovicbocquet9783
@ludovicbocquet9783 Жыл бұрын
Thank you !
@rodmenmx
@rodmenmx Жыл бұрын
Love it, thank you !!
@saran9161
@saran9161 Жыл бұрын
i just thought of a way to check if game ties , declare a global count variable and whenever a valid move is placed the count increments. when it hits 9 game ties. instead of checking using two nested loop i thought this will be efficient. good vid ❤
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Interesting! That could possibly work depending on how you implemented it but you'd just have to be careful to not make it more confusing. Sometimes the ninth move doesn't result in a tie, but instead has a winner. Also it requires a global variable, which although it's not a huge deal in a small program like this, we typically try to avoid them.
@ismaelmontenegro9600
@ismaelmontenegro9600 Жыл бұрын
You a real one 💯
@youtuberyo7321
@youtuberyo7321 3 жыл бұрын
This guy fucks! High quality code, great coding style.
@JLSXMK8
@JLSXMK8 3 жыл бұрын
char 'symbol', huh? I agree. You might have also named it a "playerIndicator", hence it indicates whether the current player is the computer ('o') or the user ('x').
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
True - there are always tons of ways you could do it, and the way I have it is certainly not the only way.
@GeM_097
@GeM_097 3 жыл бұрын
Love from India
@TheGuroguro12
@TheGuroguro12 3 жыл бұрын
Thanks
@SoftwareTestSolutions
@SoftwareTestSolutions 3 жыл бұрын
You are awesome!
@parthgupta9754
@parthgupta9754 2 жыл бұрын
thanks v sauce👍🏻
@theBATfamiliar
@theBATfamiliar Жыл бұрын
Great video, I'm really enjoying it, thanks!
@GeM_097
@GeM_097 3 жыл бұрын
Thanks sir I'm your subscriber
@rebhuroy3713
@rebhuroy3713 2 жыл бұрын
Hey your video was really helpful.. now I tried to implement a minimax algorithm on this tic tac toe version but unable to do that. Can you please help me work on that
@MariaEduarda-sx3qy
@MariaEduarda-sx3qy 3 жыл бұрын
awesome video
@seanchoi4698
@seanchoi4698 3 жыл бұрын
cheers mate
@Apo458
@Apo458 4 ай бұрын
You can extract methods?? :0
@KhaledRazouk
@KhaledRazouk 2 жыл бұрын
hi John thanks for the video it's really cool, but i have a question why you used the method isGameFinished and why we used a loop insid the other one
@hamsejama
@hamsejama 3 жыл бұрын
Thank you sooo much. You have a clear way of explaining. There are a lot and a lot of contents of how to something or explaining a principle but when it comes to applying that knowledge to a project, that is where you shine brighter. I am in the middle of the tutorial and i have a smile on my face as i admire your teaching style and that i finally found someone who can teach me the way i would prefer to. so a big tHaNk YoU `(*>﹏
@buckygarner1124
@buckygarner1124 2 жыл бұрын
Hello John, thank you for this video introduction to JAVA using Tic-Tac-Toe. Do you have a version of the TTT game that using object oriented programming? I would assume you could create a Square class, and create a board as an ArrayList of square objects. Just curious if you have a video or link to code for an OOP version. Thanks.
@van1ty629
@van1ty629 8 ай бұрын
i am trying to make it on IDE netbeans and it doesnt print the board... i did EXACTLY what u did
@mike85_pl
@mike85_pl Жыл бұрын
i have problem. when i type 6 nothing happens but when i type 9 it selects both 6 and 9. anyone know why? i have the same code
@jimg1928
@jimg1928 2 жыл бұрын
Nice Video! However, can we assume that rand.nextInt(9) + 1 will produce all values between 1 and 9? In particular, let's say that position 5 is the only position left open on the board and that it is the computers turn. How do we know that rand.nextInt(9) + 1 will "ever" produce the number 5 to finish the game?!!!
@rihasanatrofolo2472
@rihasanatrofolo2472 2 жыл бұрын
Nothing with computers is truly "random". There are certain tricks we use to make things look random. The chance of it never hitting 5 is pretty much zero when the interval is so small. Look into "true random" if you're interested, which is based on real time weather.
@MsLetishia
@MsLetishia 2 жыл бұрын
The while statement filters the computer's play. So the computer only makes valid moves
@dem1152
@dem1152 2 жыл бұрын
does anyone know how to do this using 1D array?
@sayliya
@sayliya 3 жыл бұрын
This really helped me but I do ask that you don't do the shortcut keys for the software you are using because it made it harder to follow along since I use JGrasp for my coding and I am new.
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Thanks for the feedback! There will be some times I use them and some times that I don't. If I don't use them, I always get comments like, "you know, you can just use 'sysout' to get System.out.println()". And I know many beginners like seeing shortcuts since they may never learn they exist if they don't see people using them. But I also understand not everyone uses Eclipse.
@anchs2501
@anchs2501 Жыл бұрын
Im just gonna comment for the algorithm.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Replying for the viewer interaction
@richardmeyer418
@richardmeyer418 2 жыл бұрын
Thank you for this. I know it's many months later, but those switch statements are really ugly. I, personally would make the input into an integer (if it wasn't already) - check if it's 1
@beyond_akshii
@beyond_akshii 2 жыл бұрын
you did a nice try over here but your method wouldnt work to let find out the correct row, for eg the user gave 5 as input, for extracting the row number if i follow your method i would subtract 1 from it resulting in 5-1=4 , and as u wrote int row = input/3; and input is also integer hence integer division would be done here, 4/3 , which would result in 1 which isnt my correct row number
@richardmeyer418
@richardmeyer418 2 жыл бұрын
@@beyond_akshii - I'm afraid that it IS the correct row number (and column number for that matter). Remember you start counting from 0 - therefore the first row is row 0 and the second row (where the 5 is), is row 1. Similarly for the columns (4%3) gives a 1 - which is the second column (remember we start at 0).
@beyond_akshii
@beyond_akshii 2 жыл бұрын
@@richardmeyer418 oh dang forgot about that....thanks!
@richardmeyer418
@richardmeyer418 2 жыл бұрын
@@beyond_akshii It happens. We all have occasional blind spots.
@vpenywise
@vpenywise 2 жыл бұрын
@21:24 - char... hm... "char xo" :)
@alexandrudescultescu9623
@alexandrudescultescu9623 Жыл бұрын
instead of hasContestantWon()... we can rename that method weHaveAWinner()...!
@veniaminarapidis8331
@veniaminarapidis8331 Жыл бұрын
tttMark
@vageshnp6792
@vageshnp6792 6 ай бұрын
@SeanHP
@SeanHP 3 жыл бұрын
Fact: The first program Bill Gates made was a tic tac toe game
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Ah, we're so alike, Bill Gates and I.
@usebrain2897
@usebrain2897 2 жыл бұрын
Anyone has the same problem as me? The "X" doesnt apper after writing a number 1-9....... Did legit everything the same and checked it 5 times.
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
If you're comfortable posting your code, I or someone else on here can check it out!
@usebrain2897
@usebrain2897 2 жыл бұрын
@@CodingWithJohn ahhh found the problem :D I wrote: "int input = new scanner.nextInt" and then in the switch I wrote: case '1'... Instead of just case 1 🤦‍♂️ These simple mistakes are killing me sometimes. Thanks for the reach out though!!!
@duvindudinethmin6820
@duvindudinethmin6820 2 жыл бұрын
🖤
@tallswede80
@tallswede80 Жыл бұрын
using all those logical statements in the if structure is poor style. you are supposed to use boolean variables to make the if statements more readable.
@sanjayraju8828
@sanjayraju8828 3 жыл бұрын
I am really struggling with making one of these with two human players I tried it and i can never get it to work.
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
Hmm, as long as you're OK with both players of course using the same computer and keyboard (and not doing some very complicated internet-based 2-player game), you can replace the computerTurn() calls with something like "player2Turn()", which can do pretty much the same thing the playerTurn() method does, just putting in the opposite symbol. Then just change the outputs for who wins ("You Win" might change to "player 1 wins", etc), and it should be a functioning game with two human players. If I have some time I'll try and get some functioning code up for that.
@sanjayraju8828
@sanjayraju8828 3 жыл бұрын
@@CodingWithJohn Thank you very much.
@stevemiller7050
@stevemiller7050 Жыл бұрын
I like the tone and voice. but I don't like all the changes during the tutorial. in the end its a waste of time and seems pretty messed up. would be better to prepare yourself better and then run the tutorial without all the changes in method names etc.
@med_abdelghafour
@med_abdelghafour Жыл бұрын
chikor dnya ylfortas
@inchworm9311
@inchworm9311 2 жыл бұрын
For the computerPlay could we do: int computerPlay = rand.nextInt(10);
@rihasanatrofolo2472
@rihasanatrofolo2472 2 жыл бұрын
Yes you could definitely do that, but you'd have the issue with it choosing 0 sometimes, just adding unnecessary steps to the program, since 0 isn't a valid answer. The range is from 0 to your selected number. With the + 1, you won't have this problem.
Create a Sudoku Solver In Java In 20 Minutes - Full Tutorial
20:25
Coding with John
Рет қаралды 324 М.
Minimax Algorithm for Tic Tac Toe (Coding Challenge 154)
26:33
The Coding Train
Рет қаралды 816 М.
Wait… Maxim, did you just eat 8 BURGERS?!🍔😳| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 9 МЛН
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 24 МЛН
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
Quicksort Sort Algorithm in Java - Full Tutorial With Source
24:58
Coding with John
Рет қаралды 249 М.
Code Tic Tac Toe in Java
33:23
Kenny Yip Coding
Рет қаралды 30 М.
C Tic Tac Toe game ⭕
20:08
Bro Code
Рет қаралды 169 М.
Java tic tac toe game ⭕
30:00
Bro Code
Рет қаралды 294 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 229 М.
Python TIC TAC TOE Tutorial | Beginner Friendly Tutorial
25:15
Code Coach
Рет қаралды 204 М.