Tic Tac Toe Java Game - Build a Tic Tac Toe Game in 30 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024

ความคิดเห็น • 762

  • @alexlorenlee
    @alexlorenlee  11 หลายเดือนก่อน +8

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

    • @SwiperANASS
      @SwiperANASS 8 หลายเดือนก่อน

      drive.google.com/drive/folders/1PwkFRjycQ0H2duh0iOZ52W-GxTHcbmmO?usp=sharing

  • @chrysilius0
    @chrysilius0 4 ปีที่แล้ว +1089

    ARE YOU SERIOUS DUDE!??
    HOWWW
    I LITERALLY GOT MY ASSIGNMENT OF MAKING TIC TAC TOE YESTERDAY AND I NEEDED HELP AND GUESSS WHAT....
    YOU JUST MADE A WHOLE VIDEO ABOUT ITTTTT!!!
    THANK YOUUUUU

    • @onlyios9077
      @onlyios9077 4 ปีที่แล้ว +8

      what year are you in?

    • @chrysilius0
      @chrysilius0 4 ปีที่แล้ว +31

      @@onlyios9077 2008
      Why?

    • @onlyios9077
      @onlyios9077 4 ปีที่แล้ว +6

      @@chrysilius0 I'm In CS and never got such an assignement

    • @chrysilius0
      @chrysilius0 4 ปีที่แล้ว +5

      @@onlyios9077 I'm actually doing java course

    • @usernameundefined123
      @usernameundefined123 4 ปีที่แล้ว +35

      He did it after I submitted mine 😭😭

  • @angelsdemons8520
    @angelsdemons8520 4 ปีที่แล้ว +403

    notice how he is making mistakes in middle and correcting them ,makes me realize that making little
    mistakes while programming is so common and normal ... it's as if he is talking to us while programming unlike some programmers
    who r like - " so we r gonna do this and that and tadda" , really makes me feel kinda dumb bcoz when
    I try to program I really do lots of small mistakes like Alex ... really very nice video .. enjoyed it ..

    • @coolfred9083
      @coolfred9083 3 ปีที่แล้ว +2

      Yeah I think small mistakes are very common

    • @Maks-wp2wj
      @Maks-wp2wj 3 ปีที่แล้ว +2

      Don't worry about making mistakes. If people didn't do them, what would be the usage of Stackoverflow then? There is a challange for doing 100 lines of code without any mistake, pretty hard tho.

    • @cacoca79
      @cacoca79 3 ปีที่แล้ว

      hes not telling you we here to go to make the game

    • @ptcreborntm
      @ptcreborntm 3 ปีที่แล้ว +1

      th-cam.com/video/eeIbIJR0HqQ/w-d-xo.html

    • @alexbaltimore
      @alexbaltimore 2 ปีที่แล้ว

      Agile development best route! Make mistakes, debug, get feedback, and build a better application

  • @mynameiscorenhel
    @mynameiscorenhel 4 ปีที่แล้ว +5

    Code after fixing some bugs:-
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.Random;
    import java.util.Scanner;
    public class TicTacToe {
    static ArrayList playerPositions = new ArrayList();
    static ArrayList cpuPositions = new ArrayList();
    public static void main(String[] args) {
    char[][] gameBoard = { { ' ', '|', ' ', '|', ' ' }, { '-', '+', '-', '+', '-' }, { ' ', '|', ' ', '|', ' ' },
    { '-', '+', '-', '+', '-' }, { ' ', '|', ' ', '|', ' ' }, };
    printGameBoard(gameBoard);
    while (true) {
    //**********************PLAYER*****************************************
    Scanner input = new Scanner(System.in);
    System.out.println("Enter your position from 1-9 :");
    int playerPos = input.nextInt();// Entering your position
    while (playerPositions.contains(playerPos) || cpuPositions.contains(playerPos)) {
    System.out.println("this place has been taken please Enter different position :");
    playerPos = input.nextInt(); // Rentering your position
    }
    playerPositions.add(playerPos);
    placePiece(gameBoard, playerPos, "player"); // send your position to put
    printGameBoard(gameBoard); // print Board after your position
    System.out.println();
    String result = checkWinner();
    if (result.length() > 0) {
    System.out.println(result);
    playerPositions.clear();
    cpuPositions.clear();
    resetGameBoard(gameBoard);
    printGameBoard(gameBoard);
    continue;
    }
    //**********************CPU********************************************
    Random rand = new Random();
    int cpuPos = rand.nextInt(9) + 1;
    while (playerPositions.contains(cpuPos) || cpuPositions.contains(cpuPos)) {
    cpuPos = rand.nextInt(9) + 1; // Rentering cpu position
    }
    cpuPositions.add(cpuPos);
    placePiece(gameBoard, cpuPos, "cpu");// Entering cpu position
    printGameBoard(gameBoard);
    System.out.println();
    result = checkWinner();
    if (result.length() > 0) {
    System.out.println(result);
    cpuPositions.clear();
    playerPositions.clear();
    resetGameBoard(gameBoard);
    printGameBoard(gameBoard);
    continue;
    }
    }
    }
    public static void printGameBoard(char[][] GBoard) {
    for (char[] G : GBoard) {
    for (char M : G)
    System.out.print(M);
    System.out.println();
    }
    }
    public static void resetGameBoard(char[][] gameBo) {
    char Symbol = ' ';
    gameBo[0][0] = Symbol;
    gameBo[0][2] = Symbol;
    gameBo[0][4] = Symbol;
    gameBo[2][0] = Symbol;
    gameBo[2][2] = Symbol;
    gameBo[2][4] = Symbol;
    gameBo[4][0] = Symbol;
    gameBo[4][2] = Symbol;
    gameBo[4][4] = Symbol;
    }
    public static void placePiece(char[][] Gboard, int ps, String pl) {
    char Symbol = ' ';
    if (pl.equals("player"))
    Symbol = 'X';
    else if (pl.equals("cpu"))
    Symbol = '0';
    switch (ps) {
    case 1:
    Gboard[0][0] = Symbol;
    break;
    case 2:
    Gboard[0][2] = Symbol;
    break;
    case 3:
    Gboard[0][4] = Symbol;
    break;
    case 4:
    Gboard[2][0] = Symbol;
    break;
    case 5:
    Gboard[2][2] = Symbol;
    break;
    case 6:
    Gboard[2][4] = Symbol;
    break;
    case 7:
    Gboard[4][0] = Symbol;
    break;
    case 8:
    Gboard[4][2] = Symbol;
    break;
    case 9:
    Gboard[4][4] = Symbol;
    break;
    default:
    break;
    }
    }
    public static String checkWinner() {
    List frstrow = Arrays.asList(1, 2, 3);
    List scndrow = Arrays.asList(4, 5, 6);
    List thrdrow = Arrays.asList(7, 8, 9);
    List frstclm = Arrays.asList(1, 4, 7);
    List scndclm = Arrays.asList(2, 5, 8);
    List thrdclm = Arrays.asList(3, 6, 9);
    List frstcross = Arrays.asList(1, 5, 9);
    List scndcross = Arrays.asList(3, 5, 7);
    List winning = new ArrayList();
    winning.add(frstrow);// 1
    winning.add(scndrow);// 2
    winning.add(thrdrow);// 3
    winning.add(frstclm);// 4
    winning.add(scndclm);// 5
    winning.add(thrdclm);// 6
    winning.add(frstcross);// 7
    winning.add(scndcross);// 8
    int i = 1;
    for (List l : winning) {
    if (playerPositions.containsAll(l))
    return "Congratulation you Won!";
    }
    for (List l : winning) {
    if (cpuPositions.containsAll(l))
    return "Sorry you lost this time :(";
    }
    for (List l : winning) {
    if (!(playerPositions.containsAll(l)) && !(cpuPositions.containsAll(l))
    && playerPositions.size() + cpuPositions.size() == 9)
    return "CAT!";
    }
    return "";
    }
    }

    • @ihauqpilitinmoq
      @ihauqpilitinmoq ปีที่แล้ว

      hello, i tried this code but there's an error in
      && playerPositions.size()+
      cpuPositions.size() == 9)
      it says "illegal start of expression"
      can you help me plsss

    • @ihauqpilitinmoq
      @ihauqpilitinmoq ปีที่แล้ว

      pls help me this is my exam in programming 2

  • @RajSingh-yj7zj
    @RajSingh-yj7zj 4 ปีที่แล้ว +360

    I've got to say when I started learning Java certain things I found really tough but your channel help strengthen the areas I was weak and also gave me more passion to learn how to code. Thanks for all the lessons.

    • @supptk
      @supptk 4 ปีที่แล้ว

      @Idk I just want to comment Riley And I left it at 69.😁

    • @RajSingh-yj7zj
      @RajSingh-yj7zj 4 ปีที่แล้ว

      Riley you have done the world a great service

  • @shatha-u6q
    @shatha-u6q 3 ปีที่แล้ว +221

    the fact that I spent 1HOUR in the first 6 minutes is absolutely mad

    • @Anila-te4fe
      @Anila-te4fe 3 ปีที่แล้ว +25

      Trust the process :)

    • @kevinthegamedev9049
      @kevinthegamedev9049 3 ปีที่แล้ว +8

      I had the same frustrating issue too. :(

    • @vivansheth1902
      @vivansheth1902 3 ปีที่แล้ว +1

      same bro

    • @tobber5582
      @tobber5582 3 ปีที่แล้ว +1

      3 hours

    • @vivansheth1902
      @vivansheth1902 3 ปีที่แล้ว +3

      and after four hours my jdk was just a peice of shit cuz it showed 128 errors then i. decreased them to 0 and still they showed there's a syntax error and. when we check there were no red lines like it showed there was an error but at the same time showed there were none

  • @Jechew
    @Jechew 4 ปีที่แล้ว +87

    5:03 Cool, cool, cool. Save and run. And it still works.
    I felt that

    • @BeiggoMC
      @BeiggoMC 4 ปีที่แล้ว +2

      Lol

  • @susmitapatro3082
    @susmitapatro3082 3 ปีที่แล้ว +33

    Great explanation!! 🙌
    Don't get disheartened if it takes more than 30 mins to learn . I'm a beginner. TBH it took me 6 hours and I'm proud of myself because this is my first mini project /game and i could totally understand and do it on my own .😇

  • @anlunjiang
    @anlunjiang 4 ปีที่แล้ว +274

    Hi just pointing out a small bug: If you place a winning piece as the last move - it will still register as a Tie, since you put the last "else if" in the for loop on line 118. Put this check as a separate if statement outside the for loop and it solves it. Great video thanks for sharing

    • @peterszarvas94
      @peterszarvas94 4 ปีที่แล้ว +7

      Thanks, I was also thinking how to solve this bug, but you answered.

    • @praneetkarna8498
      @praneetkarna8498 4 ปีที่แล้ว +14

      Can you please explain why this bug comes up. Because before checkWinner() we do the putPiece() function which should automatically add the last position in our list of player positions. After that, the first if condition which prints "congrats" should be satisfied. Please explain where I am going wrong with this logic.
      Edit : I got why the bug appears. In the if condition, we go through all the possible winning arrangements inside the winning list. Therefore, if the last position is not part of the top row, then the tie condition will be satisfied before the win condition and "Tie" will be returned, breaking out of the checkWinner() method.

    • @Asdf-wm4ow
      @Asdf-wm4ow 4 ปีที่แล้ว +3

      @@praneetkarna8498 Thank you for the edit now I understand also

    • @lamellama7450
      @lamellama7450 4 ปีที่แล้ว +3

      Thx man I'm a newbie to the game creation part of java I just do like easy stuff for like to find the hypotenuse length or like trigonometry. This thing really triggered me when the winning piece was the last, but thx for ur fix, I can now proudly say my first successful game created was TiC tAc ToE

    • @سميححمدان-س1ق
      @سميححمدان-س1ق 3 ปีที่แล้ว

      Thanks a lot.. 😊

  • @romitmohane4891
    @romitmohane4891 4 ปีที่แล้ว +66

    That helped me build tictactoe in PYTHON XD

    • @martingogaming1777
      @martingogaming1777 3 ปีที่แล้ว +2

      How to program tic tac toe in script languages LOL

    • @nanonssmile
      @nanonssmile 3 ปีที่แล้ว +1

      Can you share your python code? I'm really struggling...😰

    • @antwarior
      @antwarior 3 ปีที่แล้ว +1

      @@nanonssmile have you gotten everything under control?

    • @nanonssmile
      @nanonssmile 3 ปีที่แล้ว

      @@antwarior I really tried, many times... but then I gave up😅

    • @antwarior
      @antwarior 3 ปีที่แล้ว +1

      @@nanonssmile bro don't give up lol, just stick with it, I'll tell you something i did, i had started playing this game called kerbal space program then i found out theres a programing language just for the game exclusively and once i downloaded it, (its called kos ksp)
      i learned how to fly my rockets autonomously and then thats when it hit me lol, programming has become so much easier to understand now that I've learned that kerbal space programing language and could see the result of my code in real time with the rocket, once i achieved orbit with no help and just me coding out my own code after learning kos,
      I've been back into programming ever since and everything looks way different than it did before, because i understand now whats going on, so don't give up bro, find alternative ways to learn coding just like i did and i promise you, you will be thankful you did,
      btw java is so easy, its pretty much the easiest language to learn and you'll see why once you learn how to code, you'll see how java is so much more easier than people make it out to be, trust me easiest language to learn by far and i highly recommend you stick with java

  • @westonpotgieter8131
    @westonpotgieter8131 4 ปีที่แล้ว +47

    More short games please.

  • @tabrezshaikh7705
    @tabrezshaikh7705 4 ปีที่แล้ว +38

    HANDS DOWN
    SIMPLEST TIC TAC TOE PROGRAM + EXPLANATION.
    good work bruhh

    • @christianjmyhre
      @christianjmyhre 3 ปีที่แล้ว

      I wish I could see this in c++ but this was great!

  • @dougie119
    @dougie119 4 ปีที่แล้ว +13

    line 26 of your code should be playerPos not playerPositions. I was confused for a while because I was able to take the CPU positions in game. This was good for troubleshooting though!

  • @joeyphilipp4690
    @joeyphilipp4690 4 ปีที่แล้ว +15

    Shouldn't the second while loop in main be like this? Just incase user selects a position where the cpu has already gone.
    while(playerPositions.contains(playerPos) || cpuPositions.contains(playerPos)){
    System.out.println("Position taken! Enter a correct Position");
    playerPos= scan.nextInt();
    }

    • @lamellama7450
      @lamellama7450 4 ปีที่แล้ว

      Yea I figured it out myself

    • @castles990
      @castles990 4 ปีที่แล้ว

      Thats what i thought

    • @anonymousone1468
      @anonymousone1468 3 ปีที่แล้ว

      Thank you for this comment. I was confused about how I should have rewritten this part.

  • @abhinavkrothapalli3224
    @abhinavkrothapalli3224 4 ปีที่แล้ว +16

    Thanks a lot man! I appreciate this a lot, very helpful. :)

  • @YTKP21
    @YTKP21 3 ปีที่แล้ว +4

    Who knew that the game tic tac tow would be this hard lol. I just started coding juts like a month ago and beggining to undertsand arrays. Ur videos help out a ton! This video happened to be in my recommended so I clicked it. Amazing video!!! Keep up the good work! 👍

  • @BlazerBoy1337
    @BlazerBoy1337 6 หลายเดือนก่อน +2

    Kinda followed until about halfway through and then did this on my own. And then I modified it with the lists you added. Really cool tutorial, very easy to follow and understand!

  • @catombomb3003
    @catombomb3003 ปีที่แล้ว +9

    I liked the way you took care of overlapping moves. I was trying to code on my own whenever I could and then check how you did it. The way I did it worked too, but made the code quite lengthy and a bit repetitive. It was a good experience to learn how to code more efficiently!

  • @amgnico
    @amgnico 4 ปีที่แล้ว +8

    I did my first tictactoe today, but it's X vs O without CPU

  • @Nekyox_
    @Nekyox_ 4 ปีที่แล้ว +22

    Arf, you should use % and / to set the symbol instead of your switch
    gameBoard[2 * ((pos - 1) / 3)][2 * ((pos - 1) % 3)]

    • @Luca-hn2ml
      @Luca-hn2ml 4 ปีที่แล้ว +6

      Yea and there are other efficiency flaws in his code.
      For example the winning checks and the while loop for the cpu can be improved

    • @chriscarlisle8997
      @chriscarlisle8997 4 ปีที่แล้ว

      Dude that's ingenious!

  • @DaCom3AK
    @DaCom3AK 4 ปีที่แล้ว +5

    I get an error
    java: '(' expected
    for line public static void String checkWinner() {. Why is this happening?

    • @DaCom3AK
      @DaCom3AK 4 ปีที่แล้ว +3

      Nvm I got it I was using void while returning an empty string

  • @JewelFornillas
    @JewelFornillas 3 ปีที่แล้ว +6

    Im learning java here and this is my first project :)

  • @zachm4389
    @zachm4389 4 ปีที่แล้ว +3

    Someone made tic tac toe in Brianfuck

    • @Luca-hn2ml
      @Luca-hn2ml 4 ปีที่แล้ว +1

      thats the stuff i like

  • @didghkwls
    @didghkwls 4 ปีที่แล้ว +8

    This is awesome. I'm a very beginner of Java and I hope that I could make it like you do in the future. I know I have to practice over and over again! Thank you 😉

    • @asikurrahman4354
      @asikurrahman4354 4 ปีที่แล้ว +2

      You taking Computer science in college ? Its easy during the first few lessons lol and then it gets I harder and I get lost.

  • @carlosmurcia9379
    @carlosmurcia9379 4 ปีที่แล้ว +9

    I love your teaching style! Really easy to understand and make seem less scary to code in Java!

  • @Conducttor
    @Conducttor ปีที่แล้ว +1

    As of Java 13, you can use much better looking and shorter, "enhanced" switch statements:
    switch (position) {
    case 1 -> board[0][0] = symbol;
    case 2 -> board[0][2] = symbol;
    case 3 -> board[0][4] = symbol;
    case 4 -> board[2][0] = symbol;
    case 5 -> board[2][2] = symbol;
    case 6 -> board[2][4] = symbol;
    case 7 -> board[4][0] = symbol;
    case 8 -> board[4][2] = symbol;
    case 9 -> board[4][4] = symbol;
    default -> {}
    }
    Mind the missing semi-colon after "default -> {}", it's mandatory.

  • @joca1378
    @joca1378 3 ปีที่แล้ว +1

    Tic Tac Toe is funny because it doesn't make any sense and still exists as a "game". It always ends up in a draw, unless you deliberately "try" to lose (it's a simple proven fact).
    You can easily make an AI to never lose with just a few IF logic.

  • @pythondoesstuff2969
    @pythondoesstuff2969 4 ปีที่แล้ว +1

    Wow I wrote my second java project with this.......
    Thanks.
    First was obviously hello world

  • @nithinputchakayala9032
    @nithinputchakayala9032 4 ปีที่แล้ว +6

    Dude thank you very much. Literally got the same project. Thank you very much!!!!

  • @dannyluna3097
    @dannyluna3097 ปีที่แล้ว +1

    I used almost none of this but this inspired me to use what I needed too💀💀💀 let’s just say I used way to me if loops😭 (I really don’t mind because copy and paste is a king!!!)

  • @mindofpaul9543
    @mindofpaul9543 2 ปีที่แล้ว +2

    That cut at 21:03 made me think there was some magical hotkey combination I was missing to fill in all that info lol. I had to watch back a few times to realize it was just the magic of editing.

  • @day35ofdebuggingthesamelin56
    @day35ofdebuggingthesamelin56 4 ปีที่แล้ว +10

    I started to watch your java tutorial videos and now I have watched like 15 of them and ended up here. You are great at explaining things. Thanks!

  • @amberrose46
    @amberrose46 4 ปีที่แล้ว +1

    So I'm following along with this, but for List topRow and all the others, it gives me an error saying "Type mismatch: cannot convert from List to List" did I do something wrong here?

  • @frenzygamer907
    @frenzygamer907 4 ปีที่แล้ว +1

    is there really not a better way to check all the cases? so much code to do that... i have a similar program and did the same thing but its stressing me out because its so many “if” statements and im worried to put it on my resume in case its bad coding

  • @sumanroy369
    @sumanroy369 4 ปีที่แล้ว +10

    There's an error showing "cannot find symbol-variable c" even though i have imported all the classes given in ur code.
    Ps: I use Bluej.Please helpp!!

    • @yanqingjing5800
      @yanqingjing5800 3 ปีที่แล้ว +1

      You might forgot declare the c variable

    • @Sk8erMorris
      @Sk8erMorris 3 ปีที่แล้ว +5

      switch to IntelliJ IDEA ! Best for Java and is free.. also most popular and professional Java IDE

    • @aryantaywade298
      @aryantaywade298 3 ปีที่แล้ว

      Lmao bluej has nothing to do with it u might have just forgotten to initiatialize c

  • @mdshahnawaz5949
    @mdshahnawaz5949 4 ปีที่แล้ว +4

    What if i am winning the game in my last move. The condition (playerPosition.size() +cpuPosition.size() == 9) is always true.... How to solve this ??

  • @prawnydagrate
    @prawnydagrate 4 ปีที่แล้ว +3

    I'm wanting to learn Java for Android app development, and your videos are kinda helpful for me. Thanks!

  • @lakshayanand8061
    @lakshayanand8061 4 ปีที่แล้ว +1

    can you please provide the source code?

  • @MisterWealth
    @MisterWealth 4 ปีที่แล้ว +8

    This tutorial is what the gang needs! Wahooooo

  • @spidy6120
    @spidy6120 3 ปีที่แล้ว +3

    After watching, oomgg i think i need to practise a lot to put all the func together without error.

  • @justionut7826
    @justionut7826 4 ปีที่แล้ว +1

    I guess you ar enot ussing OOP stuff ?:)))

  • @adnanazad6618
    @adnanazad6618 4 ปีที่แล้ว +1

    how come mine comes out in a straight line the gameboard ?

    • @blumpkin69ish
      @blumpkin69ish 4 ปีที่แล้ว

      just a guess, System.out.println with a new line char added, versus System.out.print() with no new line added

  • @JaketheSnakeh64
    @JaketheSnakeh64 4 ปีที่แล้ว +28

    Awesome tutorial! I went through all of it with you. Please post more!
    From a teaching standpoint, I suggest placing stops in your videos. Good spots would be after you describe what the next step is. (Like: Prior to making a method, give the name of the method and pause for followers to develop their own pseudo code.)
    This involves users, allows you to get ideas from users, and makes this more of a teaching session. Best part is you can add these breaks in post.

  • @yaraa468
    @yaraa468 4 ปีที่แล้ว +3

    Can we make a GUI on this code together ? please its will help us alot thanks

  • @RealLava
    @RealLava 4 ปีที่แล้ว +3

    10:00... that momentttttttttttttttttt

  • @liamvena9031
    @liamvena9031 3 ปีที่แล้ว +1

    it says 'Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    at TicTacToe/tictactoepack.TicTacToe.main(TicTacToe.java:4)
    ' every time i try to run it, any ideas?

  • @yuruji2189
    @yuruji2189 4 ปีที่แล้ว +22

    I needed this so much. Thanks!

  • @sovoius
    @sovoius 2 ปีที่แล้ว +1

    how could i make it to where it prints the game board before the end result?

  • @forsabarça
    @forsabarça 4 ปีที่แล้ว +1

    import java.util.*;
    This imports all classes that belong to the java.util.

    • @ariton2990
      @ariton2990 4 ปีที่แล้ว

      That could cause class interferences.

  • @rondark9630
    @rondark9630 2 ปีที่แล้ว +1

    Can you copy paste the code in the comments please ?

  • @samaibrahim3652
    @samaibrahim3652 ปีที่แล้ว +1

    gedraag je typ normaal bro walking ick ://

  • @kiexen4991
    @kiexen4991 3 ปีที่แล้ว +1

    Where do I start adding stuff if its player to player?

  • @TMTallround
    @TMTallround 4 ปีที่แล้ว +4

    love your videos man, i was wondering. will you ever make a junit video?

  • @SDILUYNTsiu39fnd
    @SDILUYNTsiu39fnd 2 ปีที่แล้ว +1

    I think you've could've made a nested for loop to iterate through the x and y indexes of the 2d array, instead of using a switch

  • @kleynotnilu2713
    @kleynotnilu2713 4 ปีที่แล้ว +7

    keep the good work :)

  • @theprobro-7892
    @theprobro-7892 4 ปีที่แล้ว +6

    I made it in C with different logic and I think that was better than this so any body want that you can contact me

    • @rohitraina5059
      @rohitraina5059 4 ปีที่แล้ว

      Yeaa please give me the code

  • @jaygmz7907
    @jaygmz7907 4 ปีที่แล้ว +3

    It didn’t work do you mind at the end just showing all the code so people know where they went wrong
    Edit: My Pieces Aren’t Placing!

    • @jonbarto9146
      @jonbarto9146 4 ปีที่แล้ว +1

      Same here

    • @hyperbeast4631
      @hyperbeast4631 4 ปีที่แล้ว

      I too got the same problem. And I figured it out myself.
      So what you have to do is that, after moving the switch case to new method, you have to call the printGameBoard(gameBoard) method out of the switch case method placePiece(). This worked for me. But I think he didn't say that when moved the switch to new method.

  • @goldendigitals2967
    @goldendigitals2967 2 ปีที่แล้ว +1

    You should create a website to upload the source code

  • @biophilic23
    @biophilic23 3 ปีที่แล้ว +4

    i have no words to describe how grateful i'm after watching your java tutorials. YOU ARE AWESOME

  • @Geggaharry
    @Geggaharry 3 ปีที่แล้ว +1

    Please help me i will typing else if (cpupositions. ) but size is not showing. In eclipse IDE 2020 09

  • @kwsa6604
    @kwsa6604 3 ปีที่แล้ว +1

    but the playerposition we dident initialize it?

  • @NetITGeeks
    @NetITGeeks 3 ปีที่แล้ว +1

    Thank you for helping me pass my Java class Alex and I love your intro song Kazura - My Way.

  • @aarjuchoudhary03
    @aarjuchoudhary03 ปีที่แล้ว +1

    I spent 2:30 hours but it's awesome 👍

  • @Khyrid
    @Khyrid 3 ปีที่แล้ว +1

    My Eclipse console puts all of the characters in one vertical line and doesn't show the cool board like yours does at 4:20
    EDIT: I missed using print instead of println for that loop.

  • @mikemikel654
    @mikemikel654 4 ปีที่แล้ว +1

    25:35 isn't it supposed to be playerPos inside of the parameters? If you do
    cpuPosition.contain(playerPosition) won't it check if the user has eneterd a cpu value to late? Since you added the value to the list later in the program. This would only prevent a user from picking a cpu's position a second time or am I wrong?

  • @sean3589
    @sean3589 4 ปีที่แล้ว +3

    Great Video! I was wondering could you cover GUI too?

  • @marcusallen2485
    @marcusallen2485 3 ปีที่แล้ว +1

    suggestion.... change the white places on the origional gameBoard to the corresponding numbers to know where you are playing

  • @julienl.1080
    @julienl.1080 3 ปีที่แล้ว +6

    Next (big) step : the same game with TDD + SOLID principles + clean code + java 8 lambdas (using predicates) + thinking OOP instead of procedural + writing it in a clean architecture to isolate the domain from the infrastructure.
    The goal is to have code that is sufficiently readable, flexible, maintainable and protected by tests so that it does not have to be completely rewritten every time an evolution is needed.
    Rewrite completely a tic tac toe game is not problematic, but rewrite a big and expensive application is.
    Don't write legacy code ☺️

  • @LisaMcGraw201
    @LisaMcGraw201 2 ปีที่แล้ว +2

    Great Videos, I love your channel. It would be great if you could make the TicTacToe game using graphics, awt, swing. It would be a great lesson on extending and using canvas. Thanks again.

  • @ArtificialIntel422
    @ArtificialIntel422 4 ปีที่แล้ว +5

    This is so cool....!!!

  • @areeshamalik8190
    @areeshamalik8190 3 ปีที่แล้ว +1

    hey i have copy your whole code but its nor working can you give me source code

  • @swatishambhavi3649
    @swatishambhavi3649 4 ปีที่แล้ว +3

    Please make more such videos. You explain everything so nicely.

  • @croczgamings2828
    @croczgamings2828 4 ปีที่แล้ว

    I used to suck in java now you are the almighty overlord in teaching lol
    Please like this comment i did your login and simple GUI tutorial video. My parents are proud

  • @gliterman
    @gliterman 4 ปีที่แล้ว +2

    Why don't call the ítems of a simple array directly for creating the gameboard, I think you can call an item of the array to print on different lines, from what I have seen seems there's no need to make different groups into the array, thanks for your answer, great video as usual 🤓

  • @laddufn
    @laddufn 3 ปีที่แล้ว

    how do you fix Cannot invoke "String.length()" because "result" is null

  • @karembaz9533
    @karembaz9533 4 ปีที่แล้ว +3

    Love you lol❤

  • @learnit2065
    @learnit2065 4 ปีที่แล้ว +1

    Help full

  • @aishwaryamurugappan5138
    @aishwaryamurugappan5138 4 ปีที่แล้ว +1

    hey,Alex thanks a lot for this wonderful tutorial,btw could you help me something like,cpu working on some sort of strategy(logic) to win against human,like how it happens with chess,or even with human while playing TicTacToe, the desire to win,instead of keeping CPU's part as random ones,this'd make it more challenging doesn't it,,,what about...you making a tutorial for that one too,like kinda extension of this...Waiting for your response :')

  • @foxesrule9037
    @foxesrule9037 3 ปีที่แล้ว

    I tried making this and I've done almost the same thing just named stuff a bit differently and for some reason, it won't work. It was working at the start but then when we started adding more complicated things it stopped working.
    Here's my code:
    //Tic Tac Toe
    package test;
    import java.util.*;
    public class Start {
    static ArrayList playerPositions = new ArrayList();
    static ArrayList cpuPositions = new ArrayList();
    public static void main(String[] args) {
    String[][] board =
    {
    {"[ ]","[ ]","[ ]"},
    {"[ ]","[ ]","[ ]"},
    {"[ ]","[ ]","[ ]"}
    };
    printBoard(board);
    while (true)
    {
    Scanner scan = new Scanner(System.in);
    System.out.println("Choose position");
    int pos = scan.nextInt();
    while(playerPositions.contains(pos) || cpuPositions.contains(playerPositions))
    {
    System.out.println("Position taken! Enter a valid position.");
    pos = scan.nextInt();
    }
    placePiece(board,pos,"player");
    String result = winner();
    if(result.length()>0)
    {
    System.out.println(result);
    break;
    }
    Random rand = new Random();
    int cpuPos = rand.nextInt(9)+1;
    while(playerPositions.contains(cpuPos) || cpuPositions.contains(cpuPos))
    {
    cpuPos = rand.nextInt(9)+1;
    }
    placePiece(board,cpuPos,"cpu");
    printBoard(board);
    result = winner();
    if(result.length()>0)
    {
    System.out.println(result);
    break;
    }
    }
    }
    public static void printBoard(String[][] board)
    {
    for(int i=0;i < board.length; i++)
    {
    for(int k=0; k

  • @freedomlover4348
    @freedomlover4348 4 ปีที่แล้ว +2

    can someone PLEASE tell me at 21:04, how paste all the add list at one time?????

    • @aniler1517
      @aniler1517 4 ปีที่แล้ว

      He stopped recording of the video this time.

  • @furtnot3441
    @furtnot3441 3 ปีที่แล้ว +1

    Hope i don't get knocked for plagiarism for using the main bit of the code

  • @griffinbrooks6748
    @griffinbrooks6748 4 ปีที่แล้ว +1

    Can you do this using a window? Maybe wven buttons?

  • @shadmankabir7023
    @shadmankabir7023 4 ปีที่แล้ว +1

    Unrelated qts. But is Dave Lee ur brother?

    • @Robonova
      @Robonova 4 ปีที่แล้ว

      He only has 2 sisters

  • @NiffirgkcaJ
    @NiffirgkcaJ 7 หลายเดือนก่อน

    There are some bugs which I am unable to fix, but you're infinitely better than me! :D

  • @WRYtube14
    @WRYtube14 2 หลายเดือนก่อน

    Please make more java tutorials ,like making gui for this game and making it real life app or sth .Please do more tutorials ,we love u ,you are a great teacher!!

  • @priyadharshinijayakumar9664
    @priyadharshinijayakumar9664 3 ปีที่แล้ว +1

    :) Utube recommended this to me..I recommend to others. :) luv This channel..
    and one doubt >_< @22:08 why do we use contains instead of containsALL?

  • @Dannkhan23
    @Dannkhan23 4 ปีที่แล้ว +2

    Hey, thanks for this! Really easy to understand. I’d like to know what shortcut did you use in the checkWinner() method at 21:04 You typed one line of code and then the other lines until cross2 were printed automatically. Kindly share the shortcut for eclipse. Thanks!

    • @sadridiu8559
      @sadridiu8559 4 ปีที่แล้ว +6

      no short cut. he cut that part of the video doing copy past on background .

  • @souravshit9859
    @souravshit9859 4 ปีที่แล้ว

    Sir I think there is a small mistake,may be i am wrong........the code will not print the "Cat" message because u have to end the cpu loop with the logic user +cpu>=9; then break,and the same logic for printing the "Cat" .Thanks for the video.

  • @senthilkumaran5317
    @senthilkumaran5317 4 ปีที่แล้ว +2

    Line : 26 cpuPosition.contains(playerPos) - This should be the correct condition.

    • @rb76768
      @rb76768 4 ปีที่แล้ว

      Yeah Just found IT out too👍👍

    • @romain-up3ce
      @romain-up3ce 4 ปีที่แล้ว

      no his condition is correct.
      the programs checks at first the user's positions (playerPosition.contains(playerPos))
      and then he checks for the cpu's positions, with the condition (cpuPosition.contains(playerPos)).
      there is an or statement ( || ) between both, the code here is right ;)

  • @Name-pn5rf
    @Name-pn5rf 4 ปีที่แล้ว +1

    I just made my first tic tac toe!!

  • @dannyluna3097
    @dannyluna3097 ปีที่แล้ว

    As soon as you mentioned CPU I got scared💀 my project just requires human interaction, and rn I’m close … It fully plays but I need it to know when I won 😅💀

  • @tehminakakar8753
    @tehminakakar8753 3 ปีที่แล้ว +2

    OMG This was the best tutorial I've ever seen over internet. I just love the way, he make things easy for beginner like me. Thank you so much.

  • @torch4762
    @torch4762 4 ปีที่แล้ว +2

    @Alex Lee, nice video, thanks a lot for it. I learned massively, and I wish I had this 2 years

    • @Zyhru
      @Zyhru 3 ปีที่แล้ว

      How much have you learned?

    • @torch4762
      @torch4762 3 ปีที่แล้ว

      @@ZyhruAlex helped me refresh and understand basic concepts up to OOP. As far as what I've learned since I posed a year ago, well I figured out everything I needed to make my 2d multiplayer games ...the part I edited out.

  • @benjameerave4329
    @benjameerave4329 4 ปีที่แล้ว

    Hey Alex, im Benjameer and im just asking if Javascript is mostly same with Java? Sorry im bad at english

  • @upsilan_mitstrima
    @upsilan_mitstrima 4 ปีที่แล้ว

    my god, no dont make it 1,2,3
    4,5,6
    7,8,9
    make it
    7,8,9
    4,5,6
    1,2,3 like the numpad

  • @skb_369
    @skb_369 2 ปีที่แล้ว

    Hi Alex 😊 thank you so much for this video 😭 lot's of love from india

  • @gandhisFlipFlops
    @gandhisFlipFlops 23 วันที่ผ่านมา

    You should make a C++ tutorial. I like your teaching style compared to some other channels where they go over important concepts too quickly and speak too fast sometimes.

  • @TechMalaya
    @TechMalaya 3 ปีที่แล้ว

    can someone give me the source code?

  • @fishbones3650
    @fishbones3650 ปีที่แล้ว

    My first game was a text based game, my only issue is how do I pull of an if else statement by using characters of Y and N, I am always confused by it and probably have poor eyesight since idk what's making my code say stuff about missing if statement eventhough I literally just wrote the damn thing

  • @raymondjohnson825
    @raymondjohnson825 4 ปีที่แล้ว +2

    Hey thanks very much for the info, just had to do a TicTacToe assignment for my AI class, this help me find some errors in my code. But I was also hoping you would go over how to install the A.I code for the game because that's is the biggest thing I am stuck on