Hello all,
Me again. So the good news is I went back to square one with my chess app following discussions on here with a few of you. I am now using any components blocks and cloning buttons to help speed up the building phase and hopefully gameplay.
I have figured out how to get the rook to act as I want it to for movement. I am confident I can get the bishop, queen, king and pawn to act appropriately. Haven’t tackled the knight yet as I think that may take a little mind bending to figure out. Then again it might turn out one of the easiest. Who knows with coding?
Anyway, I have ran into another small problem. Attacking. I can get the rook to attack if only one piece is on the board. However, if there is another piece in front of it my game completely ignores this and looks for the piece behind (the original piece). It’s definitely an issue with how I have coded it but I can not figure out what.
I will attach a screenshot below of some of my blocks. Let me know if better ones are needed or ones with more detail. A bit of background to how I have coded it; I have asked the program to detect the hidden text on the piece clicked using the any components block. If the piece clicked contains the text BR (Black Rook) then display the “move” button and clone it 7 times. I made a function for this with an input value called numberOfLoops. Then attached the value 7 to that. In the function I have asked it to detect whether the clone’s x and y is the same as WP1’s x and y. If it is then the clone’s visibility should be false as should the move button. This is so it does not show anything after this as a possible move. This works fine. I have also used the same method to detect the top, bottom, left and right side of the board.
I then ask the loop inside the function to show another button called “attack1” if it detects that “clone” is at WP1’s x and y. The issue I have is introducing another piece. I want the app to show only the closest piece as an available attack no matter which piece that is (for example whether WP1 or WP2). Does that all make sense?
[EDIT] I have just discovered a way to remove the need for attack buttons. I have asked it to change the background image and text of the clone when it is at an enemy’s x and y instead of displaying a whole new button. I then ask it to change back after this. But I may still have the issue regarding it stopping cloning once it shows the attack button.