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
8 changes: 7 additions & 1 deletion client/clientsrc/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class Card extends Image{
public Card(int minX, int maxX, int minY, int maxY, MinuetoImage image, String name) {
super(minX, maxX, minY, maxY, image);
// name of card
// TODO: make sure is consistent w CardType enum in serversrc
aName = name;
}

Expand All @@ -45,7 +46,12 @@ public boolean equals(Object o){
return c.getName().equalsIgnoreCase(this.aName);
}

private String getName(){
public String getName(){
return this.aName;
}

/** DID NOT NEED THIS. USED Game.getFaceDownCard(cardString) directly from game in Player
public Card getCardByName(String cardString){
return Game.getFaceDownCard(cardString);
} **/
}
30 changes: 16 additions & 14 deletions client/clientsrc/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ClientMain {
public static User currentUser;
public static LobbyServiceGameSession currentSession;

public static Player currentPlayer;
public static Game currentGame;

static GUI gui;
static MinuetoEventQueue entryScreenQueue, loginScreenQueue, moveBootQueue, lobbyScreenQueue, createGameQueue,
elfenlandLobbyQueue;
Expand Down Expand Up @@ -792,15 +795,6 @@ public void handleMousePress(int x, int y, int button) {
&& (currentUser.getName().equals(currentSession.getCreator()))) {
// click on Launch button -> launch the session
REGISTRATOR.launchSession(currentSession, currentUser);
// go to board screen
LobbyServiceGame gameService = currentSession.getGameService();
Game game = gameService.getGame();
Mode currentMode = game.getMode();
if (currentMode.equals(Mode.ELFENLAND)) {
gui.currentBackground = GUI.Screen.ELFENLAND;
} else if (currentMode.equals(Mode.ELFENGOLD)) {
gui.currentBackground = GUI.Screen.ELFENGOLD;
}
}

} else if (x >= 822 & x <= 998 && y <= 655 && y >= 585) {
Expand Down Expand Up @@ -1274,16 +1268,14 @@ public static void displayUsers() throws MinuetoFileException {
}

MinuetoImage background = null;
LobbyServiceGame gameService = currentSession.getGameService();
Game game = gameService.getGame();
Mode currentMode = game.getMode();
if (currentMode.equals(Mode.ELFENLAND)) {

if (modeSel.equals(Mode.ELFENLAND)) {
if (currentUser.getName().equals(currentSession.getCreator())) {
background = lobbyElfenlandCreatorBackground;
} else {
background = lobbyElfenlandBackground;
}
} else if (currentMode.equals(Mode.ELFENGOLD)) {
} else if (modeSel.equals(Mode.ELFENGOLD)) {
if (currentUser.getName().equals(currentSession.getCreator())) {
background = lobbyElfengoldCreatorBackground;
} else {
Expand Down Expand Up @@ -1409,4 +1401,14 @@ public static void displayAvailableGames() {
e.printStackTrace();
}
}

public static void receivePhaseOne(String playerID, ArrayList<String> cardArray){
for (Player p: players){
if (p.getName().equalsIgnoreCase(playerID)){
p.addCardStringArray(cardArray);
}
}


}
}
11 changes: 10 additions & 1 deletion client/clientsrc/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Game {
private boolean witchEnabled;
private Mode mode;
private TownGoldOption townGoldOption;
private ArrayList<Card> faceDownCardPile;
private static ArrayList<Card> faceDownCardPile;
private ArrayList<Card> faceUpCardPile;
private ArrayList<GoldCard> goldCardPile;
//private Auction auction; not doing this now
Expand Down Expand Up @@ -218,4 +218,13 @@ public static boolean notClickingOnATown(int x, int y) {
return false;
}

public static Card getFaceDownCard(String cardString){
for (Card aCard : faceDownCardPile){
if (aCard.getName().equalsIgnoreCase(cardString)){
return aCard;
}
}
return null; //hopefully this never happens LOL
}

}
6 changes: 6 additions & 0 deletions client/clientsrc/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public void draw() {
public Action getBootAction() {
return aBootAction;
}

public void addCardStringArray(ArrayList<String> cardArray){
for (String cardString : cardArray) {
this.cardsInHand.add(Game.getFaceDownCard(cardString));
}
}
/*
Operation: Player::startGame(gameSession: Session)
Scope: Player; Session;
Expand Down
15 changes: 15 additions & 0 deletions network/networksrc/LaunchGameACK.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ public void execute() {
ClientMain.currentSession.launch();

// modify game objects based on the game state received
<<<<<<< Updated upstream
=======
// TODO: iterate thru playerNames, index for loop --> use to iterate thru playerCards, give Players their cards :)
for (int i = 0; i < playerNames.size(); i++){

String playerID = playerNames.get(i);
ArrayList<String> aPlayersCards = playerCards.get(i);

ClientMain.receivePhaseOne(playerID, aPlayersCards);


}


>>>>>>> Stashed changes
// display the new board

System.out.println("LaunchGameACK received");
Expand Down
31 changes: 31 additions & 0 deletions network/networksrc/MoveBootACK.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package networksrc;

import clientsrc.*;


// updates state of boot on GUI for clients
public class MoveBootACK implements Action{

private String newTown;
private String bootColor;

public MoveBootACK(String newTown, String bootColor){
this.newTown = newTown;
this.bootColor = bootColor;
}

@Override
public boolean isValid() {
return true;
}

@Override
public void execute() {
System.out.println("MoveBootACK received");
Player p = ClientMain.currentPlayer;
Game g = ClientMain.currentGame;
// TODO: call a method that updates GUI by changing the boot with bootColor to newTown
ClientMain.moveBoot(String bootColor, String toTown);
}

}
84 changes: 84 additions & 0 deletions network/networksrc/MoveBootAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package networksrc;

import java.util.ArrayList;
import serversrc.*;


public class MoveBootAction implements Action {

private String senderName;
private String srcTown;
private String dstTown;

public MoveBootAction(String senderName, String srcTown, String dstTown) {
this.senderName = senderName;
this.srcTown = srcTown;
this.dstTown = dstTown;
}

@Override
public boolean isValid() {
// TODO: check if parameters are not null

Player playerWhoSent = Player.getPlayerByName(senderName);
ServerGame playersCurrentGame = playerWhoSent.getCurrentGame();

// sanity check : the player is actually in that game
ArrayList<Player> allPlayers = playersCurrentGame.getAllPlayers();
if (!allPlayers.contains(playerWhoSent)) {
return false;
}

// add other validation here
// check for moveBoot phase
if (playersCurrentGame.getCurrentPhase() != 5){
// do nothing ?
System.out.println("ERROR: Not moveBoot phase!");
return false;
}
// check if it's not player's turn
if (!playerWhoSent.getIsTurn()){
// do nothing ?
System.out.println("ERROR: Not " + playerWhoSent.getName() + "'s turn!");
return false;
}
Town sTown = playersCurrentGame.getTownByName(srcTown);
Town dTown = playersCurrentGame.getTownByName(dstTown);
Route route = playersCurrentGame.getTownGraph().getRoute(sTown, dTown);
// check if route is not adjacent to player
if (!(route.getSource() == playerWhoSent.getTown() || route.getDest() == playerWhoSent.getTown())){
// do nothing ?
System.out.println("ERROR: Invalid route (not adjacent to player's location)!");
return false;
}
// check if player has the cards required to travel that route
// if (!playerWhoSent.hasCards(route.getRequiredCards())){
// System.out.println("ERROR: Player doesn't have all cards required!");
// return false;
// }

return true;
}

@Override
public void execute() {
// server has received the message
System.out.println("Executing the MoveBootAction on the server");

Player playerWhoSent = Player.getPlayerByName(senderName);
ServerGame playersCurrentGame = playerWhoSent.getCurrentGame();
Town sTown = playersCurrentGame.getTownByName(srcTown);
Town dTown = playersCurrentGame.getTownByName(dstTown);
Route route = playersCurrentGame.getTownGraph().getRoute(sTown, dTown);

System.out.println(playerWhoSent + " is in game " + playersCurrentGame.getGameID());

// here you can do stuff with playerWhoSent and playersCurrentGame
playersCurrentGame.playerMovedBoot(playerWhoSent, route);

// send an ACK to all clients in the game
ACKManager ackManager = ACKManager.getInstance();
MoveBootACK actionToSend = new MoveBootACK(dstTown, playerWhoSent.getBootColor().name());
ackManager.sentToAllPlayersInGame(actionToSend, playersCurrentGame);
}
}
3 changes: 3 additions & 0 deletions server/serversrc/Boot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class Boot {

Color color;

public Color getColor(){
return this.color;
}

}
7 changes: 7 additions & 0 deletions server/serversrc/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public boolean equals(Object o){
return c.getName().equalsIgnoreCase(this.aName);
}

<<<<<<< Updated upstream
private String getName(){
return this.aName;
=======
// public or private idk it says to make it public
public String getName(){
return this.aCardType.name();
>>>>>>> Stashed changes
}

}
24 changes: 24 additions & 0 deletions server/serversrc/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,32 @@ public Action getBootAction() {
public String getName() {
return aServerUser.getName();
}
public Town getTown(){
return this.inTown;
}

public boolean getIsTurn(){
return this.isTurn;
}

public Color getBootColor(){
return this.aBoot.getColor();
}
// draw counter from face down pile

<<<<<<< Updated upstream
=======
public void addCard(AbstractCard c){
cardsInHand.add(c);
}

public List<AbstractCard> getCards(){
return cardsInHand;
}



>>>>>>> Stashed changes
/*
Operation: Player::drawFaceUpToken(token: Token, tStack: TokenStack)
Scope: Player; Game; Token;
Expand Down
Loading