Kontakt

Fakturační údaje

IČ: 87189224, BÚ: 1958653063/0800

Contact info in QR code

Siege (Obkličovačka)

Informace

Stáhni a hraj!

  • Spustitelný soubor hry si stáhnou oba hráči
  • Zakladatel hry
    • V nabídce "Game > Create" vytvoří novou hru
    • Pošle protihráči svou IP adresu (zjistí ji v levém dolním rohu okna)
  • Protihráč
    • Jakmile obdrží IP adresu zakladatele hry, v nabídce "Game > Join" se připojí ke hře
  • Cílem je zabrat co nejvíce soupeřových polí.
  • Pozn.: Síťové spojení funguje na LAN (lokální) síťi a na počítačích s veřejnou IP adresou.

Zdrojové kódy (zip)

Zdrojové kódy (prohlížení)

  1: package siege.gui.dialogs;
  2: 
  3: import java.awt.BorderLayout;
  4: import java.awt.Dimension;
  5: import java.awt.Font;
  6: import java.awt.event.ActionEvent;
  7: import java.awt.event.ActionListener;
  8: import javax.swing.BorderFactory;
  9: import javax.swing.Box;
 10: import javax.swing.BoxLayout;
 11: import javax.swing.JButton;
 12: import javax.swing.JLabel;
 13: import javax.swing.JPanel;
 14: import javax.swing.JTextField;
 15: import javax.swing.border.EtchedBorder;
 16: import siege.core.Game;
 17: import siege.core.Player;
 18: import siege.util.Log;
 19: 
 20: /**
 21:  * Dialog for joining the existing game
 22:  * 
 23:  * @author Ondrej Macoszek, ondra@macoszek.cz
 24:  */
 25: public class DialogJoinGame extends DialogBasic
 26: {
 27:     /**
 28:      * Dialog form fields
 29:      */
 30:     public JTextField nameField;
 31:     public JLabel nameLabel;
 32:     public JTextField addressField;
 33:     public JLabel addressLabel;
 34:     public JPanel inputPane;
 35:     public JPanel buttonPane;
 36:     public JButton submit;
 37:     public JButton cancel;
 38: 
 39:     /**
 40:      * Constructor
 41:      */
 42:     public DialogJoinGame()
 43:     {
 44:         super();
 45:         setTitle("Join game");
 46: 
 47:         // name field
 48:         nameField = new JTextField();
 49:         nameField.setFont(new Font("SansSerif", Font.TRUETYPE_FONT, 14));
 50:         nameField.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
 51: 
 52:         // name label
 53:         nameLabel = new JLabel("What's your name?");
 54:         nameLabel.setFont(new Font("SansSerif", Font.BOLD, 14));
 55:         nameLabel.setLabelFor(nameField);
 56: 
 57:         // address field
 58:         addressField = new JTextField();
 59:         addressField.setFont(new Font("SansSerif", Font.TRUETYPE_FONT, 14));
 60:         addressField.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
 61:         
 62:         // address label
 63:         addressLabel = new JLabel("What's the opponent address?");
 64:         addressLabel.setFont(new Font("SansSerif", Font.BOLD, 14));
 65:         addressLabel.setLabelFor(addressField);
 66: 
 67:         // wrapper for name and address
 68:         inputPane = new JPanel();
 69:         inputPane.setAlignmentX(JLabel.LEFT_ALIGNMENT);
 70:         inputPane.setLayout(new BoxLayout(inputPane, BoxLayout.Y_AXIS));
 71:         inputPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
 72:         inputPane.add(nameLabel);
 73:         inputPane.add(Box.createRigidArea(new Dimension(0, 10)));
 74:         inputPane.add(nameField);
 75:         inputPane.add(Box.createRigidArea(new Dimension(0, 20)));
 76:         inputPane.add(addressLabel);
 77:         inputPane.add(Box.createRigidArea(new Dimension(0, 10)));
 78:         inputPane.add(addressField);
 79: 
 80:         // buttons
 81:         submit = new JButton("Join game");
 82:         cancel = new JButton("Cancel");
 83: 
 84:         // wrapper for buttons
 85:         buttonPane = new JPanel();
 86:         buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
 87:         buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
 88:         buttonPane.add(Box.createHorizontalGlue());
 89:         buttonPane.add(submit);
 90:         buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
 91:         buttonPane.add(cancel);
 92: 
 93:         // add wrappers to layout
 94:         setLayout(new BorderLayout());
 95:         add(inputPane, BorderLayout.CENTER);
 96:         add(buttonPane, BorderLayout.PAGE_END);
 97: 
 98:         // attach listeners
 99:         nameField.addActionListener(new ActionListener() {
100:             public void actionPerformed(ActionEvent e) {
101:                 addressField.requestFocus();
102:             }
103:         });
104:         addressField.addActionListener(new ActionListener() {
105:             public void actionPerformed(ActionEvent e) {
106:                 submitDialog();
107:             }
108:         });
109:         submit.addActionListener(new ActionListener() {
110:             public void actionPerformed(ActionEvent e) {
111:                 submitDialog();
112:             }
113:         });
114:         cancel.addActionListener(new ActionListener() {
115:             public void actionPerformed(ActionEvent e) {
116:                 closeDialog();
117:             }
118:         });
119: 
120:         // final dialog settings
121:         finalDialogSettings();
122:     }
123: 
124:     /**
125:      * Submit dialog operations
126:      */
127:     public void submitDialog()
128:     {
129:         Log.message(this, "submitDialog");
130:         if(nameField.getText().isEmpty()) {
131:             Log.message(this, "No name written");
132:             showAlert("Please write your name");
133:             nameField.requestFocus();
134:         } else if(addressField.getText().isEmpty()) {
135:             Log.message(this, "No address written");
136:             showAlert("Please write opponents address");
137:             addressField.requestFocus();
138:         } else {
139:             Game game = Game.getInstance();
140:             game.getLocalPlayer().setName(nameField.getText());
141:             Player remotePlayer = game.getRemotePlayer();
142:             remotePlayer.setAddress(addressField.getText());
143:             game.setChallenger(remotePlayer);
144:             closeDialog();
145:             game.connect();
146:         }
147:     }
148: }
149: 
150: