JavaFX Game: Checkers

  Рет қаралды 81,858

Almas Baim (AlmasB)

Almas Baim (AlmasB)

Күн бұрын

Пікірлер: 50
@maxlight9258
@maxlight9258 4 жыл бұрын
СПбПУ!!!!!! Если у вас задание шашки, то аккуратнее! Преподы знают об этом видео
@TRAITORwtf
@TRAITORwtf 7 жыл бұрын
спасибо, добрый человек. дико крутые туториалы)
@lexibeauchamp2454
@lexibeauchamp2454 8 жыл бұрын
Need to add the rules for when a piece becomes a king so it can move anywhere and to draw a king symbol on a piece when it becomes a king.
@micknat7665
@micknat7665 5 жыл бұрын
Hey I'm going through your tutorial now. But for some reason when it displays the board the top row and left most column are solid white. Any idea what I could be off on? I have my x and y for the for loops starting at 0. Note, when the pieces are put on the board they're distributed normally and not off.
@ROFLInternetComments
@ROFLInternetComments 7 жыл бұрын
Thank you for this wonderful tutorial! Your voice is pleasing lol. I am new to programming and new to JavaFX. Question: why did you create the method, makePiece and the logic for setOnMouseReleased, inside of the CheckersApp class instead of inside the constructor for Piece? And therefore seperated the OnMouseReleased (which is inside makePiece) from the MouseClicked, MouseDragged events that are declared inside the Piece constructor. I guess its a two part question. 1) Why are you using makePiece instead of using the Piece constructor. 2) Why did you seperate the MouseReleased from the MouseClicked, MouseDragged. Thank you, Trevor
@AlmasB0
@AlmasB0 7 жыл бұрын
Hi, it's been a while so I don't quite remember why. From a quick skim through, it seems I needed access to some methods, like tryMove(). Most of the JavaFX tutorials I've done are goal-oriented and may not follow good programming principles, so tread carefully. For proper software design with JavaFX, here's a great resource: docs.oracle.com/javase/8/javase-clienttechnologies.htm
@konnor_rg
@konnor_rg 3 жыл бұрын
I'm a beginner, just found this and it looks awesome. I implemented your code and now trying to add stuff to make more like an actual game. I recently added a method to turn regular pieces into kings. Although I'm still puzzled at how to make the kings move freely. I kind of get the basic idea of how it works, I just don't know how to implement it into the code. If anyone here can kindly clear this up for me, it'll be a huge help :)
@lucianoalarcon
@lucianoalarcon 4 жыл бұрын
Hello Almas, good tutorial. Do you could explain me, wich is the idea for this? Tile tile = new Tile ((x + y) % 2 == 0, x , y);
@merostax5294
@merostax5294 3 жыл бұрын
think of it like 2 dementional array, if you sum x and y %2, in each position where the sum of them is even then a white tile will be placed if not the green one will be placed and so on
@clarkflavor
@clarkflavor 7 жыл бұрын
I think the algorithm in ChekcerApp's toBoard() method is a bit off. It returns two different coordinates per square depending on where you click on the chess piece. If you change the algorithm to something like "return (int) ((pixel + SQUARE_SIZE) / SQUARE_SIZE) - 1;" instead, you get correct x and y coordinates no matter where on the chess piece you click.
@AlmasB0
@AlmasB0 7 жыл бұрын
Yes, you are correct. The existing code only works because the pieces are snapped to corners. If we allowed free movement, the current code would break. Nice work spotting that! The code is here - github.com/AlmasB/FXTutorials/blob/master/src/com/almasb/checkers/CheckersApp.java Can you pull a request with changes and I'll merge that.
@clarkflavor
@clarkflavor 7 жыл бұрын
Ok, cool thanks - I'll do that
@AlmasB0
@AlmasB0 7 жыл бұрын
I've run the updated code and the movement felt awkward. I realized that TILE_SIZE / 2 was deliberately allowing the user to 'drop' the piece near the tile and it would stick. Hence, adding a smoother experience. Having said that, your approach revealed another bug the code previously had. If you grab the piece, wander off the screen and drop it there, the board will still try to get coordinates for that. This has now been fixed, so thank you for that. I should, of course, point out that your approach is correct for tile-based games, it's just here we use the layout X and Y of the piece, as well as considering the center point of the piece and thus it's an edge case.
@iansweeney4883
@iansweeney4883 8 жыл бұрын
Great tutorial. Many thanks.
@Funymanyay
@Funymanyay 2 жыл бұрын
So I've written the code and run the program, and everything works except that all the pieces go into the top left corner of the board? Any idea why this is happing?
@olidare8008
@olidare8008 7 жыл бұрын
So this code just sets up the board? Would you recommend another class or 2 for the actual game logic? In the real game, when a checker gets to the end it can change direction, would I have to adjust the pieceTypes class which contains: red(1) white(-1) as surely they need to be able to go more than one way
@AlmasB0
@AlmasB0 7 жыл бұрын
Hi, having game logic separate is a good idea. Since this is just a basic demo, you will find that some of the code may not scale well to an actual game. I haven't actually thought about the software design of the full game, so take the following recommendation with caution. Have a boolean flag to check if a piece has reached the end. Then, in tryMove() have another condition to check that flag, in which case you would need to compute both directions.
@vanshgoswami1507
@vanshgoswami1507 8 жыл бұрын
Hello this tutorial is awesome, can you please make a video on how to check who wins and how to tell the player its their turn to play.
@s.a1101
@s.a1101 4 жыл бұрын
great tutorial ;) but it gives me this error whenever i,m trying to use *setOnMouesPressed* or *setOnMouseDragged* "lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)" can you plz help me with that?
@AlmasB0
@AlmasB0 4 жыл бұрын
Hi, the error says you are using java 7. Lambda expressions were introduced in java 8, so to fix, ensure your IDE uses java 8.
@mohaibra8065
@mohaibra8065 8 жыл бұрын
i dont understand this method, setFill(light ? Color.valueOf("#feb") : Color.valueOf("#582")); why do you have a question mark inside the parameter and why not this way setFill(Color.valueOf("#feb");
@AlmasB0
@AlmasB0 8 жыл бұрын
+Moha Ibra Hi, ? and : together form a shorthand for value = if (boolean expression) then value1 else value2, so this becomes now value = boolean expression ? value1 : value2
@mohaibra8065
@mohaibra8065 8 жыл бұрын
i get it thanks,
@needmorecontent6172
@needmorecontent6172 3 жыл бұрын
is there a way to move backwards??
@EmmnauelPeace
@EmmnauelPeace 4 жыл бұрын
Yes if the ai component can be develop with undo redo, other advance features can be added this will make the game highly intelligent and with difficulty level implemented using min-max and alpha plunning and other algorithm such as neural network I believe it will help so much Great work ...Thanks
@oscaralcaraz2849
@oscaralcaraz2849 7 жыл бұрын
Hi, i have some questions, how can i re draw the board? and most important if i save the position of a tile(oldX and oldY) in an array, if in the future i want to change something of that tile(value), can i do it without clicking in the tile?
@bubolski
@bubolski 6 жыл бұрын
Nice. Have a question. How i can add possible to kill backwards.
@bubolski
@bubolski 6 жыл бұрын
Ok i got it. Just remove && newY - y0 == piece.getType().moveDir * 2 (commented) if (Math.abs(newX - x0) == 1 && newY - y0 == piece.getType().moveDir) { System.out.println("q"); return new MoveResult(MoveType.NORMAL); /* THESE ELSE IF */ } else if (Math.abs(newX - x0) == 2){ int x1 = x0 + (newX - x0) / 2; int y1 = y0 + (newY - y0) / 2; if (board[x1][y1].hasPiece() && board[x1][y1].getPiece().getType() != piece.getType()) { System.out.println("w"); return new MoveResult(MoveType.KILL, board[x1][y1].getPiece()); } }
@МадинаМекенбаева-е1ю
@МадинаМекенбаева-е1ю 7 жыл бұрын
Hi Almas, Need to add the rules for when a piece becomes a king so it can move anywhere and to draw a king symbol on a piece when it becomes a king. How we write it?
@AlmasB0
@AlmasB0 7 жыл бұрын
Hi, checking when a piece should ascend to a king is simple: use the 2D grid bounds, e.g. 0 and size - 1. If a piece reaches the opposite side then it should be upgraded. The movement is a bit tricky: when you move a piece you should also check if it's a king type, if it is, then allow to move accordingly. As for the drawing, that should be easy. A Piece is a StackPane, when the "king" status is obtained, just update the children of a Piece by replacing the existing ones with a new image / sprite.
@victormarchante414
@victormarchante414 7 жыл бұрын
hey almas one question how we could call the class CheckersApp from a menu that we make with javafx, we got a main java and we are trying to use your checkersApp for testing it, and we cant. how we can use checkersApp like an object and call it from our menu .Thank you for help us
@AlmasB0
@AlmasB0 7 жыл бұрын
Hi, JavaFX cannot run two applications under a single runtime. As such, what you are describing cannot be readily done. If you want to add a menu to Checkers, you will need to create an intermediate Scene or Parent. From within the menu you should be able to create a basic event handler that will allow you to switch between root nodes, i.e. menu root and game root.
@Shaudow
@Shaudow 8 жыл бұрын
Could you do a tutorial on how to implement the kings in checkers as well as Minimax/Alpha Beta with this? If you have source code already, could you please link it?
@asennikolaev8069
@asennikolaev8069 7 жыл бұрын
Almas ? how many years of practice are needed to be master like this ?
@AlmasB0
@AlmasB0 7 жыл бұрын
Hi, generally if starting from no programming background, I'd expect 2nd, maybe 3rd year computer science students to be able to produce something similar. Having said that, if one focuses on just a single technology, e.g. first learn programming basics in Java, then move straight to JavaFX, it is potentially possible to acquire skills within a year. Nevertheless, each person is different and has a different background, hence the times I've given are just rough estimates.
@hansbaum7272
@hansbaum7272 8 жыл бұрын
hi. Can you use the same code to run it with gluon on android and ios devices?
@AlmasB0
@AlmasB0 8 жыл бұрын
+Hans Baum Hi, yes, you will, however, need to adjust the game size to the screen size, so that mouse events are mapped correctly. Everything else should work just fine.
@abdulrhmanyahyaalkahirah5660
@abdulrhmanyahyaalkahirah5660 6 жыл бұрын
Thanks a lot
@Chavyyy
@Chavyyy 5 жыл бұрын
Hello, your video is awesome! I am currently trying to add some commands to this game. a reset button, a player vs player etc. Just some GUI to it. What I actually want to do is add this code to another Pane so it doesn't take all the space of the scene. Could you help me doing this thank you.!
@МадиярМолдабаев-с1ъ
@МадиярМолдабаев-с1ъ 6 жыл бұрын
What is the name of program where you creating that?
@AlmasB0
@AlmasB0 6 жыл бұрын
It's called IntelliJ IDEA. Here's the link: www.jetbrains.com/idea/
@МадиярМолдабаев-с1ъ
@МадиярМолдабаев-с1ъ 6 жыл бұрын
thanks!!!
@Attee_Q
@Attee_Q 4 жыл бұрын
import static com.almasb.checkers.CheckersApp.TILE_SIZE; Why import, why not class variable?
@felipefig10
@felipefig10 8 жыл бұрын
what am i supposed to import?
@AlmasB0
@AlmasB0 8 жыл бұрын
+Felipe Figueiredo Hi, the link to full source code is in the video description.
@danziv94
@danziv94 4 жыл бұрын
how do you install javafx on android studio i cant imortjavafx
@danziv94
@danziv94 4 жыл бұрын
now i have a different problem i get Graphics Device initialization failed for : d3d, sw Error initializing QuantumRenderer: no suitable pipeline found java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
@learn001
@learn001 5 жыл бұрын
Can you please make Ludo King Game in javaFX.
@checkersvip
@checkersvip 3 жыл бұрын
code is not available anymore
@AlmasB0
@AlmasB0 3 жыл бұрын
Thanks, updated the link: github.com/AlmasB/FXTutorials/tree/master/src/main/java/com/almasb/checkers
JavaFX Custom Game Menu: Thief
35:41
Almas Baim (AlmasB)
Рет қаралды 42 М.
JavaFX Game: Asteroids
21:05
Almas Baim (AlmasB)
Рет қаралды 30 М.
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 3,5 МЛН
버블티로 부자 구별하는법4
00:11
진영민yeongmin
Рет қаралды 24 МЛН
JavaFX: Visualizing Vector Fields
23:26
Almas Baim (AlmasB)
Рет қаралды 2,1 М.
Making a Game with Java with No Experience
8:41
Goodgis
Рет қаралды 480 М.
JavaFX Game: Tetris
33:31
Almas Baim (AlmasB)
Рет қаралды 22 М.
JavaFX MVC + JDBC + DAO + DI: Library Loan System
56:07
Almas Baim (AlmasB)
Рет қаралды 20 М.
JavaFX Game Tutorial: TicTacToe
31:22
Almas Baim (AlmasB)
Рет қаралды 72 М.
JavaFX Game: BlackJack
29:00
Almas Baim (AlmasB)
Рет қаралды 32 М.
JavaFX Game: Connect4
34:22
Almas Baim (AlmasB)
Рет қаралды 41 М.
JavaFX Game: Battleship
32:57
Almas Baim (AlmasB)
Рет қаралды 43 М.
Board Games in Java: Chess, Checkers, etc - part 1
8:20
The Code Implementation
Рет қаралды 13 М.