Комментарии:
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.
Ответитьcreative
Ответитьvery good video
Ответить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 😌
Ответить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 :)
Ответитьi did not expect you to slowly and menacingly pop up in the first few seconds lmaoo 😭 great video!!
ОтветитьEpic
ОтветитьCan i get the code?
ОтветитьThankyou brother very helpful 🥰😇
Ответитьthanks a lot man awesome!!
Ответитьi cant thank you enough you are a great teacher
ОтветитьI think you should OOP. put the board as a class as well as the user which should branch to human and CPU.
ОтветитьCorrection:
Line 26 should be while(playerPositions.contains(playerPos) || cpuPositions.contains(playerPos))
and not while(playerPositions.contains(playerPos) || cpuPositions.contains(playerPositions)) {
I was so confused by the row placement bc I haven't learned double arrays yet and then it all clicked lol.
Ответить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.
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>
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
ОтветитьI was not able to user the scanner method on my IDE. Is there a way to get around that?
Ответить