Permalink
Browse files

beta 1.1 patchnotes

 * Cards now can be moved by any distance, the minimum distance has been removed.
 *
 * Settings added. Player now can specify their name and active deck here,
 * they will be saved and loaded on next program startup. Changing sizes
 * of cards does not work yet.
 *
 * Main game window now can be minimized (see: button in top right corner).
 *
 * Interface for joining a game has been improved. Player now can enter host
 * as IP:PORT or give only IP as a host and give a PORT separately. Last entered
 * IP is saved.
 *
 * Interface for creating a game has been improved. Once server is created
 * its IP is copied into the system clipboard. It is possible to create
 * a server, but do not join it.
 *
 * Changed the way server and client handle lost connection and other
 * connection problems. It is now possible to create a server with
 * no necessity to restart the program.
 *
 * When a player disconnects from a game, all their cards are moved into exiled.
 *
 * It is now possible to leave the game without closing a program, which makes
 * restarting a game easier.
 *
 * Deck "Ancient Depths" added.
 *
 * Source is now using JDK7, however no GUI with JLayers has been implemented
 * (yet) so there are no visible changes.
 *
 *
 * KNOWN BUGS:
 *
 * Player can move a card other player exiled into illegal zones like his
 * library or hand. Player's graveyard, exiled zone, library and hand should
 * contain only cards the player owns.
  • Loading branch information...
Jarcionek committed Oct 5, 2011
1 parent 66e7beb commit ee009950d70c71e8568c57be9bd703c56b9a06b2
Showing with 1,552 additions and 716 deletions.
  1. +1 −1 src/deckCreator/SmallCardsViewer.java
  2. +1 −1 src/game/CardViewer.java
  3. +100 −55 src/game/Client.java
  4. +68 −2 src/game/Game.java
  5. +5 −3 src/game/Logger.java
  6. +20 −5 src/game/Table.java
  7. +3 −3 src/mtg/Debug.java
  8. +16 −14 src/mtg/Deck.java
  9. +98 −0 src/mtg/JoinGameFrame.java
  10. +2 −2 src/mtg/Library.java
  11. +208 −367 src/mtg/Main.java
  12. +275 −0 src/mtg/Resources.java
  13. +90 −129 src/{server → mtg}/ServerFrame.java
  14. +304 −0 src/mtg/Settings.java
  15. +37 −19 src/mtg/Utilities.java
  16. BIN src/resources/cards/Assault Zeppelid.jpg
  17. BIN src/resources/cards/Coiling Oracle.jpg
  18. BIN src/resources/cards/Compulsive Research.jpg
  19. BIN src/resources/cards/Cultivate.jpg
  20. BIN src/resources/cards/Edric, Spymaster of Trest.jpg
  21. BIN src/resources/cards/Elvish Piper.jpg
  22. BIN src/resources/cards/Explore.jpg
  23. BIN src/resources/cards/Explosive Vegetation.jpg
  24. BIN src/resources/cards/Giant Octopus.jpg
  25. BIN src/resources/cards/Inkwell Leviathan.jpg
  26. BIN src/resources/cards/Isleback Spawn.jpg
  27. BIN src/resources/cards/Kozilek, Butcher of Truth.jpg
  28. BIN src/resources/cards/Kraken Hatchling.jpg
  29. BIN src/resources/cards/Levitation.jpg
  30. BIN src/resources/cards/Living Destiny.jpg
  31. BIN src/resources/cards/Lorthos, the Tidemaker.jpg
  32. BIN src/resources/cards/Mind Control.jpg
  33. BIN src/resources/cards/New Frontiers.jpg
  34. BIN src/resources/cards/Ondu Giant.jpg
  35. BIN src/resources/cards/Polymorph.jpg
  36. BIN src/resources/cards/Primeval Titan.jpg
  37. BIN src/resources/cards/Rite of Replication.jpg
  38. BIN src/resources/cards/Simic Sky Swallower.jpg
  39. BIN src/resources/cards/Skyshroud Claim.jpg
  40. BIN src/resources/cards/Tidal Kraken.jpg
  41. BIN src/resources/cards/Tidings.jpg
  42. BIN src/resources/cards/Treasure Hunt.jpg
  43. BIN src/resources/cards/Ulamog, the Infinite Gyre.jpg
  44. BIN src/resources/cards/Yavimaya's Embrace.jpg
  45. BIN src/resources/cards/Æther Mutation.jpg
  46. BIN src/resources/decks/Ancient Depths.txt
  47. +16 −2 src/server/Collection.java
  48. +15 −2 src/server/Game.java
  49. +145 −46 src/server/Server.java
  50. +51 −40 src/server/ServerListeningThread.java
  51. +8 −1 src/server/flags/Action.java
  52. +7 −0 src/server/flags/CardsList.java
  53. +6 −0 src/server/flags/CheckDeck.java
  54. +22 −0 src/server/flags/Disconnect.java
  55. +7 −2 src/server/flags/DragCard.java
  56. +4 −6 src/server/flags/MoveCard.java
  57. +9 −2 src/server/flags/Player.java
  58. +9 −0 src/server/flags/Ready.java
  59. +2 −1 src/server/flags/RequestCard.java
  60. +8 −4 src/server/flags/Reveal.java
  61. +3 −4 src/server/flags/Search.java
  62. +6 −3 src/server/flags/Shuffle.java
  63. +6 −2 src/server/flags/TapCard.java
@@ -71,7 +71,7 @@ protected Object doInBackground() throws Exception {
}
};

cards = new ArrayList<ViewableCard>();
cards = new ArrayList<>();
panel = new JPanel(new GridLayout(1, 0));
panel.setPreferredSize(new Dimension(0, Card.H));

@@ -39,7 +39,7 @@ private CardViewer() {}
public CardViewer(InSearcherMouseAdapter listener) {
super(null);
this.listener = listener;
this.cards = new ArrayList<Card>(60);
this.cards = new ArrayList<>(60);
this.setPreferredSize(new Dimension(Card.W * 2, Card.H));
}

@@ -1,14 +1,16 @@
package game;

import java.util.logging.Level;
import java.util.logging.Logger;
//import java.util.logging.Level;
//import java.util.logging.Logger;
import java.awt.Color;
import server.flags.*;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import mtg.Debug;
import mtg.Deck;
import mtg.Main;
@@ -23,29 +25,35 @@
private String serverIP;
private int fileTransferPort;

private game.Game g;
private Game g;

private Socket s;
private ObjectInputStream ois;
private ObjectOutputStream oos;

private String playerName;

private JFrame parentFrame;

private Client() {}

/**
* Creates and starts client thread.
* @param parent sets invisible when client successfully connects and
* sets visible if game GUI is closed
* @param playerName player's name to send to the server
* @param ip ip of the server
* @param port port the server is listening to
* @param deck player's deck
* @throws IOException if client could not connect to the server, could
* not send player's name and deck or could not receive file transfer port
*/
public Client(String playerName, String ip, int port, Deck deck)
public Client(JFrame parent, String playerName, String ip, int port, Deck deck)
throws IOException {
Socket s = new Socket(ip, port);
serverIP = ip;
Debug.p("Connected to " + ip + ":" + port);
this.s = new Socket(ip, port);
this.serverIP = ip;
this.parentFrame = parent;
Debug.p("Client: Connected to " + ip + ":" + port);

oos = new ObjectOutputStream(s.getOutputStream());
oos.flush();
@@ -56,22 +64,24 @@ public Client(String playerName, String ip, int port, Deck deck)
try {
this.playerName = (String) ois.readObject();
} catch (ClassNotFoundException ex) {
Debug.p("Error while receiving name from server", Debug.E);
Debug.p("Client: Error while receiving name from server", Debug.E);
}
fileTransferPort = ois.readInt();
int players = ois.readInt();

g = new game.Game(players, Client.this);
g.log("Connected to", ip + ":" + port, Color.black);
parent.setVisible(false);
}

@Override
public void run() {
Object object = null;
while (true) {
Action object = null;
while (!isInterrupted()) {
object = null;
try {
object = ois.readObject();
object = (Action) ois.readObject();
Debug.p("Client: Client received: " + object);

// DRAG
if (object.getClass().equals(DragCard.class)) {
@@ -118,74 +128,74 @@ public void run() {

// SEARCH
} else if (object.getClass().equals(Search.class)) {
Search s = (Search) object;
switch (s.zone) {
Search se = (Search) object;
switch (se.zone) {
case LIBRARY:
if (s.amount == -1) {
g.log("", g.getPlayerName(s.requestor)
if (se.amount == -1) {
g.log("", g.getPlayerName(se.requestor)
+ " searches his library",
game.Logger.C_SEARCH_LIBRARY);
} else {
g.log("", g.getPlayerName(s.requestor)
+ " looks at the " + s.amount
g.log("", g.getPlayerName(se.requestor)
+ " looks at the " + se.amount
+ " top cards of his library",
game.Logger.C_SEARCH_LIBRARY);
}
if (s.cardsIDs != null) {
CardViewer.createViewerInFrame(s.cardsIDs,
if (se.cardsIDs != null) {
CardViewer.createViewerInFrame(se.cardsIDs,
Zone.LIBRARY, g.getSize(),
"Your library");
}
break;
case GRAVEYARD:
g.log("", g.getPlayerName(s.requestor)
g.log("", g.getPlayerName(se.requestor)
+ " searches "
+ g.getPlayerName(s.zoneOwner)
+ g.getPlayerName(se.zoneOwner)
+ "'s graveyard", game.Logger.C_SEARCH_GRAVEYARD);
if (s.cardsIDs != null) {
CardViewer.createViewerInFrame(s.cardsIDs,
if (se.cardsIDs != null) {
CardViewer.createViewerInFrame(se.cardsIDs,
Zone.GRAVEYARD, g.getSize(),
g.getPlayerName(s.zoneOwner)
g.getPlayerName(se.zoneOwner)
+ "'s graveyard ("
+ s.cardsIDs.length + " cards)");
+ se.cardsIDs.length + " cards)");
}
break;
case EXILED:
g.log("", g.getPlayerName(s.requestor)
g.log("", g.getPlayerName(se.requestor)
+ " searches "
+ g.getPlayerName(s.zoneOwner)
+ g.getPlayerName(se.zoneOwner)
+ "'s exiled zone", game.Logger.C_SEARCH_EXILED);
if (s.cardsIDs != null) {
CardViewer.createViewerInFrame(s.cardsIDs,
if (se.cardsIDs != null) {
CardViewer.createViewerInFrame(se.cardsIDs,
Zone.EXILED, g.getSize(),
g.getPlayerName(s.zoneOwner)
+ "'s exiled zone (" + s.cardsIDs.length
g.getPlayerName(se.zoneOwner)
+ "'s exiled zone (" + se.cardsIDs.length
+ " cards)");
}
break;
}

// SHUFFLE LIBRARY
} else if (object.getClass().equals(Shuffle.class)) {
Shuffle s = (Shuffle) object;
g.log("", g.getPlayerName(s.owner) + " shuffles his library",
Shuffle sh = (Shuffle) object;
g.log("", g.getPlayerName(sh.requestor) + " shuffles his library",
game.Logger.C_SHUFFLE);

// REVEAL
} else if (object.getClass().equals(Reveal.class)) {
Reveal r = (Reveal) object;
if (r.source == Zone.TOP_LIBRARY) {
g.log(r.cardID, false, g.getPlayerName(r.requstor)
g.log(r.cardID, false, g.getPlayerName(r.requestor)
+ " reveals top card of his library: "
+ Game.getCardName(r.cardID), game.Logger.C_REVEAL);
}

// REQUEST CARD - server requests client to send card's image
} else if (object.getClass().equals(RequestCard.class)) {
RequestCard t = (RequestCard) object;
Socket socket = new Socket(serverIP, fileTransferPort);
Utilities.sendFile(new File(Utilities.findPath(t.name)), socket);
socket.close();
try (Socket socket = new Socket(serverIP, fileTransferPort)) {
Utilities.sendFile(new File(Utilities.findPath(t.name)), socket);
}

// CHECK DECK - server requests client to check if
// it has all cards in deck sent
@@ -200,12 +210,10 @@ public void run() {
// send card request
oos.writeObject(new RequestCard(d.getArrayNames(j)));
oos.flush();

// receive file
Socket t = new Socket(serverIP, fileTransferPort);
Utilities.receiveFile(new File(Main.CARDS_DL,
d.getArrayNames(j) + ".jpg"), t);
t.close();
try (Socket t = new Socket(serverIP, fileTransferPort)) {
Utilities.receiveFile(new File(Main.CARDS_DL,
d.getArrayNames(j) + ".jpg"), t);
}
}
}
oos.writeObject(new Ready());
@@ -217,19 +225,43 @@ public void run() {
+ d.getName() + ".txt"));

g.setPlayerLibrarySize(cd.owner, d.getDeckSize());

// DISCONNECT
} else if (object.getClass().equals(Disconnect.class)) {
Disconnect d = (Disconnect) object;
if (d.requestor == -1) {
JOptionPane.showMessageDialog(parentFrame,
"Server has been closed", "MTG",
JOptionPane.ERROR_MESSAGE);
s.close();
g.dispose();
parentFrame.setVisible(true);
return;
}
String text = d.intentional? "has left the game" :
"has lost connection";
g.log(null, false, g.getPlayerName(d.requestor) + " " + text,
game.Logger.C_DISCONNECT);
g.kill(d.requestor);

// CARDS LIST
} else if (object.getClass().equals(CardsList.class)) {
g.setCardsList(((CardsList) object).list);
}
} catch (Exception ex) {
if ("Connection reset".equals(ex.getLocalizedMessage())) {
Debug.p("Server closed", Debug.CE);
break;
} else {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
Debug.p("Client error while dealing with " + object + ": " + ex,
Debug.E);
switch (ex.getLocalizedMessage() != null?
ex.getLocalizedMessage() : "") {
case "Connection reset":
Debug.p("Client: Server closed");
closeClient();
case "socket closed":
//it happens when client has been closed
return;
default:
//Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
Debug.p("Client: Error while dealing with " + object + ": " + ex,
Debug.E);
break;
}
}
}
@@ -271,7 +303,7 @@ private void handleMoveCard(MoveCard mc) {
game.Logger.C_MOVE_EXILE);
break;
case LIBRARY:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("Illegal move");
case TOP_LIBRARY:
g.changeLibrarySize(mc.requestor, 1);
if (mc.reveal) {
@@ -325,7 +357,7 @@ private void handleMoveCard(MoveCard mc) {
game.Logger.C_MOVE_EXILE);
break;
case LIBRARY:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("Illegal move");
case TOP_LIBRARY:
g.changeLibrarySize(mc.requestor, 1);
g.log(mc.cardID, false, g.getPlayerName(mc.requestor)
@@ -362,7 +394,7 @@ private void handleMoveCard(MoveCard mc) {
game.Logger.C_MOVE_EXILE);
break;
case LIBRARY:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("Illegal move");
case TOP_LIBRARY:
g.changeLibrarySize(mc.requestor, 1);
g.log(mc.cardID, false, g.getPlayerName(mc.requestor)
@@ -403,7 +435,7 @@ private void handleMoveCard(MoveCard mc) {
game.Logger.C_MOVE_DESTROY);
break;
case LIBRARY:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("Illegal move");
case TOP_LIBRARY:
g.changeLibrarySize(mc.requestor, 1);
g.log(mc.cardID, false, g.getPlayerName(mc.requestor)
@@ -528,9 +560,22 @@ public void send(Action object) {
oos.writeObject(object);
oos.flush();
} catch (IOException ex) {
Debug.p("Error while sending " + object + " to server: "
Debug.p("Client: Error while sending " + object + " to server: "
+ ex, Debug.E);
}
}

/**
* Sends <code>Disconnect</code>, closes sockets
* and restores main menu frame
*/
void closeClient() {
this.interrupt();
try {
send(new Disconnect(-1, true));
s.close();
} catch (IOException ex1) {}
parentFrame.setVisible(true);
}

}
Oops, something went wrong.

0 comments on commit ee00995

Please sign in to comment.