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.
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!
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. 💙
@@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 .
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.
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.
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 ❤
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.
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').
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
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.
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?!!!
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.
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 `(*>﹏
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
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
@@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).
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.
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.
@@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!!!
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.
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.
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.
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.