Тёмный

Tic Tac Toe Game in Java - Full Tutorial with Source 

Coding with John
Подписаться 364 тыс.
Просмотров 75 тыс.
50% 1

Опубликовано:

 

26 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@CosmonautCoding
@CosmonautCoding 4 года назад
Awesome tutorial John! Thank you for sharing
@CodingWithJohn
@CodingWithJohn 4 года назад
Thank you sir!
@aniruddhkhatri9834
@aniruddhkhatri9834 3 года назад
Thanks a lot for explaining, John. Because of you I am fully able to understand Java.
@SkAbdulSajeed
@SkAbdulSajeed 10 месяцев назад
I saw this and it was very helpful to me thank you very much
@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 .
@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.
@ismaelmontenegro9600
@ismaelmontenegro9600 Год назад
You saved my friends life mate. ❤
@Rooswarden
@Rooswarden 3 года назад
Thank you from the Netherlands ❤️
@pardeepdangi292
@pardeepdangi292 2 года назад
helped me a lot , thanx for your effort for making it look simple .
@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.
@girishanker3796
@girishanker3796 2 года назад
Thanks John. Really loved it!
@richardlink7291
@richardlink7291 2 года назад
Learned a lot through this. Thanks!
@salamistu
@salamistu Год назад
I just looked at this video and I made a slot game hahaha good stuff Sir! thank you!
@CodingWithJohn
@CodingWithJohn Год назад
Nice!
@veereshchinna9934
@veereshchinna9934 3 года назад
It's really fun nd cool. ❤️ *From 🇮🇳 india*
@CodingWithJohn
@CodingWithJohn 3 года назад
Thanks, glad you enjoyed it!
@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.
@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.
@rodmenmx
@rodmenmx Год назад
Love it, thank you !!
@theBATfamiliar
@theBATfamiliar Год назад
Great video, I'm really enjoying it, thanks!
@piotrfengler7658
@piotrfengler7658 2 года назад
Thx John!
@ludovicbocquet9783
@ludovicbocquet9783 Год назад
Thank you !
@inrealife9126
@inrealife9126 10 месяцев назад
This task came to me as an internship interview question
@ismaelmontenegro9600
@ismaelmontenegro9600 Год назад
You a real one 💯
@youtuberyo7321
@youtuberyo7321 3 года назад
This guy fucks! High quality code, great coding style.
@GeM_097
@GeM_097 3 года назад
Love from India
@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
@TheGuroguro12
@TheGuroguro12 3 года назад
Thanks
@parthgupta9754
@parthgupta9754 2 года назад
thanks v sauce👍🏻
@SoftwareTestSolutions
@SoftwareTestSolutions 3 года назад
You are awesome!
@GeM_097
@GeM_097 3 года назад
Thanks sir I'm your subscriber
@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
@MariaEduarda-sx3qy
@MariaEduarda-sx3qy 3 года назад
awesome video
@Apo458
@Apo458 4 месяца назад
You can extract methods?? :0
@seanchoi4698
@seanchoi4698 3 года назад
cheers mate
@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.
@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
@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 `(*>﹏
@van1ty629
@van1ty629 7 месяцев назад
i am trying to make it on IDE netbeans and it doesnt print the board... i did EXACTLY what u did
@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.
@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
@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.
@vpenywise
@vpenywise 2 года назад
@21:24 - char... hm... "char xo" :)
@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!!!
@alexandrudescultescu9623
@alexandrudescultescu9623 Год назад
instead of hasContestantWon()... we can rename that method weHaveAWinner()...!
@veniaminarapidis8331
@veniaminarapidis8331 Год назад
tttMark
@dem1152
@dem1152 2 года назад
does anyone know how to do this using 1D array?
@anchs2501
@anchs2501 Год назад
Im just gonna comment for the algorithm.
@CodingWithJohn
@CodingWithJohn Год назад
Replying for the viewer interaction
@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.
@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.
@vageshnp6792
@vageshnp6792 5 месяцев назад
@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.
@duvindudinethmin6820
@duvindudinethmin6820 2 года назад
🖤
@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.
@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.
Далее
Wait for it 😂
00:19
Просмотров 3,4 млн
А вы знали что металл тонет?
00:32
Java tic tac toe game ⭕
30:00
Просмотров 293 тыс.
Make Video Games
44:12
Просмотров 1,3 млн
Code Tic Tac Toe in Java
33:23
Просмотров 28 тыс.
.equals() vs. == in Java - The Real Difference
8:48
Просмотров 192 тыс.
Faster than Rust and C++: the PERFECT hash table
33:52
Просмотров 596 тыс.