JavaFX Game: Checkers

Поделиться
HTML-код
  • Опубликовано: 23 окт 2024

Комментарии • 50

  • @maxlight9258
    @maxlight9258 4 года назад

    СПбПУ!!!!!! Если у вас задание шашки, то аккуратнее! Преподы знают об этом видео

  • @TRAITORwtf
    @TRAITORwtf 7 лет назад +1

    спасибо, добрый человек. дико крутые туториалы)

  • @lexibeauchamp2454
    @lexibeauchamp2454 8 лет назад +1

    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 лет назад +1

    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 года назад +2

    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 года назад +1

      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 лет назад +1

      Ok, cool thanks - I'll do that

    • @AlmasB0
      @AlmasB0  7 лет назад +1

      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 лет назад +4

    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 лет назад +3

    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 года назад +1

    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 лет назад +1

    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 лет назад +2

      +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ю

    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 лет назад +1

      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 лет назад +1

      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 лет назад +2

    hi. Can you use the same code to run it with gluon on android and ios devices?

    • @AlmasB0
      @AlmasB0  8 лет назад +3

      +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 лет назад +1

    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ъ

    What is the name of program where you creating that?

  • @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 года назад +1

      Thanks, updated the link: github.com/AlmasB/FXTutorials/tree/master/src/main/java/com/almasb/checkers