Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Fixed piece moving functionality, again
Browse files Browse the repository at this point in the history
  • Loading branch information
downvec committed Dec 17, 2017
1 parent fe188f7 commit efb6d68
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 80 deletions.
200 changes: 127 additions & 73 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/ProyectoCuatroTribus/com/company/Tribes/Tribe.class
Binary file not shown.
8 changes: 7 additions & 1 deletion src/com/company/GUI/BoardSquare.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ public void addPiecesToSquare(List<GuiPiece> newPieces, Piece.colors actingColor
if (actingColor != this.dominantColor && this.dominantColor != null){
List<GuiPiece> survivingPieces = LogicEngine.resolveBattle(this.pieces,newPieces);

pieces.addAll(survivingPieces);
if (!survivingPieces.isEmpty()) {
for (GuiPiece piece : survivingPieces) {
piece.setRowCol(this.row, this.col);
}

pieces.addAll(survivingPieces);
}
}else{ // No battle was detected
for (GuiPiece piece: newPieces){
piece.setRowCol(this.row,this.col);
Expand Down
4 changes: 2 additions & 2 deletions src/com/company/GUI/DragNDropListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DragNDropListener implements MouseMotionListener, MouseListener{
*/
public DragNDropListener( Board board){
this.gameBoard = board;
this.boardMatrix = this.gameBoard.boardMatrix;
this.boardMatrix = Board.boardMatrix;
this.troopsAreBeingMobilized = false;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public void mousePressed(MouseEvent e) {
} else {
this.clickedSquare.addPiecesToSquare(piecesOnTheMove, gameBoard.colorInTurn);
this.troopsAreBeingMobilized = false;
piecesOnTheMove = Collections.emptyList();
piecesOnTheMove = new ArrayList<>();
gameBoard.repaint();
}

Expand Down
6 changes: 2 additions & 4 deletions src/com/company/Logic/LogicEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import com.company.GUI.BoardSquare;
import com.company.Pieces.GuiPiece;
import com.company.Pieces.Piece;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -19,7 +17,7 @@ public class LogicEngine {
* List of pieces is sorted. Pieces are eliminated in 1:1 ratio starting from bottom.
* @param defendingPieces Pieces originally on sqaure. Pieces defending the city
* @param attackingPieces Pieces attacking the city.
* @return
* @return List of pieces surviving the battle
*/
public static List<GuiPiece> resolveBattle(List<GuiPiece> defendingPieces, List<GuiPiece> attackingPieces){
boolean artillieryPresent = false;
Expand All @@ -33,7 +31,7 @@ public static List<GuiPiece> resolveBattle(List<GuiPiece> defendingPieces, List<
}

if (!artillieryPresent){
//TODO: Verify if the sorting actually works

Collections.sort(defendingPieces);
Collections.sort(attackingPieces);

Expand Down
1 change: 1 addition & 0 deletions src/com/company/Tribes/Tribe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

public abstract class Tribe {
Piece.colors myColor;
int PacsAvailable;
}

0 comments on commit efb6d68

Please sign in to comment.