added tournaments - drafts are now a variant of tournament

This commit is contained in:
BetaSteward 2011-02-06 11:09:25 -05:00
parent 78e60ce457
commit ffc7b5bfd8
88 changed files with 3768 additions and 311 deletions

View file

@ -75,6 +75,7 @@ import java.util.prefs.Preferences;
import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener; import javax.swing.event.PopupMenuListener;
import mage.client.draft.DraftPane; import mage.client.draft.DraftPane;
import mage.client.tournament.TournamentPane;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -155,6 +156,14 @@ public class MageFrame extends javax.swing.JFrame {
e1.printStackTrace(); e1.printStackTrace();
} }
tournamentPane = new TournamentPane();
desktopPane.add(tournamentPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
try {
tournamentPane.setMaximum(true);
} catch (java.beans.PropertyVetoException e1) {
e1.printStackTrace();
}
addTooltipContainer(); addTooltipContainer();
setBackground(); setBackground();
addMageLabel(); addMageLabel();
@ -407,6 +416,12 @@ public class MageFrame extends javax.swing.JFrame {
this.draftPane.showDraft(draftId); this.draftPane.showDraft(draftId);
} }
public void showTournament(UUID tournamentId) {
this.tournamentPane.setVisible(true);
this.tournamentPane.toFront();
this.tournamentPane.showTournament(tournamentId);
}
public static boolean connect(String userName, String serverName, int port) { public static boolean connect(String userName, String serverName, int port) {
return session.connect(userName, serverName, port); return session.connect(userName, serverName, port);
} }
@ -746,6 +761,7 @@ public class MageFrame extends javax.swing.JFrame {
private static final long serialVersionUID = -9104885239063142218L; private static final long serialVersionUID = -9104885239063142218L;
private ImagePanel backgroundPane; private ImagePanel backgroundPane;
private DraftPane draftPane; private DraftPane draftPane;
private TournamentPane tournamentPane;
public void setStatusText(String status) { public void setStatusText(String status) {
this.lblStatus.setText(status); this.lblStatus.setText(status);

View file

@ -1,6 +1,29 @@
/* /*
* To change this template, choose Tools | Templates * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
* and open the template in the editor. *
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/ */
/* /*
@ -14,11 +37,9 @@ package mage.client.cards;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.UUID;
import mage.cards.CardDimensions; import mage.cards.CardDimensions;
import mage.cards.MageCard; import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
import mage.client.util.Config; import mage.client.util.Config;
import mage.view.CardView; import mage.view.CardView;
@ -97,13 +118,6 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
/*if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume();
Object obj = e.getSource();
if (obj instanceof MageCard) {
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
}
}*/
} }
@Override @Override

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues> <AuxValues>

View file

@ -35,13 +35,9 @@
package mage.client.dialog; package mage.client.dialog;
import java.awt.Cursor; import java.awt.Cursor;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.Config; import mage.client.util.Config;
import mage.util.Logging; import mage.util.Logging;
@ -212,9 +208,6 @@ public class ConnectDialog extends MageDialog {
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected())); MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
this.setVisible(false); this.setVisible(false);
} }
else {
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server");
}
} }
finally { finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

View file

@ -0,0 +1,210 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="New Tournament"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlPacks" alignment="1" pref="525" max="32767" attributes="0"/>
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" pref="113" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbTournamentType" pref="408" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cbTournamentType" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="pnlPacks" pref="47" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="spnNumPlayers" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Tournament Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbTournamentType">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbTournamentTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JSpinner" name="spnNumPlayers">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Players:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnOk">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOkActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlPacks">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="1"/>
<Property name="horizontalGap" type="int" value="2"/>
<Property name="rows" type="int" value="0"/>
</Layout>
</Container>
<Container class="javax.swing.JPanel" name="jPanel1">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="pnlOtherPlayers" alignment="0" pref="525" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="445" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPlayer1Name" pref="490" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPlayer1Name" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" pref="58" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Player 1 (You)"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPlayer1Name">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlOtherPlayers">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="1"/>
<Property name="horizontalGap" type="int" value="2"/>
<Property name="rows" type="int" value="0"/>
</Layout>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Packs"/>
</Properties>
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,359 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* NewTournamentDialog.java
*
* Created on Jan 28, 2011, 12:15:56 PM
*/
package mage.client.dialog;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence;
import mage.cards.ExpansionSet;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.table.TournamentPlayerPanel;
import mage.game.draft.DraftOptions;
import mage.game.tournament.TournamentOptions;
import mage.sets.Sets;
import mage.util.Logging;
import mage.view.TableView;
import mage.view.TournamentTypeView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class NewTournamentDialog extends MageDialog {
private final static Logger logger = Logging.getLogger(NewTournamentDialog.class.getName());
private TableView table;
private UUID playerId;
private UUID roomId;
private Session session;
private List<TournamentPlayerPanel> players = new ArrayList<TournamentPlayerPanel>();
private List<JComboBox> packs = new ArrayList<JComboBox>();
/** Creates new form NewTournamentDialog */
public NewTournamentDialog() {
initComponents();
}
public void showDialog(UUID roomId) {
this.roomId = roomId;
session = MageFrame.getSession();
this.txtPlayer1Name.setText(session.getUserName());
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
this.setModal(true);
setTournamentOptions();
this.setLocation(150, 100);
this.setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbTournamentType = new javax.swing.JComboBox();
spnNumPlayers = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
btnOk = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
pnlPacks = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtPlayer1Name = new javax.swing.JTextField();
pnlOtherPlayers = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
setTitle("New Tournament");
jLabel1.setText("Tournament Type:");
cbTournamentType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbTournamentType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbTournamentTypeActionPerformed(evt);
}
});
spnNumPlayers.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spnNumPlayersStateChanged(evt);
}
});
jLabel2.setText("Players:");
btnOk.setText("OK");
btnOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOkActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
pnlPacks.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("Player 1 (You)");
jLabel4.setText("Name:");
txtPlayer1Name.setEditable(false);
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))
);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Packs");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlPacks, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbTournamentType, 0, 408, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel5))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbTournamentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3)
.addComponent(jLabel5)
.addGap(1, 1, 1)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(19, 19, 19)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnOk))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cbTournamentTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTournamentTypeActionPerformed
setTournamentOptions();
}//GEN-LAST:event_cbTournamentTypeActionPerformed
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
TournamentOptions tOptions = new TournamentOptions(tournamentType.getName());
tOptions.setTournamentType(tournamentType.getName());
tOptions.getPlayerTypes().add("Human");
for (TournamentPlayerPanel player: players) {
tOptions.getPlayerTypes().add(player.getPlayerType());
}
if (tournamentType.isDraft()) {
tOptions.getDraftOptions().setDraftType("");
tOptions.getDraftOptions().setTiming(DraftOptions.TimingOption.REGULAR);
for (JComboBox pack: packs) {
tOptions.getDraftOptions().getSets().add((ExpansionSet) pack.getSelectedItem());
}
}
tOptions.getMatchOptions().setDeckType("Limited");
tOptions.getMatchOptions().setWinsNeeded(2);
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
table = session.createTournamentTable(roomId, tOptions);
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText())) {
for (TournamentPlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {
if (!player.joinTournamentTable(roomId, table.getTableId())) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
this.setVisible(false);
return;
}
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.table = null;
this.playerId = null;
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void spnNumPlayersStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumPlayersStateChanged
int numPlayers = (Integer)this.spnNumPlayers.getValue() - 1;
createPlayers(numPlayers);
}//GEN-LAST:event_spnNumPlayersStateChanged
private void setTournamentOptions() {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
this.spnNumPlayers.setModel(new SpinnerNumberModel(tournamentType.getMinPlayers(), tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
createPlayers(tournamentType.getMinPlayers() - 1);
createPacks(tournamentType.getNumBoosters());
}
private void createPacks(int numPacks) {
while (packs.size() < numPacks) {
JComboBox pack = new JComboBox();
pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray()));
pnlPacks.add(pack);
packs.add(pack);
}
this.pack();
this.revalidate();
this.repaint();
}
private void createPlayers(int numPlayers) {
if (numPlayers > players.size()) {
while (players.size() != numPlayers) {
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
playerPanel.init(players.size() + 2);
players.add(playerPanel);
}
}
else if (numPlayers < players.size()) {
while (players.size() != numPlayers) {
players.remove(players.size() - 1);
}
}
drawPlayers();
}
private void drawPlayers() {
this.pnlOtherPlayers.removeAll();
for (TournamentPlayerPanel panel: players) {
this.pnlOtherPlayers.add(panel);
}
this.pack();
this.revalidate();
this.repaint();
}
public TableView getTable() {
return table;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOk;
private javax.swing.JComboBox cbTournamentType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel pnlOtherPlayers;
private javax.swing.JPanel pnlPacks;
private javax.swing.JSpinner spnNumPlayers;
private javax.swing.JTextField txtPlayer1Name;
// End of variables declaration//GEN-END:variables
}

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo"> <Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties> <Properties>
@ -39,7 +39,7 @@
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="jSplitPane1" pref="247" max="32767" attributes="0"/> <Component id="jSplitPane1" pref="251" max="32767" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/> <EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="btnMoveDown" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMoveDown" alignment="3" min="-2" max="-2" attributes="0"/>

View file

@ -60,6 +60,7 @@ public class TableWaitingDialog extends MageDialog implements Observer {
private UUID tableId; private UUID tableId;
private UUID roomId; private UUID roomId;
private boolean isTournament;
private Session session; private Session session;
private TableWaitModel tableWaitModel; private TableWaitModel tableWaitModel;
private SeatsWatchdog seatsWatchdog = new SeatsWatchdog(); private SeatsWatchdog seatsWatchdog = new SeatsWatchdog();
@ -105,9 +106,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
} }
} }
public void showDialog(UUID roomId, UUID tableId) { public void showDialog(UUID roomId, UUID tableId, boolean isTournament) {
this.roomId = roomId; this.roomId = roomId;
this.tableId = tableId; this.tableId = tableId;
this.isTournament = isTournament;
session = MageFrame.getSession(); session = MageFrame.getSession();
if (session.isTableOwner(roomId, tableId)) { if (session.isTableOwner(roomId, tableId)) {
this.btnStart.setVisible(true); this.btnStart.setVisible(true);
@ -235,7 +237,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
closeDialog(); closeDialog();
session.startGame(roomId, tableId); if (!isTournament)
session.startGame(roomId, tableId);
else
session.startTournament(roomId, tableId);
}//GEN-LAST:event_btnStartActionPerformed }//GEN-LAST:event_btnStartActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed

View file

@ -86,6 +86,10 @@ public class Client implements CallbackClient {
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId()); GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
gameStarted(message.getGameId(), message.getPlayerId()); gameStarted(message.getGameId(), message.getPlayerId());
} }
else if(callback.getMethod().equals("startTournament")) {
TableClientMessage message = (TableClientMessage) callback.getData();
tournamentStarted(message.getGameId(), message.getPlayerId());
}
else if(callback.getMethod().equals("startDraft")) { else if(callback.getMethod().equals("startDraft")) {
TableClientMessage message = (TableClientMessage) callback.getData(); TableClientMessage message = (TableClientMessage) callback.getData();
draftStarted(message.getGameId(), message.getPlayerId()); draftStarted(message.getGameId(), message.getPlayerId());
@ -171,6 +175,9 @@ public class Client implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData(); TableClientMessage message = (TableClientMessage) callback.getData();
construct(message.getDeck(), message.getTableId()); construct(message.getDeck(), message.getTableId());
} }
else if (callback.getMethod().equals("draftOver")) {
session.getDraft().hideDraft();
}
else if (callback.getMethod().equals("draftPick")) { else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData(); DraftClientMessage message = (DraftClientMessage) callback.getData();
session.getDraft().loadBooster(message.getDraftPickView()); session.getDraft().loadBooster(message.getDraftPickView());
@ -189,6 +196,9 @@ public class Client implements CallbackClient {
else if (callback.getMethod().equals("draftInit")) { else if (callback.getMethod().equals("draftInit")) {
session.ack("draftInit"); session.ack("draftInit");
} }
else if (callback.getMethod().equals("tournamentInit")) {
session.ack("tournamentInit");
}
messageId = callback.getMessageId(); messageId = callback.getMessageId();
} }
catch (Exception ex) { catch (Exception ex) {
@ -202,7 +212,7 @@ public class Client implements CallbackClient {
return clientId; return clientId;
} }
protected void gameStarted(UUID gameId, UUID playerId) { protected void gameStarted(final UUID gameId, final UUID playerId) {
try { try {
frame.showGame(gameId, playerId); frame.showGame(gameId, playerId);
logger.info("Game " + gameId + " started for player " + playerId); logger.info("Game " + gameId + " started for player " + playerId);
@ -226,6 +236,16 @@ public class Client implements CallbackClient {
} }
} }
protected void tournamentStarted(UUID tournamentId, UUID playerId) {
try {
frame.showTournament(tournamentId);
logger.info("Tournament " + tournamentId + " started for player " + playerId);
}
catch (Exception ex) {
handleException(ex);
}
}
protected void watchGame(UUID gameId) { protected void watchGame(UUID gameId) {
try { try {
frame.watchGame(gameId); frame.watchGame(gameId);

View file

@ -46,17 +46,20 @@ import mage.client.chat.ChatPanel;
import mage.client.components.MageUI; import mage.client.components.MageUI;
import mage.client.draft.DraftPanel; import mage.client.draft.DraftPanel;
import mage.client.game.GamePanel; import mage.client.game.GamePanel;
import mage.client.tournament.TournamentPanel;
import mage.client.util.Config; import mage.client.util.Config;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions;
import mage.interfaces.MageException; import mage.interfaces.MageException;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.Server; import mage.interfaces.Server;
import mage.interfaces.ServerState; import mage.interfaces.ServerState;
import mage.interfaces.callback.CallbackClientDaemon; import mage.interfaces.callback.CallbackClientDaemon;
import mage.util.Logging; import mage.util.Logging;
import mage.view.GameTypeView; import mage.view.GameTypeView;
import mage.view.TableView; import mage.view.TableView;
import mage.view.TournamentTypeView;
import mage.view.TournamentView;
/** /**
* *
@ -75,6 +78,7 @@ public class Session {
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>(); private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private GamePanel game; private GamePanel game;
private DraftPanel draft; private DraftPanel draft;
private TournamentPanel tournament;
private CallbackClientDaemon callbackDaemon; private CallbackClientDaemon callbackDaemon;
private MageUI ui = new MageUI(); private MageUI ui = new MageUI();
@ -101,6 +105,7 @@ public class Session {
return true; return true;
} catch (MageException ex) { } catch (MageException ex) {
logger.log(Level.SEVERE, null, ex); logger.log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (RemoteException ex) { } catch (RemoteException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex); logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
} catch (NotBoundException ex) { } catch (NotBoundException ex) {
@ -156,6 +161,10 @@ public class Session {
return serverState.getDeckTypes(); return serverState.getDeckTypes();
} }
public List<TournamentTypeView> getTournamentTypes() {
return serverState.getTournamentTypes();
}
public boolean isTestMode() { public boolean isTestMode() {
return serverState.isTestMode(); return serverState.isTestMode();
} }
@ -180,6 +189,10 @@ public class Session {
draft = draftPanel; draft = draftPanel;
} }
public void setTournament(TournamentPanel tournament) {
this.tournament = tournament;
}
public UUID getMainRoomId() { public UUID getMainRoomId() {
try { try {
return server.getMainRoomId(); return server.getMainRoomId();
@ -272,9 +285,9 @@ public class Session {
return false; return false;
} }
public boolean joinDraftTable(UUID roomId, UUID tableId, String playerName) { public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName) {
try { try {
return server.joinDraftTable(sessionId, roomId, tableId, playerName); return server.joinTournamentTable(sessionId, roomId, tableId, playerName);
} catch (RemoteException ex) { } catch (RemoteException ex) {
handleRemoteException(ex); handleRemoteException(ex);
} catch (MageException ex) { } catch (MageException ex) {
@ -297,6 +310,29 @@ public class Session {
} }
} }
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
try {
return server.getTournament(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
throw new MageRemoteException();
} catch (MageException ex) {
handleMageException(ex);
throw new MageRemoteException();
}
}
public UUID getTournamentChatId(UUID tournamentId) {
try {
return server.getTournamentChatId(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean sendPlayerUUID(UUID gameId, UUID data) { public boolean sendPlayerUUID(UUID gameId, UUID data) {
try { try {
server.sendPlayerUUID(gameId, sessionId, data); server.sendPlayerUUID(gameId, sessionId, data);
@ -419,6 +455,18 @@ public class Session {
return false; return false;
} }
public boolean joinTournament(UUID tournamentId) {
try {
server.joinTournament(tournamentId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean watchGame(UUID gameId) { public boolean watchGame(UUID gameId) {
try { try {
server.watchGame(gameId, sessionId); server.watchGame(gameId, sessionId);
@ -454,9 +502,9 @@ public class Session {
return null; return null;
} }
public TableView createDraftTable(UUID roomId, DraftOptions draftOptions) { public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
try { try {
return server.createDraftTable(sessionId, roomId, draftOptions); return server.createTournamentTable(sessionId, roomId, tournamentOptions);
} catch (RemoteException ex) { } catch (RemoteException ex) {
handleRemoteException(ex); handleRemoteException(ex);
} catch (MageException ex) { } catch (MageException ex) {
@ -524,9 +572,9 @@ public class Session {
return false; return false;
} }
public boolean startDraft(UUID roomId, UUID tableId) { public boolean startTournament(UUID roomId, UUID tableId) {
try { try {
server.startDraft(sessionId, roomId, tableId); server.startTournament(sessionId, roomId, tableId);
return true; return true;
} catch (RemoteException ex) { } catch (RemoteException ex) {
handleRemoteException(ex); handleRemoteException(ex);
@ -650,4 +698,5 @@ public class Session {
public MageUI getUI() { public MageUI getUI() {
return ui; return ui;
} }
} }

View file

@ -34,30 +34,15 @@
package mage.client.table; package mage.client.table;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.deck.generator.DeckGenerator; import mage.client.deck.generator.DeckGenerator;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.gui.ColorsChooser;
import mage.sets.Sets;
/** /**
* *
@ -119,8 +104,8 @@ public class NewPlayerPanel extends javax.swing.JPanel {
* always regenerated by the Form Editor. * always regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">
// </editor-fold>//GEN-END:initComponents // </editor-fold>
private void initComponents() { private void initComponents() {
lblPlayerName = new javax.swing.JLabel(); lblPlayerName = new javax.swing.JLabel();

View file

@ -40,10 +40,10 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnNewTable" min="-2" max="-2" attributes="0"/> <Component id="btnNewTable" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/> <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<Component id="btnNewDraft" min="-2" max="-2" attributes="0"/> <Component id="btnNewTournament" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnQuickStart" min="-2" max="-2" attributes="0"/> <Component id="btnQuickStart" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="450" max="32767" attributes="0"/> <EmptySpace pref="416" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -54,7 +54,7 @@
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="btnNewTable" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnNewTable" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnQuickStart" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnQuickStart" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnNewDraft" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnNewTournament" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace pref="16" max="32767" attributes="0"/> <EmptySpace pref="16" max="32767" attributes="0"/>
</Group> </Group>
@ -78,12 +78,12 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuickStartActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuickStartActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="btnNewDraft"> <Component class="javax.swing.JButton" name="btnNewTournament">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="New Draft"/> <Property name="text" type="java.lang.String" value="New Tournament"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewDraftActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewTournamentActionPerformed"/>
</Events> </Events>
</Component> </Component>
</SubComponents> </SubComponents>

View file

@ -58,6 +58,9 @@ import java.awt.event.ActionListener;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.client.dialog.NewTournamentDialog;
import mage.game.draft.DraftOptions;
import mage.game.tournament.TournamentOptions;
/** /**
@ -73,6 +76,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private TablesWatchdog tablesWatchdog = new TablesWatchdog(); private TablesWatchdog tablesWatchdog = new TablesWatchdog();
private JoinTableDialog joinTableDialog; private JoinTableDialog joinTableDialog;
private NewTableDialog newTableDialog; private NewTableDialog newTableDialog;
private NewTournamentDialog newTournamentDialog;
private TableWaitingDialog tableWaitingDialog; private TableWaitingDialog tableWaitingDialog;
private Session session; private Session session;
@ -99,7 +103,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
joinTableDialog.showDialog(roomId, tableId); joinTableDialog.showDialog(roomId, tableId);
if (joinTableDialog.isJoined()) if (joinTableDialog.isJoined())
tableWaitingDialog.showDialog(roomId, tableId); tableWaitingDialog.showDialog(roomId, tableId, false);
} else if (state.equals("Watch")) { } else if (state.equals("Watch")) {
logger.info("Watching table " + tableId); logger.info("Watching table " + tableId);
if (!session.watchTable(roomId, tableId)) if (!session.watchTable(roomId, tableId))
@ -152,6 +156,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
newTableDialog = new NewTableDialog(); newTableDialog = new NewTableDialog();
MageFrame.getDesktop().add(newTableDialog); MageFrame.getDesktop().add(newTableDialog);
} }
if (newTournamentDialog == null) {
newTournamentDialog = new NewTournamentDialog();
MageFrame.getDesktop().add(newTournamentDialog);
}
if (joinTableDialog == null) { if (joinTableDialog == null) {
joinTableDialog = new JoinTableDialog(); joinTableDialog = new JoinTableDialog();
MageFrame.getDesktop().add(joinTableDialog); MageFrame.getDesktop().add(joinTableDialog);
@ -201,7 +209,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
jPanel1 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel();
btnNewTable = new javax.swing.JButton(); btnNewTable = new javax.swing.JButton();
btnQuickStart = new javax.swing.JButton(); btnQuickStart = new javax.swing.JButton();
btnNewDraft = new javax.swing.JButton(); btnNewTournament = new javax.swing.JButton();
jSplitPane1 = new javax.swing.JSplitPane(); jSplitPane1 = new javax.swing.JSplitPane();
chatPanel = new mage.client.chat.ChatPanel(); chatPanel = new mage.client.chat.ChatPanel();
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
@ -221,14 +229,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
} }
}); });
btnNewDraft.setText("New Draft"); btnNewTournament.setText("New Tournament");
btnNewDraft.addActionListener(new java.awt.event.ActionListener() { btnNewTournament.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNewDraftActionPerformed(evt); btnNewTournamentActionPerformed(evt);
} }
}); });
//FIXME: removed on released 0.6 version
btnNewDraft.setVisible(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout); jPanel1.setLayout(jPanel1Layout);
@ -238,10 +244,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
.addContainerGap() .addContainerGap()
.addComponent(btnNewTable) .addComponent(btnNewTable)
.addGap(6, 6, 6) .addGap(6, 6, 6)
.addComponent(btnNewDraft) .addComponent(btnNewTournament)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnQuickStart) .addComponent(btnQuickStart)
.addContainerGap(450, Short.MAX_VALUE)) .addContainerGap(416, Short.MAX_VALUE))
); );
jPanel1Layout.setVerticalGroup( jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -250,7 +256,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnNewTable) .addComponent(btnNewTable)
.addComponent(btnQuickStart) .addComponent(btnQuickStart)
.addComponent(btnNewDraft)) .addComponent(btnNewTournament))
.addContainerGap(16, Short.MAX_VALUE)) .addContainerGap(16, Short.MAX_VALUE))
); );
@ -284,7 +290,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private void btnNewTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTableActionPerformed private void btnNewTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTableActionPerformed
newTableDialog.showDialog(roomId); newTableDialog.showDialog(roomId);
if (newTableDialog.getTable() != null) { if (newTableDialog.getTable() != null) {
tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId()); tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId(), false);
} }
}//GEN-LAST:event_btnNewTableActionPerformed }//GEN-LAST:event_btnNewTableActionPerformed
@ -318,9 +324,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
} }
}//GEN-LAST:event_btnQuickStartActionPerformed }//GEN-LAST:event_btnQuickStartActionPerformed
private void btnNewDraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewDraftActionPerformed private void btnNewTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTournamentActionPerformed
newTournamentDialog.showDialog(roomId);
}//GEN-LAST:event_btnNewDraftActionPerformed if (newTournamentDialog.getTable() != null) {
tableWaitingDialog.showDialog(roomId, newTournamentDialog.getTable().getTableId(), true);
}
}//GEN-LAST:event_btnNewTournamentActionPerformed
private void handleError(Exception ex) { private void handleError(Exception ex) {
logger.log(Level.SEVERE, "Error loading deck", ex); logger.log(Level.SEVERE, "Error loading deck", ex);
@ -329,8 +338,8 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnNewDraft;
private javax.swing.JButton btnNewTable; private javax.swing.JButton btnNewTable;
private javax.swing.JButton btnNewTournament;
private javax.swing.JButton btnQuickStart; private javax.swing.JButton btnQuickStart;
private mage.client.chat.ChatPanel chatPanel; private mage.client.chat.ChatPanel chatPanel;
private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel1;

View file

@ -0,0 +1,105 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblPlayerNum" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbPlayerType" min="-2" pref="175" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlPlayerName" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="2" attributes="0">
<Component id="lblPlayerNum" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="cbPlayerType" alignment="2" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pnlPlayerName" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="cbPlayerType"/>
</Property>
<Property name="text" type="java.lang.String" value="Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbPlayerType">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbPlayerTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblPlayerNum">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Player Num:"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlPlayerName">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPlayerName" pref="189" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPlayerName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="txtPlayerName">
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,168 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* TournamentPlayerPanel.java
*
* Created on Jan 28, 2011, 1:50:29 PM
*/
package mage.client.table;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import mage.client.MageFrame;
import mage.client.remote.Session;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayerPanel extends javax.swing.JPanel {
private Session session;
/** Creates new form TournamentPlayerPanel */
public TournamentPlayerPanel() {
initComponents();
this.pnlPlayerName.setVisible(false);
}
public void init(int playerNum) {
session = MageFrame.getSession();
cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes()));
this.lblPlayerNum.setText("Player " + playerNum);
}
public String getPlayerType() {
return (String) this.cbPlayerType.getSelectedItem();
}
public boolean joinTournamentTable(UUID roomId, UUID tableId) {
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
return session.joinTournamentTable(roomId, tableId, this.txtPlayerName.getText());
}
return true;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbPlayerType = new javax.swing.JComboBox();
lblPlayerNum = new javax.swing.JLabel();
pnlPlayerName = new javax.swing.JPanel();
txtPlayerName = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel1.setLabelFor(cbPlayerType);
jLabel1.setText("Type:");
cbPlayerType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbPlayerType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbPlayerTypeActionPerformed(evt);
}
});
lblPlayerNum.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblPlayerNum.setText("Player Num:");
jLabel2.setText("Name:");
javax.swing.GroupLayout pnlPlayerNameLayout = new javax.swing.GroupLayout(pnlPlayerName);
pnlPlayerName.setLayout(pnlPlayerNameLayout);
pnlPlayerNameLayout.setHorizontalGroup(
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPlayerNameLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
);
pnlPlayerNameLayout.setVerticalGroup(
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblPlayerNum)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(lblPlayerNum)
.addComponent(jLabel1)
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(pnlPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
}// </editor-fold>//GEN-END:initComponents
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
this.pnlPlayerName.setVisible(true);
if (this.txtPlayerName.getText().length() == 0) {
this.txtPlayerName.setText("Computer " + this.lblPlayerNum.getText());
}
}
else {
this.pnlPlayerName.setVisible(false);
}
this.revalidate();
this.repaint();
}//GEN-LAST:event_cbPlayerTypeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox cbPlayerType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lblPlayerNum;
private javax.swing.JPanel pnlPlayerName;
private javax.swing.JTextField txtPlayerName;
// End of variables declaration//GEN-END:variables
}

View file

@ -0,0 +1,35 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="tournamentPanel1" alignment="0" pref="758" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="tournamentPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="mage.client.tournament.TournamentPanel" name="tournamentPanel1">
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,87 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* TournamentPane.java
*
* Created on 22-Jan-2011, 11:41:47 PM
*/
package mage.client.tournament;
import java.util.UUID;
import mage.client.MagePane;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPane extends MagePane {
/** Creates new form TournamentPane */
public TournamentPane() {
initComponents();
}
public void showTournament(UUID tournamentId) {
this.setTitle("Tournament " + tournamentId);
this.tournamentPanel1.showTournament(tournamentId);
this.repaint();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
tournamentPanel1 = new mage.client.tournament.TournamentPanel();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.tournament.TournamentPanel tournamentPanel1;
// End of variables declaration//GEN-END:variables
}

View file

@ -0,0 +1,76 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jScrollPane1" pref="573" max="32767" attributes="2"/>
<Component id="jScrollPane2" alignment="1" pref="573" max="32767" attributes="2"/>
</Group>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="chatPanel1" min="-2" pref="215" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="jScrollPane1" min="-2" pref="262" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="jScrollPane2" pref="260" max="32767" attributes="0"/>
</Group>
<Component id="chatPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="mage.client.chat.ChatPanel" name="chatPanel1">
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tablePlayers">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="this.playersModel" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tableMatches">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="matchesModel" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,300 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* TournamentPanel.java
*
* Created on 20-Jan-2011, 9:18:30 PM
*/
package mage.client.tournament;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.UUID;
import javax.swing.Timer;
import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame;
import mage.client.remote.MageRemoteException;
import mage.client.remote.Session;
import mage.view.RoundView;
import mage.view.TournamentGameView;
import mage.view.TournamentPlayerView;
import mage.view.TournamentView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPanel extends javax.swing.JPanel implements Observer {
private UUID tournamentId;
private Session session;
private TournamentPlayersTableModel playersModel;
private TournamentMatchesTableModel matchesModel;
private TournamentWatchdog tournamentWatchdog = new TournamentWatchdog();
/** Creates new form TournamentPanel */
public TournamentPanel() {
playersModel = new TournamentPlayersTableModel();
matchesModel = new TournamentMatchesTableModel();
initComponents();
tablePlayers.createDefaultColumnsFromModel();
tableMatches.createDefaultColumnsFromModel();
}
public synchronized void showTournament(UUID tournamentId) {
this.tournamentId = tournamentId;
session = MageFrame.getSession();
session.setTournament(this);
UUID chatRoomId = session.getTournamentChatId(tournamentId);
if (session.joinTournament(tournamentId) && chatRoomId != null) {
this.chatPanel1.connect(chatRoomId);
tournamentWatchdog.addObserver(this);
this.setVisible(true);
this.repaint();
}
else {
hideTournament();
}
}
public void hideTournament() {
this.setVisible(false);
}
@Override
public void update(Observable arg0, Object arg1) {
TournamentView tournament;
try {
tournament = MageFrame.getSession().getTournament(tournamentId);
playersModel.loadData(tournament);
matchesModel.loadData(tournament);
this.tablePlayers.repaint();
this.tableMatches.repaint();
} catch (MageRemoteException ex) {
hideTournament();
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
chatPanel1 = new mage.client.chat.ChatPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tablePlayers = new javax.swing.JTable();
jScrollPane2 = new javax.swing.JScrollPane();
tableMatches = new javax.swing.JTable();
tablePlayers.setModel(this.playersModel);
jScrollPane1.setViewportView(tablePlayers);
tableMatches.setModel(matchesModel);
jScrollPane2.setViewportView(tableMatches);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE))
.addGap(0, 0, 0)
.addComponent(chatPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addComponent(chatPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.chat.ChatPanel chatPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable tableMatches;
private javax.swing.JTable tablePlayers;
// End of variables declaration//GEN-END:variables
}
class TournamentPlayersTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Player Name", "Points", "Results"};
private TournamentPlayerView[] players = new TournamentPlayerView[0];
public void loadData(TournamentView tournament) {
players = tournament.getPlayers().toArray(new TournamentPlayerView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return players.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return players[arg0].getName();
case 1:
return Integer.toString(players[arg0].getPoints());
case 2:
return players[arg0].getResults();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
colName = columnNames[columnIndex];
return colName;
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
class TournamentMatchesTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Round Number", "Players", "Match Id", "Game Id", "State", "Result"};
private TournamentGameView[] games = new TournamentGameView[0];
public void loadData(TournamentView tournament) {
List<TournamentGameView> views = new ArrayList<TournamentGameView>();
for (RoundView round: tournament.getRounds()) {
for (TournamentGameView game: round.getGames()) {
views.add(game);
}
}
games = views.toArray(new TournamentGameView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return games.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return Integer.toString(games[arg0].getRoundNum());
case 1:
return games[arg0].getPlayers();
case 2:
return games[arg0].getMatchId().toString();
case 3:
return games[arg0].getGameId().toString();
case 4:
return games[arg0].getState();
case 5:
return games[arg0].getResult();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
colName = columnNames[columnIndex];
return colName;
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
class TournamentWatchdog extends Observable implements ActionListener {
Timer t = new Timer(1000, this); // check every second
public TournamentWatchdog() {
t.start();
}
@Override
public void actionPerformed(ActionEvent arg0) {
setChanged();
notifyObservers();
}
}

View file

@ -35,10 +35,11 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions; import mage.game.tournament.TournamentOptions;
import mage.interfaces.callback.CallbackServer; import mage.interfaces.callback.CallbackServer;
import mage.view.TableView; import mage.view.TableView;
import mage.view.GameView; import mage.view.GameView;
import mage.view.TournamentView;
/** /**
* *
@ -54,9 +55,9 @@ public interface Server extends Remote, CallbackServer {
//table methods //table methods
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException; public TableView createTable(UUID sessionId, UUID roomId, MatchOptions matchOptions) throws RemoteException, MageException;
public TableView createDraftTable(UUID sessionId, UUID roomId, DraftOptions draftOptions) throws RemoteException, MageException; public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions tournamentOptions) throws RemoteException, MageException;
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws RemoteException, MageException, GameException; public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, String name, DeckCardLists deckList) throws RemoteException, MageException, GameException;
public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException; public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws RemoteException, MageException, GameException;
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException; public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException;
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException; public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
@ -74,6 +75,7 @@ public interface Server extends Remote, CallbackServer {
public UUID getTableChatId(UUID tableId) throws RemoteException, MageException; public UUID getTableChatId(UUID tableId) throws RemoteException, MageException;
public UUID getGameChatId(UUID gameId) throws RemoteException, MageException; public UUID getGameChatId(UUID gameId) throws RemoteException, MageException;
public UUID getRoomChatId(UUID roomId) throws RemoteException, MageException; public UUID getRoomChatId(UUID roomId) throws RemoteException, MageException;
public UUID getTournamentChatId(UUID tournamentId) throws RemoteException, MageException;
//room methods //room methods
public UUID getMainRoomId() throws RemoteException, MageException; public UUID getMainRoomId() throws RemoteException, MageException;
@ -89,8 +91,12 @@ public interface Server extends Remote, CallbackServer {
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException; public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException;
public void concedeGame(UUID gameId, UUID sessionId) throws RemoteException, MageException; public void concedeGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
//tournament methods
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
public void joinTournament(UUID draftId, UUID sessionId) throws RemoteException, MageException;
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException;
//draft methods //draft methods
public void startDraft(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException; public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException; public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;

View file

@ -31,6 +31,7 @@ package mage.interfaces;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import mage.view.GameTypeView; import mage.view.GameTypeView;
import mage.view.TournamentTypeView;
/** /**
* *
@ -39,12 +40,14 @@ import mage.view.GameTypeView;
public class ServerState implements Serializable { public class ServerState implements Serializable {
private List<GameTypeView> gameTypes; private List<GameTypeView> gameTypes;
private List<TournamentTypeView> tournamentTypes;
private String[] playerTypes; private String[] playerTypes;
private String[] deckTypes; private String[] deckTypes;
private boolean testMode; private boolean testMode;
public ServerState(List<GameTypeView> gameTypes, String[] playerTypes, String[] deckTypes, boolean testMode) { public ServerState(List<GameTypeView> gameTypes, List<TournamentTypeView> tournamentTypes, String[] playerTypes, String[] deckTypes, boolean testMode) {
this.gameTypes = gameTypes; this.gameTypes = gameTypes;
this.tournamentTypes = tournamentTypes;
this.playerTypes = playerTypes; this.playerTypes = playerTypes;
this.deckTypes = deckTypes; this.deckTypes = deckTypes;
this.testMode = testMode; this.testMode = testMode;
@ -54,6 +57,10 @@ public class ServerState implements Serializable {
return gameTypes; return gameTypes;
} }
public List<TournamentTypeView> getTournamentTypes() {
return tournamentTypes;
}
public String[] getPlayerTypes() { public String[] getPlayerTypes() {
return playerTypes; return playerTypes;
} }

View file

@ -47,6 +47,10 @@ public class ClientCallback implements Serializable {
this.data = data; this.data = data;
} }
public ClientCallback(String method) {
this(method, null);
}
public void clear() { public void clear() {
method = null; method = null;
data = null; data = null;

View file

@ -29,7 +29,11 @@
package mage.view; package mage.view;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.game.Game;
import mage.game.tournament.Round; import mage.game.tournament.Round;
import mage.game.tournament.TournamentPairing;
/** /**
* *
@ -38,8 +42,20 @@ import mage.game.tournament.Round;
public class RoundView implements Serializable { public class RoundView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public RoundView(Round round) { List<TournamentGameView> games = new ArrayList<TournamentGameView>();
public RoundView(Round round) {
for (TournamentPairing pair: round.getPairs()) {
if (pair.getMatch() != null) {
for (Game game: pair.getMatch().getGames()) {
games.add(new TournamentGameView(round.getRoundNumber(), pair, game));
}
}
}
}
public List<TournamentGameView> getGames() {
return games;
} }
} }

View file

@ -0,0 +1,89 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.io.Serializable;
import java.util.UUID;
import mage.game.Game;
import mage.game.tournament.TournamentPairing;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentGameView implements Serializable {
private static final long serialVersionUID = 1L;
private int roundNum;
private UUID matchId;
private UUID gameId;
private String state;
private String result;
private String players;
TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
this.roundNum = roundNum;
this.matchId = pair.getMatch().getId();
this.gameId = game.getId();
this.players = pair.getPlayer1().getPlayer().getName() + " " + pair.getPlayer2().getPlayer().getName();
if (game.isGameOver()) {
this.state = "Finished";
this.result = game.getWinner();
}
else {
this.state = "Dueling";
this.result = "";
}
}
public int getRoundNum() {
return roundNum;
}
public UUID getMatchId() {
return this.matchId;
}
public UUID getGameId() {
return this.gameId;
}
public String getState() {
return this.state;
}
public String getResult() {
return this.result;
}
public String getPlayers() {
return this.players;
}
}

View file

@ -29,6 +29,10 @@
package mage.view; package mage.view;
import java.io.Serializable; import java.io.Serializable;
import mage.game.tournament.Round;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentPairing;
import mage.game.tournament.TournamentPlayer;
/** /**
* *
@ -37,4 +41,25 @@ import java.io.Serializable;
public class TournamentPlayerView implements Serializable { public class TournamentPlayerView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name;
private String results;
private int points;
TournamentPlayerView(TournamentPlayer player) {
this.name = player.getPlayer().getName();
this.points = player.getPoints();
this.results = player.getResults();
}
public String getName() {
return this.name;
}
public int getPoints() {
return this.points;
}
public String getResults() {
return results;
}
} }

View file

@ -0,0 +1,79 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.io.Serializable;
import mage.game.tournament.TournamentType;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentTypeView implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private int minPlayers;
private int maxPlayers;
private int numBoosters;
private boolean draft;
public TournamentTypeView(TournamentType tournamentType) {
this.name = tournamentType.getName();
this.minPlayers = tournamentType.getMinPlayers();
this.maxPlayers = tournamentType.getMaxPlayers();
this.numBoosters = tournamentType.getNumBoosters();
this.draft = tournamentType.isDraft();
}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public int getMinPlayers() {
return minPlayers;
}
public int getMaxPlayers() {
return maxPlayers;
}
public int getNumBoosters() {
return numBoosters;
}
public boolean isDraft() {
return draft;
}
}

View file

@ -31,7 +31,9 @@ package mage.view;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import mage.game.tournament.Round;
import mage.game.tournament.Tournament; import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentPlayer;
/** /**
* *
@ -41,8 +43,22 @@ public class TournamentView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
List<RoundView> rounds = new ArrayList<RoundView>(); List<RoundView> rounds = new ArrayList<RoundView>();
List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
public TournamentView(Tournament tournament) { public TournamentView(Tournament tournament) {
for (TournamentPlayer player: tournament.getPlayers()) {
players.add(new TournamentPlayerView(player));
}
for (Round round: tournament.getRounds()) {
rounds.add(new RoundView(round));
}
}
public List<TournamentPlayerView> getPlayers() {
return players;
}
public List<RoundView> getRounds() {
return rounds;
} }
} }

View file

@ -35,7 +35,7 @@ import mage.game.match.MatchOptions;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class FreeForAllMatch extends MatchImpl<FreeForAll> { public class FreeForAllMatch extends MatchImpl {
public FreeForAllMatch(MatchOptions options) { public FreeForAllMatch(MatchOptions options) {
super(options); super(options);

View file

@ -35,7 +35,7 @@ import mage.game.match.MatchOptions;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class TwoPlayerMatch extends MatchImpl<TwoPlayerDuel> { public class TwoPlayerMatch extends MatchImpl {
public TwoPlayerMatch(MatchOptions options) { public TwoPlayerMatch(MatchOptions options) {
super(options); super(options);

View file

@ -0,0 +1,51 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mage</groupId>
<artifactId>Mage-Server-Plugins</artifactId>
<version>0.6</version>
</parent>
<artifactId>Mage-Tournament-BoosterDraft</artifactId>
<packaging>jar</packaging>
<name>Mage Tournament Booster Draft</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Mage</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>mage-tournament-booster-draft</finalName>
</build>
<properties/>
</project>

View file

@ -0,0 +1,90 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.tournament;
import mage.game.draft.BoosterDraft;
import mage.game.draft.Draft;
import mage.game.events.TableEvent.EventType;
import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentPlayer;
import mage.game.tournament.TournamentSingleElimination;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class BoosterDraftEliminationTournament extends TournamentSingleElimination {
protected enum TournamentStep {
START, DRAFT, CONSTRUCT, COMPETE, WINNERS
}
protected TournamentStep currentStep;
public BoosterDraftEliminationTournament(TournamentOptions options) {
super(options);
currentStep = TournamentStep.START;
}
protected void draft() {
Draft draft = new BoosterDraft(options.getDraftOptions());
for (TournamentPlayer player: players.values()) {
draft.addPlayer(player.getPlayer());
}
tableEventSource.fireTableEvent(EventType.START_DRAFT, null, draft);
}
protected void winners() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void nextStep() {
switch (currentStep) {
case START:
currentStep = TournamentStep.DRAFT;
draft();
break;
case DRAFT:
currentStep = TournamentStep.CONSTRUCT;
construct();
break;
case CONSTRUCT:
currentStep = TournamentStep.COMPETE;
runTournament();
break;
case COMPETE:
currentStep = TournamentStep.WINNERS;
winners();
break;
}
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.tournament;
import mage.game.tournament.TournamentType;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class BoosterDraftEliminationTournamentType extends TournamentType<BoosterDraftEliminationTournamentType> {
public BoosterDraftEliminationTournamentType() {
this.name = "Elimination Booster Draft";
this.maxPlayers = 16;
this.minPlayers = 4;
this.numBoosters = 3;
this.draft = true;
}
}

View file

@ -0,0 +1,5 @@
#Generated by Maven
#Sun Feb 06 08:07:38 EST 2011
version=0.6
groupId=org.mage
artifactId=Mage-Tournament-BoosterDraft

View file

@ -22,7 +22,7 @@
<module>Mage.Player.AI</module> <module>Mage.Player.AI</module>
<module>Mage.Player.AIMinimax</module> <module>Mage.Player.AIMinimax</module>
<module>Mage.Player.Human</module> <module>Mage.Player.Human</module>
<module>Mage.Draft.8PlayerBooster</module> <module>Mage.Tournament.BoosterDraft</module>
</modules> </modules>
</project> </project>

View file

@ -12,9 +12,9 @@
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/> <gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/> <gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
</gameTypes> </gameTypes>
<draftTypes> <tournamentTypes>
<draftType name="8 Player Booster" jar="mage-draft-8playerbooster.jar" className="mage.draft.BoosterDraft"/> <tournamentType name="Elimination Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
</draftTypes> </tournamentTypes>
<deckTypes> <deckTypes>
<deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/> <deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/>
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/> <deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>

Binary file not shown.

View file

@ -34,7 +34,6 @@ import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.util.Logging; import mage.util.Logging;

View file

@ -36,10 +36,11 @@ import java.net.InetAddress;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.game.match.MatchType; import mage.game.match.MatchType;
import mage.game.tournament.TournamentType;
import mage.server.game.DeckValidatorFactory; import mage.server.game.DeckValidatorFactory;
import mage.server.game.DraftFactory;
import mage.server.game.GameFactory; import mage.server.game.GameFactory;
import mage.server.game.PlayerFactory; import mage.server.game.PlayerFactory;
import mage.server.tournament.TournamentFactory;
import mage.server.util.ConfigSettings; import mage.server.util.ConfigSettings;
import mage.server.util.config.Plugin; import mage.server.util.config.Plugin;
import mage.server.util.config.GamePlugin; import mage.server.util.config.GamePlugin;
@ -73,8 +74,8 @@ public class Main {
for (GamePlugin plugin: config.getGameTypes()) { for (GamePlugin plugin: config.getGameTypes()) {
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin)); GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
} }
for (Plugin plugin: config.getDraftTypes()) { for (GamePlugin plugin: config.getTournamentTypes()) {
DraftFactory.getInstance().addDraftType(plugin.getName(), loadPlugin(plugin)); TournamentFactory.getInstance().addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
} }
for (Plugin plugin: config.getPlayerTypes()) { for (Plugin plugin: config.getPlayerTypes()) {
PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin)); PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
@ -136,6 +137,19 @@ public class Main {
return null; return null;
} }
private static TournamentType loadTournamentType(GamePlugin plugin) {
try {
classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL());
logger.info("Loading tournament type: " + plugin.getClassName());
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "Tournament type not found:" + plugin.getJar() + " - check plugin folder");
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
}
return null;
}
private static void deleteSavedGames() { private static void deleteSavedGames() {
File directory = new File("saved/"); File directory = new File("saved/");
if (!directory.exists()) if (!directory.exists())

View file

@ -26,7 +26,7 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server;
import java.rmi.Remote; import java.rmi.Remote;
import java.util.UUID; import java.util.UUID;

View file

@ -26,7 +26,7 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server;
import java.util.UUID; import java.util.UUID;
import mage.server.ChatManager; import mage.server.ChatManager;

View file

@ -41,25 +41,27 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions;
import mage.interfaces.MageException; import mage.interfaces.MageException;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.Server; import mage.interfaces.Server;
import mage.interfaces.ServerState; import mage.interfaces.ServerState;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.server.game.DeckValidatorFactory; import mage.server.game.DeckValidatorFactory;
import mage.server.game.DraftManager; import mage.server.draft.DraftManager;
import mage.server.game.GameFactory; import mage.server.game.GameFactory;
import mage.server.game.GameManager; import mage.server.game.GameManager;
import mage.server.game.GamesRoomManager; import mage.server.game.GamesRoomManager;
import mage.server.game.PlayerFactory; import mage.server.game.PlayerFactory;
import mage.server.game.ReplayManager; import mage.server.game.ReplayManager;
import mage.server.game.TableManager; import mage.server.tournament.TournamentFactory;
import mage.server.tournament.TournamentManager;
import mage.server.util.ThreadExecutor; import mage.server.util.ThreadExecutor;
import mage.util.Logging; import mage.util.Logging;
import mage.view.ChatMessage.MessageColor; import mage.view.ChatMessage.MessageColor;
import mage.view.GameView; import mage.view.GameView;
import mage.view.TableView; import mage.view.TableView;
import mage.view.TournamentView;
/** /**
* *
@ -130,10 +132,10 @@ public class ServerImpl extends RemoteServer implements Server {
} }
@Override @Override
public TableView createDraftTable(UUID sessionId, UUID roomId, DraftOptions options) throws MageException { public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions options) throws MageException {
try { try {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createDraftTable(sessionId, options); TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
logger.info("Draft table " + table.getTableId() + " created"); logger.log(Level.INFO, "Tournament table {0} created", table.getTableId());
return table; return table;
} }
catch (Exception ex) { catch (Exception ex) {
@ -175,9 +177,9 @@ public class ServerImpl extends RemoteServer implements Server {
} }
@Override @Override
public boolean joinDraftTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException { public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name) throws MageException, GameException {
try { try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinDraftTable(sessionId, tableId, name); boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name);
logger.info("Session " + sessionId + " joined table " + tableId); logger.info("Session " + sessionId + " joined table " + tableId);
return ret; return ret;
} }
@ -262,13 +264,13 @@ public class ServerImpl extends RemoteServer implements Server {
} }
@Override @Override
public void startDraft(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException { public void startTournament(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
try { try {
rmiExecutor.execute( rmiExecutor.execute(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
TableManager.getInstance().startDraft(sessionId, roomId, tableId); TableManager.getInstance().startTournament(sessionId, roomId, tableId);
} }
} }
); );
@ -278,6 +280,17 @@ public class ServerImpl extends RemoteServer implements Server {
} }
} }
@Override
public TournamentView getTournament(UUID tournamentId) throws RemoteException, MageException {
try {
return TournamentManager.getInstance().getTournamentView(tournamentId);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override @Override
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException { public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
try { try {
@ -441,6 +454,23 @@ public class ServerImpl extends RemoteServer implements Server {
} }
} }
@Override
public void joinTournament(final UUID tournamentId, final UUID sessionId) throws MageException {
try {
rmiExecutor.execute(
new Runnable() {
@Override
public void run() {
TournamentManager.getInstance().joinTournament(tournamentId, sessionId);
}
}
);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override @Override
public UUID getGameChatId(UUID gameId) throws MageException { public UUID getGameChatId(UUID gameId) throws MageException {
try { try {
@ -452,6 +482,17 @@ public class ServerImpl extends RemoteServer implements Server {
return null; return null;
} }
@Override
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
try {
return TournamentManager.getInstance().getChatId(tournamentId);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override @Override
public void sendPlayerUUID(final UUID gameId, final UUID sessionId, final UUID data) throws MageException { public void sendPlayerUUID(final UUID gameId, final UUID sessionId, final UUID data) throws MageException {
try { try {
@ -683,6 +724,7 @@ public class ServerImpl extends RemoteServer implements Server {
try { try {
return new ServerState( return new ServerState(
GameFactory.getInstance().getGameTypes(), GameFactory.getInstance().getGameTypes(),
TournamentFactory.getInstance().getTournamentTypes(),
PlayerFactory.getInstance().getPlayerTypes().toArray(new String[0]), PlayerFactory.getInstance().getPlayerTypes().toArray(new String[0]),
DeckValidatorFactory.getInstance().getDeckTypes().toArray(new String[0]), DeckValidatorFactory.getInstance().getDeckTypes().toArray(new String[0]),
testMode); testMode);
@ -722,7 +764,7 @@ public class ServerImpl extends RemoteServer implements Server {
public void handleException(Exception ex) throws MageException { public void handleException(Exception ex) throws MageException {
logger.log(Level.SEVERE, "", ex); logger.log(Level.SEVERE, "", ex);
throw new MageException("Server error"); throw new MageException("Server error: " + ex.getMessage());
} }
public GameView getGameView(final UUID gameId, final UUID sessionId, final UUID playerId) { public GameView getGameView(final UUID gameId, final UUID sessionId, final UUID playerId) {

View file

@ -35,7 +35,6 @@ import mage.cards.decks.Deck;
import mage.interfaces.callback.CallbackServerSession; import mage.interfaces.callback.CallbackServerSession;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.server.game.GameManager; import mage.server.game.GameManager;
import mage.server.game.TableManager;
import mage.util.Logging; import mage.util.Logging;
import mage.view.TableClientMessage; import mage.view.TableClientMessage;
@ -99,6 +98,10 @@ public class Session {
fireCallback(new ClientCallback("startDraft", new TableClientMessage(draftId, playerId))); fireCallback(new ClientCallback("startDraft", new TableClientMessage(draftId, playerId)));
} }
public void tournamentStarted(final UUID tournamentId, final UUID playerId) {
fireCallback(new ClientCallback("startTournament", new TableClientMessage(tournamentId, playerId)));
}
public void sideboard(final Deck deck, final UUID tableId) { public void sideboard(final Deck deck, final UUID tableId) {
fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId))); fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId)));
} }

View file

@ -30,6 +30,7 @@ package mage.server;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.MageException;
/** /**
* *
@ -49,15 +50,25 @@ public class SessionManager {
return sessions.get(sessionId); return sessions.get(sessionId);
} }
public UUID createSession(String userName, UUID clientId) { public UUID createSession(String userName, UUID clientId) throws MageException {
Session session = new Session(userName, clientId); if (!isNameUsed(userName)) {
sessions.put(session.getId(), session); Session session = new Session(userName, clientId);
return session.getId(); sessions.put(session.getId(), session);
return session.getId();
}
throw new MageException("User name already in use");
} }
public void removeSession(UUID sessionId) { public void removeSession(UUID sessionId) {
sessions.remove(sessionId); sessions.remove(sessionId);
} }
private boolean isNameUsed(String name) {
for (Session session: sessions.values()) {
if (session.getUsername().equals(name))
return true;
}
return false;
}
} }

View file

@ -26,8 +26,11 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server;
import mage.server.draft.DraftManager;
import mage.server.tournament.TournamentFactory;
import mage.server.tournament.TournamentManager;
import mage.game.Table; import mage.game.Table;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -56,16 +59,24 @@ import mage.game.GameStates;
import mage.game.match.Match; import mage.game.match.Match;
import mage.game.Seat; import mage.game.Seat;
import mage.game.draft.Draft; import mage.game.draft.Draft;
import mage.game.draft.DraftOptions;
import mage.game.draft.DraftPlayer; import mage.game.draft.DraftPlayer;
import mage.game.events.Listener; import mage.game.events.Listener;
import mage.game.events.TableEvent; import mage.game.events.TableEvent;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.match.MatchPlayer; import mage.game.match.MatchPlayer;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentPlayer;
import mage.players.Player; import mage.players.Player;
import mage.server.ChatManager; import mage.server.ChatManager;
import mage.server.Main; import mage.server.Main;
import mage.server.SessionManager; import mage.server.SessionManager;
import mage.server.game.DeckValidatorFactory;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.GameReplay;
import mage.server.game.PlayerFactory;
import mage.server.game.ReplayManager;
import mage.util.CopierObjectInputStream; import mage.util.CopierObjectInputStream;
import mage.util.Logging; import mage.util.Logging;
@ -82,8 +93,8 @@ public class TableController {
private Table table; private Table table;
private Match match; private Match match;
private MatchOptions options; private MatchOptions options;
private Draft draft; private Tournament tournament;
private DraftOptions draftOptions; private TournamentOptions tournamentOptions;
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>(); private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
public TableController(UUID sessionId, MatchOptions options) { public TableController(UUID sessionId, MatchOptions options) {
@ -95,12 +106,12 @@ public class TableController {
init(); init();
} }
public TableController(UUID sessionId, DraftOptions options) { public TableController(UUID sessionId, TournamentOptions options) {
this.sessionId = sessionId; this.sessionId = sessionId;
chatId = ChatManager.getInstance().createChatSession(); chatId = ChatManager.getInstance().createChatSession();
this.draftOptions = options; this.tournamentOptions = options;
draft = DraftFactory.getInstance().createDraft(options.getDraftType(), options); tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
table = new Table(options.getDraftType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator("Limited"), options.getPlayerTypes()); table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes());
init(); init();
} }
@ -125,7 +136,7 @@ public class TableController {
); );
} }
public synchronized boolean joinDraft(UUID sessionId, String name) throws GameException { public synchronized boolean joinTournament(UUID sessionId, String name) throws GameException {
if (table.getState() != TableState.WAITING) { if (table.getState() != TableState.WAITING) {
return false; return false;
} }
@ -134,7 +145,7 @@ public class TableController {
throw new GameException("No available seats."); throw new GameException("No available seats.");
} }
Player player = createPlayer(name, seat.getPlayerType()); Player player = createPlayer(name, seat.getPlayerType());
draft.addPlayer(player); tournament.addPlayer(player, seat.getPlayerType());
table.joinTable(player, seat); table.joinTable(player, seat);
logger.info("player joined " + player.getId()); logger.info("player joined " + player.getId());
//only add human players to sessionPlayerMap //only add human players to sessionPlayerMap
@ -170,6 +181,21 @@ public class TableController {
return true; return true;
} }
public void addPlayer(UUID sessionId, Player player, Deck deck) throws GameException {
if (table.getState() != TableState.WAITING) {
return;
}
Seat seat = table.getNextAvailableSeat();
if (seat == null) {
throw new GameException("No available seats.");
}
match.addPlayer(player, deck);
table.joinTable(player, seat);
if (player.isHuman()) {
sessionPlayerMap.put(sessionId, player.getId());
}
}
public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException { public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException {
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) { if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
return false; return false;
@ -180,7 +206,7 @@ public class TableController {
playerName = player.getPlayer().getName(); playerName = player.getPlayer().getName();
} }
else { else {
DraftPlayer player = draft.getPlayer(sessionPlayerMap.get(sessionId)); TournamentPlayer player = tournament.getPlayer(sessionPlayerMap.get(sessionId));
playerName = player.getPlayer().getName(); playerName = player.getPlayer().getName();
} }
Deck deck = Deck.load(deckList); Deck deck = Deck.load(deckList);
@ -196,9 +222,8 @@ public class TableController {
MatchPlayer player = match.getPlayer(playerId); MatchPlayer player = match.getPlayer(playerId);
player.submitDeck(deck); player.submitDeck(deck);
} }
else if (table.getState() == TableState.CONSTRUCTING) { else {
DraftPlayer player = draft.getPlayer(playerId); tournament.submitDeck(playerId, deck);
player.submitDeck(deck);
} }
} }
@ -267,17 +292,25 @@ public class TableController {
} }
} }
public synchronized void startDraft(UUID sessionId) { public synchronized void startTournament(UUID sessionId) {
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) { if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
table.initDraft(); TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId());
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
SessionManager sessionManager = SessionManager.getInstance(); SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) { for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue()); sessionManager.getSession(entry.getKey()).tournamentStarted(tournament.getId(), entry.getValue());
} }
} }
} }
public void startDraft(Draft draft) {
table.initDraft();
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
}
}
private void sideboard() { private void sideboard() {
table.sideboard(); table.sideboard();
for (MatchPlayer player: match.getPlayers()) { for (MatchPlayer player: match.getPlayers()) {
@ -297,13 +330,12 @@ public class TableController {
} }
} }
private void construct() { public void construct() {
table.construct(); table.construct();
for (DraftPlayer player: draft.getPlayers()) { for (TournamentPlayer player: tournament.getPlayers()) {
player.setConstructing(); player.setConstructing();
player.getPlayer().construct(table, player.getDeck()); player.getPlayer().construct(table, player.getDeck());
} }
while (!draft.isDoneConstructing()){}
} }
private void construct(UUID playerId, Deck deck) { private void construct(UUID playerId, Deck deck) {
@ -332,9 +364,11 @@ public class TableController {
} }
} }
public void endDraft() { public void endDraft(Draft draft) {
construct(); for (DraftPlayer player: draft.getPlayers()) {
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
}
tournament.nextStep();
} }
public void swapSeats(int seatNum1, int seatNum2) { public void swapSeats(int seatNum1, int seatNum2) {
@ -405,4 +439,7 @@ public class TableController {
return chatId; return chatId;
} }
public Match getMatch() {
return match;
}
} }

View file

@ -26,17 +26,22 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server;
import mage.game.Table; import mage.game.Table;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions; import mage.game.draft.Draft;
import mage.game.match.Match;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.players.Player;
import mage.server.game.GameReplay;
import mage.util.Logging; import mage.util.Logging;
/** /**
@ -62,7 +67,7 @@ public class TableManager {
return tableController.getTable(); return tableController.getTable();
} }
public Table createDraftTable(UUID sessionId, DraftOptions options) { public Table createTournamentTable(UUID sessionId, TournamentOptions options) {
TableController tableController = new TableController(sessionId, options); TableController tableController = new TableController(sessionId, options);
controllers.put(tableController.getTable().getId(), tableController); controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable()); tables.put(tableController.getTable().getId(), tableController.getTable());
@ -73,6 +78,10 @@ public class TableManager {
return tables.get(tableId); return tables.get(tableId);
} }
public Match getMatch(UUID tableId) {
return controllers.get(tableId).getMatch();
}
public Collection<Table> getTables() { public Collection<Table> getTables() {
return tables.values(); return tables.values();
} }
@ -81,8 +90,8 @@ public class TableManager {
return controllers.get(tableId).joinTable(sessionId, name, deckList); return controllers.get(tableId).joinTable(sessionId, name, deckList);
} }
public boolean joinDraft(UUID sessionId, UUID tableId, String name) throws GameException { public boolean joinTournament(UUID sessionId, UUID tableId, String name) throws GameException {
return controllers.get(tableId).joinDraft(sessionId, name); return controllers.get(tableId).joinTournament(sessionId, name);
} }
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException { public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
@ -118,8 +127,12 @@ public class TableManager {
controllers.get(tableId).startMatch(sessionId); controllers.get(tableId).startMatch(sessionId);
} }
public void startDraft(UUID sessionId, UUID roomId, UUID tableId) { public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
controllers.get(tableId).startDraft(sessionId); controllers.get(tableId).startTournament(sessionId);
}
public void startDraft(UUID tableId, Draft draft) {
controllers.get(tableId).startDraft(draft);
} }
public boolean watchTable(UUID sessionId, UUID tableId) { public boolean watchTable(UUID sessionId, UUID tableId) {
@ -134,8 +147,8 @@ public class TableManager {
controllers.get(tableId).endGame(); controllers.get(tableId).endGame();
} }
public void endDraft(UUID tableId) { public void endDraft(UUID tableId, Draft draft) {
controllers.get(tableId).endDraft(); controllers.get(tableId).endDraft(draft);
} }
public GameReplay createReplay(UUID tableId) { public GameReplay createReplay(UUID tableId) {
@ -147,4 +160,12 @@ public class TableManager {
controllers.get(tableId).swapSeats(seatNum1, seatNum2); controllers.get(tableId).swapSeats(seatNum1, seatNum2);
} }
} }
public void construct(UUID tableId) {
controllers.get(tableId).construct();
}
public void addPlayer(UUID sessionId, UUID tableId, Player player, Deck deck) throws GameException {
controllers.get(tableId).addPlayer(sessionId, player, deck);
}
} }

View file

@ -26,13 +26,12 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server.draft;
import java.io.File; import java.io.File;
import java.util.UUID; import java.util.UUID;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.game.draft.Draft; import mage.game.draft.Draft;
@ -40,11 +39,11 @@ import mage.game.draft.DraftPlayer;
import mage.game.events.Listener; import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent; import mage.game.events.PlayerQueryEvent;
import mage.game.events.TableEvent; import mage.game.events.TableEvent;
import mage.server.ChatManager; import mage.server.game.GameController;
import mage.server.TableManager;
import mage.server.util.ThreadExecutor; import mage.server.util.ThreadExecutor;
import mage.util.Logging; import mage.util.Logging;
import mage.view.DraftPickView; import mage.view.DraftPickView;
import mage.view.ChatMessage.MessageColor;
import mage.view.DraftView; import mage.view.DraftView;
/** /**
@ -60,13 +59,11 @@ public class DraftController {
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap; private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
private UUID draftSessionId; private UUID draftSessionId;
private Draft draft; private Draft draft;
private UUID chatId;
private UUID tableId; private UUID tableId;
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) { public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
draftSessionId = UUID.randomUUID(); draftSessionId = UUID.randomUUID();
this.sessionPlayerMap = sessionPlayerMap; this.sessionPlayerMap = sessionPlayerMap;
chatId = ChatManager.getInstance().createChatSession();
this.draft = draft; this.draft = draft;
this.tableId = tableId; this.tableId = tableId;
init(); init();
@ -100,6 +97,13 @@ public class DraftController {
} }
} }
); );
for (DraftPlayer player: draft.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.info("player " + player.getPlayer().getId() + " has joined draft " + draft.getId());
}
}
checkStart();
} }
private UUID getPlayerId(UUID sessionId) { private UUID getPlayerId(UUID sessionId) {
@ -111,16 +115,8 @@ public class DraftController {
DraftSession draftSession = new DraftSession(draft, sessionId, playerId); DraftSession draftSession = new DraftSession(draft, sessionId, playerId);
draftSessions.put(playerId, draftSession); draftSessions.put(playerId, draftSession);
logger.info("player " + playerId + " has joined draft " + draft.getId()); logger.info("player " + playerId + " has joined draft " + draft.getId());
ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(playerId).getPlayer().getName() + " has joined the draft", MessageColor.BLACK); draft.getPlayer(playerId).setJoined();
if (allJoined()) { checkStart();
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startDraft();
}
});
}
} }
private synchronized void startDraft() { private synchronized void startDraft() {
@ -134,7 +130,21 @@ public class DraftController {
draft.start(); draft.start();
} }
private void checkStart() {
if (allJoined()) {
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startDraft();
}
});
}
}
private boolean allJoined() { private boolean allJoined() {
if (!draft.allJoined())
return false;
for (DraftPlayer player: draft.getPlayers()) { for (DraftPlayer player: draft.getPlayers()) {
if (player.getPlayer().isHuman() && draftSessions.get(player.getPlayer().getId()) == null) { if (player.getPlayer().isHuman() && draftSessions.get(player.getPlayer().getId()) == null) {
return false; return false;
@ -148,7 +158,10 @@ public class DraftController {
} }
private void endDraft() { private void endDraft() {
TableManager.getInstance().endDraft(tableId); for (final DraftSession draftSession: draftSessions.values()) {
draftSession.draftOver();
}
TableManager.getInstance().endDraft(tableId, draft);
} }
public void kill(UUID sessionId) { public void kill(UUID sessionId) {
@ -162,26 +175,15 @@ public class DraftController {
public void timeout(UUID sessionId) { public void timeout(UUID sessionId) {
if (sessionPlayerMap.containsKey(sessionId)) { if (sessionPlayerMap.containsKey(sessionId)) {
ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(sessionPlayerMap.get(sessionId)).getPlayer().getName() + " has timed out. Auto picking.", MessageColor.BLACK); // ChatManager.getInstance().broadcast(chatId, "", draft.getPlayer(sessionPlayerMap.get(sessionId)).getPlayer().getName() + " has timed out. Auto picking.", MessageColor.BLACK);
draft.autoPick(sessionPlayerMap.get(sessionId)); draft.autoPick(sessionPlayerMap.get(sessionId));
} }
} }
public void endDraft(final String message) {
for (final DraftSession draftSession: draftSessions.values()) {
draftSession.gameOver(message);
}
TableManager.getInstance().endDraft(tableId);
}
public UUID getSessionId() { public UUID getSessionId() {
return this.draftSessionId; return this.draftSessionId;
} }
public UUID getChatId() {
return chatId;
}
public void sendCardPick(UUID sessionId, UUID cardId) { public void sendCardPick(UUID sessionId, UUID cardId) {
draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId); draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId);
} }

View file

@ -26,7 +26,7 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server.draft;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -61,10 +61,6 @@ public class DraftManager {
draftControllers.remove(gameId); draftControllers.remove(gameId);
} }
public UUID getChatId(UUID draftId) {
return draftControllers.get(draftId).getChatId();
}
public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) { public void sendCardPick(UUID draftId, UUID sessionId, UUID cardId) {
draftControllers.get(draftId).sendCardPick(sessionId, cardId); draftControllers.get(draftId).sendCardPick(sessionId, cardId);
} }

View file

@ -26,7 +26,7 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server.draft;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.UUID; import java.util.UUID;
@ -44,7 +44,6 @@ import mage.util.Logging;
import mage.view.DraftClientMessage; import mage.view.DraftClientMessage;
import mage.view.DraftPickView; import mage.view.DraftPickView;
import mage.view.DraftView; import mage.view.DraftView;
import mage.view.GameClientMessage;
/** /**
* *
@ -52,7 +51,7 @@ import mage.view.GameClientMessage;
*/ */
public class DraftSession { public class DraftSession {
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName()); protected final static Logger logger = Logging.getLogger(DraftSession.class.getName());
protected UUID sessionId; protected UUID sessionId;
protected UUID playerId; protected UUID playerId;
@ -105,11 +104,11 @@ public class DraftSession {
} }
} }
public void gameOver(final String message) { public void draftOver() {
if (!killed) { if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId); Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) if (session != null)
session.fireCallback(new ClientCallback("gameOver", message)); session.fireCallback(new ClientCallback("draftOver"));
} }
} }

View file

@ -28,6 +28,7 @@
package mage.server.game; package mage.server.game;
import mage.server.TableManager;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
@ -43,7 +44,6 @@ import java.util.regex.Pattern;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
@ -153,6 +153,12 @@ public class GameController implements GameCallback {
} }
} }
); );
for (Player player: game.getPlayers().values()) {
if (!player.isHuman()) {
ChatManager.getInstance().broadcast(chatId, "", player.getName() + " has joined the game", MessageColor.BLACK);
}
}
checkStart();
} }
private UUID getPlayerId(UUID sessionId) { private UUID getPlayerId(UUID sessionId) {
@ -165,15 +171,7 @@ public class GameController implements GameCallback {
gameSessions.put(playerId, gameSession); gameSessions.put(playerId, gameSession);
logger.info("player " + playerId + " has joined game " + game.getId()); logger.info("player " + playerId + " has joined game " + game.getId());
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK); ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK);
if (allJoined()) { checkStart();
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startGame();
}
});
}
} }
private synchronized void startGame() { private synchronized void startGame() {
@ -190,6 +188,18 @@ public class GameController implements GameCallback {
} }
} }
private void checkStart() {
if (allJoined()) {
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startGame();
}
});
}
}
private boolean allJoined() { private boolean allJoined() {
for (Player player: game.getPlayers().values()) { for (Player player: game.getPlayers().values()) {
if (player.isHuman() && gameSessions.get(player.getId()) == null) { if (player.isHuman() && gameSessions.get(player.getId()) == null) {

View file

@ -117,11 +117,11 @@ public class GameManager {
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName); return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
} }
void timeout(UUID gameId, UUID sessionId) { public void timeout(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).timeout(sessionId); gameControllers.get(gameId).timeout(sessionId);
} }
void removeGame(UUID gameId) { public void removeGame(UUID gameId) {
gameControllers.remove(gameId); gameControllers.remove(gameId);
} }

View file

@ -28,12 +28,13 @@
package mage.server.game; package mage.server.game;
import mage.server.Room;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.view.TableView; import mage.view.TableView;
/** /**
@ -44,9 +45,9 @@ public interface GamesRoom extends Room {
public List<TableView> getTables(); public List<TableView> getTables();
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException; public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException;
public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException; public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException;
public TableView createTable(UUID sessionId, MatchOptions options); public TableView createTable(UUID sessionId, MatchOptions options);
public TableView createDraftTable(UUID sessionId, DraftOptions options); public TableView createTournamentTable(UUID sessionId, TournamentOptions options);
public void removeTable(UUID sessionId, UUID tableId); public void removeTable(UUID sessionId, UUID tableId);
public TableView getTable(UUID tableId); public TableView getTable(UUID tableId);
public void leaveTable(UUID sessionId, UUID tableId); public void leaveTable(UUID sessionId, UUID tableId);

View file

@ -28,6 +28,8 @@
package mage.server.game; package mage.server.game;
import mage.server.TableManager;
import mage.server.RoomImpl;
import mage.game.Table; import mage.game.Table;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,6 +41,7 @@ import mage.cards.decks.DeckCardLists;
import mage.game.GameException; import mage.game.GameException;
import mage.game.draft.DraftOptions; import mage.game.draft.DraftOptions;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.util.Logging; import mage.util.Logging;
import mage.view.TableView; import mage.view.TableView;
@ -78,17 +81,17 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
} }
@Override @Override
public boolean joinDraftTable(UUID sessionId, UUID tableId, String name) throws GameException { public boolean joinTournamentTable(UUID sessionId, UUID tableId, String name) throws GameException {
if (tables.containsKey(tableId)) { if (tables.containsKey(tableId)) {
return TableManager.getInstance().joinDraft(sessionId, tableId, name); return TableManager.getInstance().joinTournament(sessionId, tableId, name);
} else { } else {
return false; return false;
} }
} }
@Override @Override
public TableView createDraftTable(UUID sessionId, DraftOptions options) { public TableView createTournamentTable(UUID sessionId, TournamentOptions options) {
Table table = TableManager.getInstance().createDraftTable(sessionId, options); Table table = TableManager.getInstance().createTournamentTable(sessionId, options);
tables.put(table.getId(), table); tables.put(table.getId(), table);
return new TableView(table); return new TableView(table);
} }

View file

@ -28,6 +28,7 @@
package mage.server.game; package mage.server.game;
import mage.server.TableManager;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;
import mage.game.Game; import mage.game.Game;

View file

@ -0,0 +1,214 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.tournament;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.GameException;
import mage.game.Table;
import mage.game.draft.Draft;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.game.match.MatchOptions;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentPairing;
import mage.game.tournament.TournamentPlayer;
import mage.server.ChatManager;
import mage.server.TableManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.ChatMessage.MessageColor;
import mage.view.TournamentView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentController {
private final static Logger logger = Logging.getLogger(TournamentController.class.getName());
private UUID sessionId;
private UUID chatId;
private UUID tableId;
private Tournament tournament;
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
sessionId = UUID.randomUUID();
this.sessionPlayerMap = sessionPlayerMap;
chatId = ChatManager.getInstance().createChatSession();
this.tournament = tournament;
this.tableId = tableId;
init();
}
private void init() {
tournament.addTableEventListener(
new Listener<TableEvent> () {
@Override
public void event(TableEvent event) {
switch (event.getEventType()) {
case INFO:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK);
logger.finest(tournament.getId() + " " + event.getMessage());
break;
case CONSTRUCT:
construct();
break;
case START_DRAFT:
startDraft(event.getDraft());
break;
case START_MATCH:
startMatch(event.getPair(), event.getMatchOptions());
break;
}
}
}
);
for (TournamentPlayer player: tournament.getPlayers()) {
if (!player.getPlayer().isHuman()) {
player.setJoined();
logger.info("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has joined the tournament", MessageColor.BLACK);
}
}
checkStart();
}
public void join(UUID sessionId) {
UUID playerId = sessionPlayerMap.get(sessionId);
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, playerId);
tournamentSessions.put(playerId, tournamentSession);
TournamentPlayer player = tournament.getPlayer(playerId);
player.setJoined();
logger.info("player " + playerId + " has joined tournament " + tournament.getId());
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has joined the tournament", MessageColor.BLACK);
checkStart();
}
private void checkStart() {
if (allJoined()) {
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startTournament();
}
});
}
}
private boolean allJoined() {
if (!tournament.allJoined())
return false;
for (TournamentPlayer player: tournament.getPlayers()) {
if (player.getPlayer().isHuman() && tournamentSessions.get(player.getPlayer().getId()) == null) {
return false;
}
}
return true;
}
private synchronized void startTournament() {
for (final Entry<UUID, TournamentSession> entry: tournamentSessions.entrySet()) {
if (!entry.getValue().init(getTournamentView())) {
logger.severe("Unable to initialize client");
//TODO: generate client error message
return;
}
}
tournament.nextStep();
}
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
try {
TableManager tableManager = TableManager.getInstance();
Table table = tableManager.createTable(sessionId, matchOptions);
TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2();
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getDeck());
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getDeck());
tableManager.startMatch(sessionId, null, table.getId());
pair.setMatch(tableManager.getMatch(table.getId()));
} catch (GameException ex) {
Logger.getLogger(TournamentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void startDraft(Draft draft) {
TableManager.getInstance().startDraft(tableId, draft);
}
private void construct() {
TableManager.getInstance().construct(tableId);
}
public UUID getSessionId() {
return this.sessionId;
}
public UUID getChatId() {
return chatId;
}
public void kill(UUID sessionId) {
if (sessionPlayerMap.containsKey(sessionId)) {
tournamentSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
tournamentSessions.remove(sessionPlayerMap.get(sessionId));
leave(sessionId);
sessionPlayerMap.remove(sessionId);
}
}
private void leave(UUID sessionId) {
tournament.leave(getPlayerId(sessionId));
}
private UUID getPlayerId(UUID sessionId) {
return sessionPlayerMap.get(sessionId);
}
private UUID getPlayerSessionId(UUID playerId) {
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
if (entry.getValue().equals(playerId))
return entry.getKey();
}
return null;
}
public TournamentView getTournamentView() {
return new TournamentView(tournament);
}
}

View file

@ -0,0 +1,91 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.tournament;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentType;
import mage.util.Logging;
import mage.view.TournamentTypeView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentFactory {
private final static TournamentFactory INSTANCE = new TournamentFactory();
private final static Logger logger = Logging.getLogger(TournamentFactory.class.getName());
private Map<String, Class<Tournament>> tournaments = new HashMap<String, Class<Tournament>>();
private Map<String, TournamentType> tournamentTypes = new HashMap<String, TournamentType>();
private List<TournamentTypeView> tournamentTypeViews = new ArrayList<TournamentTypeView>();
public static TournamentFactory getInstance() {
return INSTANCE;
}
private TournamentFactory() {}
public Tournament createTournament(String tournamentType, TournamentOptions options) {
Tournament tournament;
Constructor<Tournament> con;
try {
con = tournaments.get(tournamentType).getConstructor(new Class[]{TournamentOptions.class});
tournament = con.newInstance(new Object[] {options});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
return null;
}
logger.info("Tournament created: " + tournamentType); // + game.getId().toString());
return tournament;
}
public List<TournamentTypeView> getTournamentTypes() {
return tournamentTypeViews;
}
public void addTournamentType(String name, TournamentType tournamentType, Class tournament) {
if (tournament != null) {
this.tournaments.put(name, tournament);
this.tournamentTypes.put(name, tournamentType);
this.tournamentTypeViews.add(new TournamentTypeView(tournamentType));
}
}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
@ -26,54 +26,47 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server.game; package mage.server.tournament;
import java.lang.reflect.Constructor; import java.util.UUID;
import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.Map; import mage.game.tournament.Tournament;
import java.util.logging.Level; import mage.view.TournamentView;
import java.util.logging.Logger;
import mage.game.draft.Draft;
import mage.game.draft.DraftOptions;
import mage.util.Logging;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class DraftFactory { public class TournamentManager {
private final static DraftFactory INSTANCE = new DraftFactory(); private final static TournamentManager INSTANCE = new TournamentManager();
private final static Logger logger = Logging.getLogger(DraftFactory.class.getName());
private Map<String, Class<Draft>> drafts = new HashMap<String, Class<Draft>>(); private ConcurrentHashMap<UUID, TournamentController> controllers = new ConcurrentHashMap<UUID, TournamentController>();
public static DraftFactory getInstance() { public static TournamentManager getInstance() {
return INSTANCE; return INSTANCE;
} }
private DraftFactory() {} public UUID createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
TournamentController tournamentController = new TournamentController(tournament, sessionPlayerMap, tableId);
public Draft createDraft(String draftType, DraftOptions options) { controllers.put(tournament.getId(), tournamentController);
return tournamentController.getSessionId();
Draft draft;
Constructor<Draft> con;
try {
con = drafts.get(draftType).getConstructor(new Class[]{DraftOptions.class});
draft = con.newInstance(new Object[] {options});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
return null;
}
logger.info("Draft created: " + draftType); // + game.getId().toString());
return draft;
} }
public void addDraftType(String name, Class draft) { public void joinTournament(UUID tournamentId, UUID sessionId) {
if (draft != null) { controllers.get(tournamentId).join(sessionId);
this.drafts.put(name, draft); }
}
public void kill(UUID tournamentId, UUID sessionId) {
controllers.get(tournamentId).kill(sessionId);
}
public TournamentView getTournamentView(UUID tournamentId) {
return controllers.get(tournamentId).getTournamentView();
}
public UUID getChatId(UUID tournamentId) {
return controllers.get(tournamentId).getChatId();
} }
} }

View file

@ -0,0 +1,106 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.tournament;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.tournament.Tournament;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.util.Logging;
import mage.view.TournamentView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentSession {
protected final static Logger logger = Logging.getLogger(TournamentSession.class.getName());
protected UUID sessionId;
protected UUID playerId;
protected Tournament tournament;
protected boolean killed = false;
public TournamentSession(Tournament tournament, UUID sessionId, UUID playerId) {
this.sessionId = sessionId;
this.tournament = tournament;
this.playerId = playerId;
}
public boolean init(final TournamentView tournamentView) {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
session.clearAck();
session.fireCallback(new ClientCallback("tournamentInit", tournamentView));
if (waitForAck("tournamentInit"))
return true;
}
}
return false;
}
public boolean waitForAck(String message) {
Session session = SessionManager.getInstance().getSession(sessionId);
do {
//TODO: add timeout
} while (!session.getAckMessage().equals(message) && !killed);
return true;
}
public void update(final TournamentView tournamentView) {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("tournamentUpdate", tournamentView));
}
}
public void gameOver(final String message) {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("tournamentOver", message));
}
}
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
}
public void setKilled() {
killed = true;
}
}

View file

@ -92,8 +92,8 @@ public class ConfigSettings {
return config.getGameTypes().getGameType(); return config.getGameTypes().getGameType();
} }
public List<Plugin> getDraftTypes() { public List<GamePlugin> getTournamentTypes() {
return config.getDraftTypes().getDraftType(); return config.getTournamentTypes().getTournamentType();
} }
public List<Plugin> getDeckTypes() { public List<Plugin> getDeckTypes() {

View file

@ -8,7 +8,7 @@
<xs:element ref="server"/> <xs:element ref="server"/>
<xs:element ref="playerTypes"/> <xs:element ref="playerTypes"/>
<xs:element ref="gameTypes"/> <xs:element ref="gameTypes"/>
<xs:element ref="draftTypes"/> <xs:element ref="tournamentTypes"/>
<xs:element ref="deckTypes"/> <xs:element ref="deckTypes"/>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
@ -54,10 +54,10 @@
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="draftTypes"> <xs:element name="tournamentTypes">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="draftType" type="plugin" maxOccurs="unbounded"/> <xs:element name="tournamentType" type="gamePlugin" maxOccurs="unbounded"/>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>

View file

@ -12,9 +12,9 @@
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/> <gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/> <gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
</gameTypes> </gameTypes>
<draftTypes> <tournamentTypes>
<draftType name="8 Player Booster" jar="mage-draft-8playerbooster.jar" className="mage.draft.BoosterDraft"/> <tournamentType name="Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>
</draftTypes> </tournamentTypes>
<deckTypes> <deckTypes>
<deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/> <deckType name="Constructed" jar="mage-deck-constructed.jar" className="mage.deck.Constructed"/>
<deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/> <deckType name="Limited" jar="mage-deck-limited.jar" className="mage.deck.Limited"/>

View file

@ -26,10 +26,7 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.draft; package mage.game.draft;
import mage.game.draft.DraftImpl;
import mage.game.draft.DraftOptions;
/** /**
* *

View file

@ -53,9 +53,9 @@ public interface Draft extends MageItem, Serializable {
public int getCardNum(); public int getCardNum();
public void addPick(UUID playerId, UUID cardId); public void addPick(UUID playerId, UUID cardId);
public void start(); public void start();
public boolean allJoined();
public void leave(UUID playerId); public void leave(UUID playerId);
public void autoPick(UUID playerId); public void autoPick(UUID playerId);
public boolean isDoneConstructing();
public void addTableEventListener(Listener<TableEvent> listener); public void addTableEventListener(Listener<TableEvent> listener);
public void fireUpdatePlayersEvent(); public void fireUpdatePlayersEvent();

View file

@ -33,8 +33,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.game.draft.DraftOptions.TimingOption; import mage.game.draft.DraftOptions.TimingOption;
@ -177,12 +175,11 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
player.setPicking(); player.setPicking();
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this); player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
} }
while (!donePicking()) { synchronized(this) {
try { while (!donePicking()) {
Thread.sleep(1000); try {
} catch (InterruptedException ex) { this.wait();
Logger.getLogger(DraftImpl.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { }
break;
} }
} }
return true; return true;
@ -190,7 +187,16 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
protected boolean donePicking() { protected boolean donePicking() {
for (DraftPlayer player: players.values()) { for (DraftPlayer player: players.values()) {
if (player.picking) if (player.isPicking())
return false;
}
return true;
}
@Override
public boolean allJoined() {
for (DraftPlayer player: this.players.values()) {
if (!player.isJoined())
return false; return false;
} }
return true; return true;
@ -235,19 +241,9 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
break; break;
} }
} }
} synchronized(this) {
this.notifyAll();
protected void startTournament() {
//TODO: implement this
}
@Override
public boolean isDoneConstructing() {
for (DraftPlayer player: this.players.values()) {
if (!player.isDoneConstructing())
return false;
} }
return true;
} }
} }

View file

@ -39,10 +39,8 @@ import mage.cards.ExpansionSet;
*/ */
public class DraftOptions implements Serializable { public class DraftOptions implements Serializable {
protected String name;
protected String draftType; protected String draftType;
protected List<ExpansionSet> sets = new ArrayList<ExpansionSet>(); protected List<ExpansionSet> sets = new ArrayList<ExpansionSet>();
protected List<String> playerTypes = new ArrayList<String>();
protected TimingOption timing; protected TimingOption timing;
public enum TimingOption { public enum TimingOption {
@ -61,22 +59,10 @@ public class DraftOptions implements Serializable {
} }
} }
public DraftOptions(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List<ExpansionSet> getSets() { public List<ExpansionSet> getSets() {
return sets; return sets;
} }
public List<String> getPlayerTypes() {
return playerTypes;
}
public String getDraftType() { public String getDraftType() {
return draftType; return draftType;
} }

View file

@ -46,7 +46,7 @@ public class DraftPlayer {
protected Deck deck; protected Deck deck;
protected List<Card> booster; protected List<Card> booster;
protected boolean picking; protected boolean picking;
protected boolean doneConstructing; protected boolean joined = false;
public DraftPlayer(Player player) { public DraftPlayer(Player player) {
id = UUID.randomUUID(); id = UUID.randomUUID();
@ -92,17 +92,12 @@ public class DraftPlayer {
return picking; return picking;
} }
public void setConstructing() { public boolean isJoined() {
this.doneConstructing = false; return joined;
} }
public void submitDeck(Deck deck) { public void setJoined() {
this.deck = deck; this.joined = true;
this.doneConstructing = true;
}
public boolean isDoneConstructing() {
return this.doneConstructing;
} }
} }

View file

@ -35,6 +35,8 @@ import mage.cards.Cards;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.game.Game; import mage.game.Game;
import mage.game.draft.Draft; import mage.game.draft.Draft;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentPairing;
/** /**
* *
@ -43,8 +45,7 @@ import mage.game.draft.Draft;
public class TableEvent extends EventObject implements ExternalEvent, Serializable { public class TableEvent extends EventObject implements ExternalEvent, Serializable {
public enum EventType { public enum EventType {
UPDATE, INFO, REVEAL, LOOK, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END UPDATE, INFO, REVEAL, LOOK, START_DRAFT, START_MATCH, SIDEBOARD, CONSTRUCT, SUBMIT_DECK, END}
}
private Game game; private Game game;
private Draft draft; private Draft draft;
@ -53,6 +54,13 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
private Cards cards; private Cards cards;
private UUID playerId; private UUID playerId;
private Deck deck; private Deck deck;
private TournamentPairing pair;
private MatchOptions options;
public TableEvent(EventType eventType) {
super(eventType);
this.eventType = eventType;
}
public TableEvent(EventType eventType, String message, Cards cards, Game game) { public TableEvent(EventType eventType, String message, Cards cards, Game game) {
super(game); super(game);
@ -76,6 +84,13 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
this.eventType = eventType; this.eventType = eventType;
} }
public TableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {
super(options);
this.pair = pair;
this.options = options;
this.eventType = eventType;
}
public Game getGame() { public Game getGame() {
return game; return game;
} }
@ -103,4 +118,12 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
public Deck getDeck() { public Deck getDeck() {
return deck; return deck;
} }
public TournamentPairing getPair() {
return pair;
}
public MatchOptions getMatchOptions() {
return options;
}
} }

View file

@ -35,6 +35,8 @@ import mage.cards.decks.Deck;
import mage.game.Game; import mage.game.Game;
import mage.game.draft.Draft; import mage.game.draft.Draft;
import mage.game.events.TableEvent.EventType; import mage.game.events.TableEvent.EventType;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentPairing;
/** /**
* *
@ -49,6 +51,10 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
dispatcher.addListener(listener); dispatcher.addListener(listener);
} }
public void fireTableEvent(EventType eventType) {
dispatcher.fireEvent(new TableEvent(eventType));
}
public void fireTableEvent(EventType eventType, String message, Game game) { public void fireTableEvent(EventType eventType, String message, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, null, game)); dispatcher.fireEvent(new TableEvent(eventType, message, null, game));
} }
@ -64,4 +70,8 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
public void fireTableEvent(EventType eventType, UUID playerId, Deck deck) { public void fireTableEvent(EventType eventType, UUID playerId, Deck deck) {
dispatcher.fireEvent(new TableEvent(eventType, playerId, deck)); dispatcher.fireEvent(new TableEvent(eventType, playerId, deck));
} }
public void fireTableEvent(EventType eventType, TournamentPairing pair, MatchOptions options) {
dispatcher.fireEvent(new TableEvent(eventType, pair, options));
}
} }

View file

@ -50,6 +50,8 @@ public interface Match {
public void startGame() throws GameException; public void startGame() throws GameException;
public void endGame(); public void endGame();
public Game getGame(); public Game getGame();
public List<Game> getGames();
public int getWinsNeeded();
public int getNumGames(); public int getNumGames();
public boolean isDoneSideboarding(); public boolean isDoneSideboarding();
public UUID getChooser(); public UUID getChooser();

View file

@ -31,20 +31,24 @@ package mage.game.match;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.game.Game; import mage.game.Game;
import mage.game.GameException; import mage.game.GameException;
import mage.players.Player; import mage.players.Player;
import mage.util.Logging;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public abstract class MatchImpl<T extends Game> implements Match { public abstract class MatchImpl implements Match {
private final static Logger logger = Logging.getLogger(MatchImpl.class.getName());
protected UUID id = UUID.randomUUID(); protected UUID id = UUID.randomUUID();
protected List<MatchPlayer> players = new ArrayList<MatchPlayer>(); protected List<MatchPlayer> players = new ArrayList<MatchPlayer>();
protected List<T> games = new ArrayList<T>(); protected List<Game> games = new ArrayList<Game>();
protected MatchOptions options; protected MatchOptions options;
public MatchImpl(MatchOptions options) { public MatchImpl(MatchOptions options) {
@ -92,15 +96,25 @@ public abstract class MatchImpl<T extends Game> implements Match {
} }
@Override @Override
public T getGame() { public Game getGame() {
return games.get(games.size() -1); return games.get(games.size() -1);
} }
@Override
public List<Game> getGames() {
return games;
}
@Override @Override
public int getNumGames() { public int getNumGames() {
return games.size(); return games.size();
} }
@Override
public int getWinsNeeded() {
return options.getWinsNeeded();
}
protected void initGame(Game game) throws GameException { protected void initGame(Game game) throws GameException {
for (MatchPlayer matchPlayer: this.players) { for (MatchPlayer matchPlayer: this.players) {
game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId());

View file

@ -29,8 +29,6 @@
package mage.game.match; package mage.game.match;
import java.io.Serializable; import java.io.Serializable;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence;
/** /**
* *

View file

@ -30,8 +30,7 @@ package mage.game.tournament;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import mage.game.match.Match; import java.util.UUID;
import mage.players.Player;
/** /**
* *
@ -40,15 +39,39 @@ import mage.players.Player;
public class Round { public class Round {
private int roundNum; private int roundNum;
private List<Match> matches = new ArrayList<Match>(); private List<TournamentPairing> pairs = new ArrayList<TournamentPairing>();
public Round(int roundNum, List<Player> players) { public Round(int roundNum) {
this.roundNum = roundNum; this.roundNum = roundNum;
} }
public List<Match> getMatches() { public void addPairing(TournamentPairing match) {
return matches; this.pairs.add(match);
} }
public TournamentPairing getPairing(UUID pairId) {
for (TournamentPairing pair: pairs) {
if (pair.getId().equals(pairId)) {
return pair;
}
}
return null;
}
public List<TournamentPairing> getPairs() {
return pairs;
}
public int getRoundNumber() {
return this.roundNum;
}
public boolean isRoundOver() {
for (TournamentPairing pair: pairs) {
if (!pair.getMatch().isMatchOver()) {
return false;
}
}
return true;
}
} }

View file

@ -28,12 +28,30 @@
package mage.game.tournament; package mage.game.tournament;
import java.util.Collection;
import java.util.UUID;
import mage.cards.decks.Deck;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.players.Player;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public interface Tournament { public interface Tournament {
public void playRound(); public UUID getId();
public void addPlayer(Player player, String playerType);
public TournamentPlayer getPlayer(UUID playerId);
public Collection<TournamentPlayer> getPlayers();
public Collection<Round> getRounds();
public void submitDeck(UUID playerId, Deck deck);
public boolean allJoined();
public boolean isDoneConstructing();
public void leave(UUID playerId);
public void nextStep();
public void addTableEventListener(Listener<TableEvent> listener);
} }

View file

@ -29,24 +29,191 @@
package mage.game.tournament; package mage.game.tournament;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.match.Match;
import mage.players.Player; import mage.players.Player;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class TournamentImpl implements Tournament { public abstract class TournamentImpl implements Tournament {
List<Round> rounds = new ArrayList<Round>(); protected UUID id = UUID.randomUUID();
List<Player> players = new ArrayList<Player>(); protected List<Round> rounds = new CopyOnWriteArrayList<Round>();
protected Map<UUID, TournamentPlayer> players = new HashMap<UUID, TournamentPlayer>();
protected static Random rnd = new Random();
protected String matchName;
protected TournamentOptions options;
protected transient TableEventSource tableEventSource = new TableEventSource();
public TournamentImpl(TournamentOptions options) {
this.options = options;
}
@Override @Override
public void playRound() { public UUID getId() {
throw new UnsupportedOperationException("Not supported yet."); return id;
} }
protected void createRound() { @Override
public void addPlayer(Player player, String playerType) {
players.put(player.getId(), new TournamentPlayer(player, playerType));
}
@Override
public TournamentPlayer getPlayer(UUID playerId) {
return players.get(playerId);
}
@Override
public Collection<TournamentPlayer> getPlayers() {
return players.values();
}
@Override
public Collection<Round> getRounds() {
return rounds;
}
@Override
public void leave(UUID playerId) {
//TODO: implement this
}
@Override
public void submitDeck(UUID playerId, Deck deck) {
if (players.containsKey(playerId)) {
players.get(playerId).submitDeck(deck);
}
synchronized (this) {
this.notifyAll();
}
}
protected Round createRoundRandom() {
Round round = new Round(rounds.size() + 1);
rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers();
while (roundPlayers.size() > 1) {
int i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player1 = roundPlayers.get(i);
roundPlayers.remove(i);
i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player2 = roundPlayers.get(i);
roundPlayers.remove(i);
round.addPairing(new TournamentPairing(player1, player2));
}
return round;
}
protected void playRound(Round round) {
for (TournamentPairing pair: round.getPairs()) {
playMatch(pair);
}
while (!round.isRoundOver()) {
try {
//TODO: improve this
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(TournamentImpl.class.getName()).log(Level.SEVERE, null, ex);
break;
}
}
updateResults();
}
protected List<TournamentPlayer> getActivePlayers() {
List<TournamentPlayer> activePlayers = new ArrayList<TournamentPlayer>();
for (TournamentPlayer player: players.values()) {
if (!player.getEliminated()) {
activePlayers.add(player);
}
}
return activePlayers;
}
protected void updateResults() {
for (TournamentPlayer player: players.values()) {
player.setResults("");
}
for (Round round: rounds) {
for (TournamentPairing pair: round.getPairs()) {
UUID player1Id = pair.getPlayer1().getPlayer().getId();
UUID player2Id = pair.getPlayer2().getPlayer().getId();
Match match = pair.getMatch();
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
sb1.append(pair.getPlayer2().getPlayer().getName());
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") ");
sb2.append(pair.getPlayer1().getPlayer().getName());
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
players.get(player1Id).setResults(sb1.toString());
players.get(player2Id).setResults(sb2.toString());
}
}
} }
@Override
public boolean isDoneConstructing() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isDoneConstructing())
return false;
}
return true;
}
@Override
public boolean allJoined() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isJoined())
return false;
}
return true;
}
@Override
public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener);
}
public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
}
nextStep();
}
public void playMatch(TournamentPairing pair) {
options.getMatchOptions().getPlayerTypes().clear();
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer2().getPlayerType());
tableEventSource.fireTableEvent(EventType.START_MATCH, pair, options.getMatchOptions());
}
protected abstract void runTournament();
} }

View file

@ -0,0 +1,77 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.game.draft.DraftOptions;
import mage.game.match.MatchOptions;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentOptions implements Serializable {
protected String name;
protected String tournamentType;
protected List<String> playerTypes = new ArrayList<String>();
protected MatchOptions matchOptions = new MatchOptions("", "Two Player Duel");
protected DraftOptions draftOptions = new DraftOptions();
public TournamentOptions(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getTournamentType() {
return tournamentType;
}
public void setTournamentType(String tournamentType) {
this.tournamentType = tournamentType;
}
public List<String> getPlayerTypes() {
return playerTypes;
}
public MatchOptions getMatchOptions() {
return matchOptions;
}
public DraftOptions getDraftOptions() {
return draftOptions;
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import java.util.UUID;
import mage.game.match.Match;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPairing {
UUID id = UUID.randomUUID();
Match match;
TournamentPlayer player1;
TournamentPlayer player2;
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
this.player1 = player1;
this.player2 = player2;
}
public UUID getId() {
return id;
}
public TournamentPlayer getPlayer1() {
return this.player1;
}
public TournamentPlayer getPlayer2() {
return this.player2;
}
public Match getMatch() {
return match;
}
public void setMatch(Match match) {
this.match = match;
}
public void eliminatePlayers() {
if (match.getPlayer(player1.getPlayer().getId()).getWins() < match.getWinsNeeded()) {
player1.setEliminated();
}
if (match.getPlayer(player2.getPlayer().getId()).getWins() < match.getWinsNeeded()) {
player2.setEliminated();
}
}
}

View file

@ -28,6 +28,7 @@
package mage.game.tournament; package mage.game.tournament;
import mage.cards.decks.Deck;
import mage.players.Player; import mage.players.Player;
/** /**
@ -38,16 +39,31 @@ public class TournamentPlayer {
protected int points; protected int points;
protected String name; protected String name;
protected String playerType;
protected Player player; protected Player player;
protected Deck deck;
protected String results = "";
protected boolean eliminated = false;
protected boolean doneConstructing;
protected boolean joined = false;
public TournamentPlayer(Player player) { public TournamentPlayer(Player player, String playerType) {
this.player = player; this.player = player;
this.playerType = playerType;
} }
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
public String getPlayerType() {
return playerType;
}
public Deck getDeck() {
return deck;
}
public int getPoints() { public int getPoints() {
return points; return points;
} }
@ -56,4 +72,44 @@ public class TournamentPlayer {
this.points = points; this.points = points;
} }
public boolean getEliminated() {
return eliminated;
}
public void setEliminated() {
this.eliminated = true;
}
public boolean isJoined() {
return joined;
}
public void setJoined() {
this.joined = true;
}
public void setConstructing() {
this.doneConstructing = false;
}
public void submitDeck(Deck deck) {
this.deck = deck;
this.doneConstructing = true;
}
public boolean isDoneConstructing() {
return this.doneConstructing;
}
public void setDeck(Deck deck) {
this.deck = deck;
}
public String getResults() {
return this.results;
}
public void setResults(String results) {
this.results = results;
}
} }

View file

@ -0,0 +1,41 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentSealedOptions extends TournamentOptions {
public TournamentSealedOptions(String name) {
super(name);
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentSingleElimination extends TournamentImpl {
public TournamentSingleElimination(TournamentOptions options) {
super(options);
}
@Override
protected void runTournament() {
while (this.getActivePlayers().size() > 1) {
Round round = createRoundRandom();
playRound(round);
eliminatePlayers(round);
}
nextStep();
}
private void eliminatePlayers(Round round) {
for (TournamentPairing pair: round.getPairs()) {
pair.eliminatePlayers();
}
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentSwiss extends TournamentImpl {
public TournamentSwiss(TournamentOptions options) {
super(options);
}
@Override
protected void runTournament() {
//TODO: implement this
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentType <T extends TournamentType<T>> implements Serializable {
protected String name;
protected int minPlayers;
protected int maxPlayers;
protected int numBoosters;
protected boolean draft;
protected TournamentType() {}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public int getMinPlayers() {
return minPlayers;
}
public int getMaxPlayers() {
return maxPlayers;
}
public int getNumBoosters() {
return numBoosters;
}
public boolean isDraft() {
return draft;
}
}

View file

@ -0,0 +1,219 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.game.events.Listener;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.match.Match;
import mage.players.Player;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentImpl implements Tournament {
protected UUID id = UUID.randomUUID();
protected List<Round> rounds = new CopyOnWriteArrayList<Round>();
protected Map<UUID, TournamentPlayer> players = new HashMap<UUID, TournamentPlayer>();
protected static Random rnd = new Random();
protected String matchName;
protected TournamentOptions options;
protected transient TableEventSource tableEventSource = new TableEventSource();
public TournamentImpl(TournamentOptions options) {
this.options = options;
}
@Override
public UUID getId() {
return id;
}
@Override
public void addPlayer(Player player, String playerType) {
players.put(player.getId(), new TournamentPlayer(player, playerType));
}
@Override
public TournamentPlayer getPlayer(UUID playerId) {
return players.get(playerId);
}
@Override
public Collection<TournamentPlayer> getPlayers() {
return players.values();
}
@Override
public Collection<Round> getRounds() {
return rounds;
}
@Override
public void leave(UUID playerId) {
//TODO: implement this
}
@Override
public void submitDeck(UUID playerId, Deck deck) {
if (players.containsKey(playerId)) {
players.get(playerId).submitDeck(deck);
}
synchronized (this) {
this.notifyAll();
}
}
protected Round createRoundRandom() {
Round round = new Round(rounds.size() + 1);
rounds.add(round);
List<TournamentPlayer> roundPlayers = getActivePlayers();
while (roundPlayers.size() > 1) {
int i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player1 = roundPlayers.get(i);
roundPlayers.remove(i);
i = rnd.nextInt(roundPlayers.size());
TournamentPlayer player2 = roundPlayers.get(i);
roundPlayers.remove(i);
round.addPairing(new TournamentPairing(player1, player2));
}
return round;
}
protected void playRound(Round round) {
for (TournamentPairing pair: round.getPairs()) {
playMatch(pair);
}
while (!round.isRoundOver()) {
try {
//TODO: improve this
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(TournamentImpl.class.getName()).log(Level.SEVERE, null, ex);
break;
}
}
updateResults();
}
protected List<TournamentPlayer> getActivePlayers() {
List<TournamentPlayer> activePlayers = new ArrayList<TournamentPlayer>();
for (TournamentPlayer player: players.values()) {
if (!player.getEliminated()) {
activePlayers.add(player);
}
}
return activePlayers;
}
protected void updateResults() {
for (TournamentPlayer player: players.values()) {
player.setResults("");
}
for (Round round: rounds) {
for (TournamentPairing pair: round.getPairs()) {
UUID player1Id = pair.getPlayer1().getPlayer().getId();
UUID player2Id = pair.getPlayer2().getPlayer().getId();
Match match = pair.getMatch();
StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults());
StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults());
sb1.append(pair.getPlayer2().getPlayer().getName());
sb1.append(" (").append(match.getPlayer(player1Id).getWins());
sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(")");
sb2.append(pair.getPlayer1().getPlayer().getName());
sb2.append(" (").append(match.getPlayer(player2Id).getWins());
sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") ");
players.get(player1Id).setResults(sb1.toString());
players.get(player2Id).setResults(sb2.toString());
}
}
}
@Override
public boolean isDoneConstructing() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isDoneConstructing())
return false;
}
return true;
}
@Override
public boolean allJoined() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isJoined())
return false;
}
return true;
}
@Override
public void addTableEventListener(Listener<TableEvent> listener) {
tableEventSource.addListener(listener);
}
public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
}
nextStep();
}
public void playMatch(TournamentPairing pair) {
options.getMatchOptions().getPlayerTypes().clear();
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer2().getPlayerType());
tableEventSource.fireTableEvent(EventType.START_MATCH, pair, options.getMatchOptions());
}
protected abstract void runTournament();
}

View file

@ -0,0 +1,115 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
import mage.cards.decks.Deck;
import mage.players.Player;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayer {
protected int points;
protected String name;
protected String playerType;
protected Player player;
protected Deck deck;
protected String results = "";
protected boolean eliminated = false;
protected boolean doneConstructing;
protected boolean joined = false;
public TournamentPlayer(Player player, String playerType) {
this.player = player;
this.playerType = playerType;
}
public Player getPlayer() {
return player;
}
public String getPlayerType() {
return playerType;
}
public Deck getDeck() {
return deck;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public boolean getEliminated() {
return eliminated;
}
public void setEliminated() {
this.eliminated = true;
}
public boolean isJoined() {
return joined;
}
public void setJoined() {
this.joined = true;
}
public void setConstructing() {
this.doneConstructing = false;
}
public void submitDeck(Deck deck) {
this.deck = deck;
this.doneConstructing = true;
}
public boolean isDoneConstructing() {
return this.doneConstructing;
}
public void setDeck(Deck deck) {
this.deck = deck;
}
public String getResults() {
return this.results;
}
public void setResults(String results) {
this.results = results;
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.tournament;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TournamentSingleElimination extends TournamentImpl {
public TournamentSingleElimination(TournamentOptions options) {
super(options);
}
@Override
protected void runTournament() {
while (this.getActivePlayers().size() > 1) {
Round round = createRoundRandom();
playRound(round);
eliminatePlayers(round);
}
nextStep();
}
private void eliminatePlayers(Round round) {
for (TournamentPairing pair: round.getPairs()) {
pair.eliminatePlayers();
}
}
}