Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import akka.actor.ActorRef;
import structures.GameState;
import game.selection.SelectionGuards;
import game.selection.SelectionManager;
import game.selection.TargetingOverlay;
import structures.basic.Card;

/**
* Indicates that the user has clicked an object on the game canvas, in this case a card.
Expand All @@ -20,12 +24,41 @@
*/
public class CardClicked implements EventProcessor{

@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {

int handPosition = message.get("position").asInt();


}
@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {

if (gameState == null || !gameState.gameInitalised) return;
int handPosition = message.get("position").asInt();
if (!SelectionGuards.isValidHandPosition(handPosition)) return;
SelectionGuards.clearStaleSelectionIfNeeded(gameState);

if (!SelectionGuards.hasCardInHand(gameState, handPosition)) {
SelectionManager.clearSelectionAndHighlights(out, gameState);
return;
}
if (SelectionGuards.isSameSelectedCard(gameState, handPosition)) {
SelectionManager.clearSelectionAndHighlights(out, gameState);
return;
}

SelectionManager.selectCard(out, gameState, handPosition);
Card card = gameState.getP1HandAtPos(handPosition);
if (card == null) {
SelectionManager.clearSelectionAndHighlights(out, gameState);
return;
}

// Wenbo’s responsibility starts here:
//compute legal summon/spell targets for this card
//then highlight those tiles
//The important rule for Wenbo is:
// use SelectionManager.selectCard(...) when switching to a card
// use TargetingOverlay.showTargetHighlights(...) to draw legal targets
// use SelectionManager.clearSelectionAndHighlights(...) only for real cancel
// do not wipe card selection just to redraw tiles,
// because my (abdullah) D4 responsibility is that the selected card stays visibly selected during targeting
//example only:
// Iterable<GameState.Coord> legalTargets = ...
// TargetingOverlay.showTargetHighlights(out, gameState, legalTargets);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package events;
import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;

import akka.actor.ActorRef;
import structures.GameState;
import commands.BasicCommands;
import structures.basic.Card;
import structures.basic.Tile;
import utils.BasicObjectBuilders;

/**
* In the user’s browser, the game is running in an infinite loop, where there is around a 1 second delay
Expand All @@ -24,25 +19,12 @@
*/
public class Heartbeat implements EventProcessor{

private static final int TILE_MODE_NORMAL = 0;
private static final int CARD_MODE_NORMAL = 0;
@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
if (gameState == null || !gameState.gameInitalised) return;
if (gameState.getSelectionMode() != GameState.SelectionState.Mode.NONE) return;
//clear highlighted tiles
Set<GameState.Coord> tilesToClear = gameState.consumeHighlightedTiles();
for (GameState.Coord c : tilesToClear) {
Tile t = BasicObjectBuilders.loadTile(c.x, c.y);
BasicCommands.drawTile(out, t, TILE_MODE_NORMAL);
}
//clear highlighted cards
Set<Integer> handToClear = gameState.consumeHighlightedHandPositions();
for (Integer pos : handToClear) {
if (pos == null) continue;
Card card = gameState.getP1HandAtPos(pos);
if (card != null) BasicCommands.drawCard(out, card, pos, CARD_MODE_NORMAL);
}

game.selection.SelectionManager.clearSelectionAndHighlights(out, gameState);
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package events;

import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;

import akka.actor.ActorRef;
import commands.BasicCommands;
import structures.GameState;
import structures.basic.Card;
import structures.basic.Tile;
import utils.BasicObjectBuilders;

/**
* Indicates that the user has clicked an object on the game canvas, in this case
Expand All @@ -24,33 +18,11 @@
*/
public class OtherClicked implements EventProcessor{

//mode 0 is the "normal" render mode for tiles and cards in the template.
private static final int TILE_MODE_NORMAL = 0;
private static final int CARD_MODE_NORMAL = 0;

@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
if (gameState == null || !gameState.gameInitalised) return;

//clear any highlighted tiles by drawing them again in normal mode
Set<GameState.Coord> tilesToClear = gameState.consumeHighlightedTiles();
for (GameState.Coord c : tilesToClear) {
Tile t = BasicObjectBuilders.loadTile(c.x, c.y);
BasicCommands.drawTile(out, t, TILE_MODE_NORMAL);
}
//clear any highlighted hand cards for player 1 by drawing them again in normal mode
Set<Integer> handPositionsToClear = gameState.consumeHighlightedHandPositions();
for (Integer pos : handPositionsToClear) {
if (pos == null) continue;
Card card = gameState.getP1HandAtPos(pos);
if (card != null) {
BasicCommands.drawCard(out, card, pos, CARD_MODE_NORMAL);
}
}
//clear selection state
gameState.clearSelection();

}
game.selection.SelectionManager.clearSelectionAndHighlights(out, gameState);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import akka.actor.ActorRef;
import structures.GameState;
import game.selection.SelectionGuards;
import game.selection.SelectionManager;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -24,8 +26,9 @@
*/
public class TileClicked implements EventProcessor{

@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
@Override
public void processEvent(ActorRef out, GameState gameState, JsonNode message) {
if (gameState == null || !gameState.gameInitalised) return;

int tilex = message.get("tilex").asInt();
int tiley = message.get("tiley").asInt();
Expand Down Expand Up @@ -74,4 +77,41 @@ public void processEvent(ActorRef out, GameState gameState, JsonNode message) {

}

}
if (!SelectionGuards.isValidBoardTile(gameState, tilex, tiley)) return;
SelectionGuards.clearStaleSelectionIfNeeded(gameState);
//Assumption: human player is player 1
int friendlyPlayerId = 1;

//for friendly occupied tile use Abdullah's selection helper
if (SelectionManager.handleFriendlyUnitTileClick(out, gameState, tilex, tiley, friendlyPlayerId)) {
return;
}

//if a selected unit exists and clicked tile is highlighted,
// Yang handles movement/combat from here
if (SelectionManager.isUnitSelected(gameState)
&& SelectionGuards.isHighlightedTile(gameState, tilex, tiley)) {

Integer selectedUnitId = gameState.getSelectedUnitId();
if (selectedUnitId == null) {
SelectionManager.clearSelectionAndHighlights(out, gameState);
return;
}

Integer clickedUnitId = gameState.board.getUnitIdAt(tilex, tiley);

if (clickedUnitId == null) {
// Yang: movement logic here
// move selected unit to (tilex, tiley)
return;
} else {
// Yang: combat logic here
// selected unit attacks clicked unit
return;
}
}

//Anything else would clear selection
SelectionManager.clearSelectionAndHighlights(out, gameState);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package events;

//Core behaviour of this class is as follows:
//If nothing selected:
// select this unit
//If another unit selected:
// switch selection
//If same unit selected:
// cancel selection

public class UnitClicked {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Board {
public static final int WIDTH = 9;
public static final int HEIGHT = 5;

//I used 1 based coordinates here which means x = 1 to 9 and y = 1 to 5
//I used 0 based coordinates here which means x = 0 to 8 and y = 0 to 4
private final int minX;
private final int minY;

Expand Down
Loading