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

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

Alex Lee

4 года назад

746,138 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Carlos Martinez
Carlos Martinez - 27.10.2023 11:33

Hello Alex on line 26 not sure if you corrected it afterwards but on that line it's supposed to be "playerPos" when you used "playerPosition". If it's not switched, it still let's player put X's where there are some O's. Amazing step by step though. I learned a lot from it. Also you probably won't see my message but i appreciate your videos.

Ответить
7leb
7leb - 19.10.2023 14:38

creative

Ответить
Jonathan Umaña
Jonathan Umaña - 15.10.2023 00:56

very good video

Ответить
Rocky Bhujel
Rocky Bhujel - 12.10.2023 13:43

I felt betrayed when I got this type of no fun game after spending hours into coding it. But I am somewhat satisfied somewhere or I think so 😌

Ответить
Patryk Krzyżak
Patryk Krzyżak - 26.09.2023 13:48

Hi, is there any better way to check for a winner? i am writing a Tic Tac Toe game with board 10x10 and writing every possibility there is not doable i believe :)

Ответить
oliver
oliver - 13.09.2023 22:31

i did not expect you to slowly and menacingly pop up in the first few seconds lmaoo 😭 great video!!

Ответить
Kfour9Black
Kfour9Black - 02.09.2023 23:26

Epic

Ответить
darkion.02
darkion.02 - 17.07.2023 10:25

Can i get the code?

Ответить
THE_TIMELESS
THE_TIMELESS - 28.06.2023 05:42

Thankyou brother very helpful 🥰😇

Ответить
keep running!
keep running! - 11.06.2023 04:43

thanks a lot man awesome!!

Ответить
krishna177
krishna177 - 23.05.2023 20:00

i cant thank you enough you are a great teacher

Ответить
António Gonçalves
António Gonçalves - 08.05.2023 05:55

I think you should OOP. put the board as a class as well as the user which should branch to human and CPU.

Ответить
Jethalal
Jethalal - 13.04.2023 17:49

Correction:
Line 26 should be while(playerPositions.contains(playerPos) || cpuPositions.contains(playerPos))
and not while(playerPositions.contains(playerPos) || cpuPositions.contains(playerPositions)) {

Ответить
The Witch’s Bath
The Witch’s Bath - 13.04.2023 16:46

I was so confused by the row placement bc I haven't learned double arrays yet and then it all clicked lol.

Ответить
Cruccy
Cruccy - 02.04.2023 02:13

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.

Ответить
brookestephen
brookestephen - 19.02.2023 05:36

I used a magic square to number the squares, not a matrix or ordered sequence. The algorithms for offense and defense both use the "sum to 15" principle, so you can use the same code for both. Magic square numbers are ((8, 1, 6), (3, 5, 7), (4, 9, 2)). Now you can write the program in 15 minutes! The opposite corner and side squares are "sum to 10". It's really simple.
Yes, I did it in Javascript, not Java lol.

<body>
<table>
<tr><td id=2 onclick="move(2)">2</td><td id=7 onclick="move(7)">7</td><td id=6 onclick="move(6)">6</td)</tr>
<tr><td id=9 onclick="move(9)">9</td><td id=5 onclick="move(5)">5</td><td id=1 onclick="move(1)">1</td)</tr>
<tr><td id=4 onclick="move(4)">4</td><td id=3 onclick="move(3)">3</td><td id=8 onclick="move(8)">8</td)</tr>
</table>
</body>

Ответить
Fishbones
Fishbones - 02.02.2023 07:26

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

Ответить
aimrick nya
aimrick nya - 09.01.2023 21:07

I was not able to user the scanner method on my IDE. Is there a way to get around that?

Ответить