Package net.yura.lobby.model

Examples of net.yura.lobby.model.Game


        ((Integer)numberDecks.getValue()).intValue(),
        ((Integer)easybotsplayers.getValue()).intValue(),
        ((Integer)numberRounds.getValue()).intValue()
      );

      return new Game( namebox.getText(), bkoptions , ((Integer)humanplayers.getValue()).intValue() );

    }
    return null;

  }
View Full Code Here


     * as that may cause the game to never start as 2 people can join it at the same time
     */
    @Version int version;

    public GameRoom() {
        game = new Game();
    }
View Full Code Here

            else if (ProtoAccess.REQUEST_GET_GAMES.equals(command)) {
                Map map = (Map)param;
                lobby.setCurrentGameType(session, (Integer)map.get("game_type_id") );
            }
            else if (ProtoLobby.REQUEST_CREATE_NEW_GAME.equals(command)) {
                Game game = (Game)param;

                if (game.getId() >= 0) {
                    assertAmMod(session); // only admin can edit existing games.
                    try {
                        lobby.database.startTransaction();
                        GameRoom gameRoom = lobby.database.getGame(game.getId());
                        if (!gameRoom.getName().equals(game.getName())) {
                            gameRoom.setName( game.getName() );
                            lobby.database.saveGame(gameRoom);
                            lobby.gameChanged(gameRoom);
                        }
                        // TODO we may want to resign/add players
                    }
                    finally {
                        lobby.database.endTransaction();
                    }
                }
                else {
                    if (game.getPlayers().isEmpty()) {
                        GameRoom gameRoom = lobby.createGame(game);
                        lobby.joinGame(session.getUsername(), gameRoom.getId());
                    }
                    else {
                        Set<Player> players = game.getPlayers();
                        game.setPlayers(new HashSet());
                        GameRoom gameRoom = lobby.createGame(game);
                        // TODO somehow need to tell the DB this is a private game
                        for (Player player: players) {
                            gameRoom = lobby.joinGame(player.getName(), gameRoom.getId(), session);
                        }
View Full Code Here

    games = new TranslucentJTable(gamesModel,0.5f) {
                    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                        Component c = super.prepareRenderer(renderer, row, column);
                        if (c instanceof JComponent) {
                            JComponent jc = (JComponent) c;
                            Game game = (Game)gamesModel.getDataVector().get(row);
                            StringBuffer buffer = new StringBuffer();
                            buffer.append( "<html>" );

                            buffer.append("Description: ");
                            buffer.append( getLobbyGame(game.getType(),false).getGameDescription(game.getOptions()) );
                            buffer.append("<br>");

                            buffer.append("ID: ");
                            buffer.append(game.getId());
                            buffer.append("<br>");

                            buffer.append("WhosTurn: ");
                            buffer.append(game.getWhosTurn());
                            buffer.append("<br>");

                            buffer.append("Players: ");
                            buffer.append(game.getPlayers());
                            buffer.append("<br>");

//                            Iterator it = game.getPlayers().iterator();
//                            while (it.hasNext()) {
//                                buffer.append( ( (Player)it.next() ).getName() );
//                                buffer.append( "<br>" );
//                            }
                            jc.setToolTipText( buffer.toString() );


                            if (!(jc instanceof TranslucentJButton) && game.getWhosTurn()!=null && !"".equals(game.getWhosTurn()) && !game.getPlayers().contains(new Player(game.getWhosTurn(), 0))) {
                                jc.setBackground(Color.RED);
                                jc.setOpaque(true);
                            }

                        }
                        return c;
                    }
                };




/*

    {

        public Component prepareRenderer(TableCellRenderer renderer,int row, int col) {
      Component comp = super.prepareRenderer(renderer, row, col);
      JComponent jcomp = (JComponent)comp;
      if (comp == jcomp) {
        jcomp.setToolTipText((String)getValueAt(row, col));
      }
      return comp;
        }
    };

*/

    gamesModel.addTableModelListener(games);





    games.getTableHeader().setReorderingAllowed(false);
    games.getTableHeader().setOpaque(false);
    games.getTableHeader().setDefaultRenderer(new DefaultTableCellRenderer() {
      public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component c = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
        if(c instanceof JLabel) {

                                        //We get a better looking font if we do not use the default table font.
                                        JLabel label = new JLabel(((JLabel)c).getText());
                                        label.setOpaque(false);
                                        label.setHorizontalAlignment(SwingConstants.CENTER);
                                        if(column==table.getColumnCount()) {
                                                label.setBorder(BorderFactory.createLineBorder(Color.BLACK ));
                                        }
                                        else {
                                                label.setBorder(BorderFactory.createMatteBorder(1,0,1,1,Color.BLACK ));
                                        }
                                        return label;
                                }
        return c;
      }
    });
    games.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);


    //games.addColumn(new javax.swing.table.TableColumn(0, 32));

    games.getColumnModel().getColumn(0).setMaxWidth(32);
    games.getColumnModel().getColumn(2).setMaxWidth(50);
    games.getColumnModel().getColumn(3).setMaxWidth(50);
                games.getColumnModel().getColumn(4).setMaxWidth(50);
                games.getColumnModel().getColumn(5).setMaxWidth(50);
    games.getColumn("Action").setCellRenderer(new ButtonRenderer());
    games.getColumn("Action").setCellEditor(new ButtonEditor());

                String DELETE = "del";
                int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
                InputMap inputMap = games.getInputMap(condition);
                ActionMap actionMap = games.getActionMap();

                // DELETE is a String constant that for me was defined as "Delete"
                inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
                inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), DELETE);
                actionMap.put(DELETE, new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        if (playerType >= Player.PLAYER_MODERATOR) {
                            int[] selections = games.getSelectedRows();
                            Game[] gamesToRemove = new Game[selections.length];
                            int startedGameCount = 0;
                            for (int c = 0; c < selections.length; c++) {
                                Game game = gamesToRemove[c] = gamesModel.getGame(selections[c]);
                                if (game.getNumOfPlayers() == game.getMaxPlayers()) {
                                    startedGameCount++;
                                }
                            }
                            if (startedGameCount > 0) {
                                int result = JOptionPane.showConfirmDialog(LobbyClientGUI.this,
View Full Code Here

                        boolean doAndroidSend=false;
                        try {
                            database.startTransaction();

                            LobbySession found=null;
                            Game game = getGame( sg.getId() ).getGame();
                            Collection<LobbySession> sessions = sg.getAllClients();
                            for (LobbySession session:sessions) {
                                sendGame(session, game);
                                if (session.getUsername().equals(username)) {
                                    found = session;
View Full Code Here

                        }
                        finally {
                            stopLoading();
                        }

      Game newGameOptions = lg.newGameDialog(
        (java.awt.Frame)javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, this),
        gametype.getOptions(),
        myusername
      );

      if (newGameOptions!=null) {
                                newGameOptions.setType(gametype);

                                // uncomment for testing private game creation
                                //newGameOptions.getPlayers().add(new Player(whoAmI(), 0));

        mycom.createNewGame(newGameOptions);
View Full Code Here

        public int getColumnCount() {
            return colnames.length;
        }

      public Object getValueAt(int row, int column) {
          Game game = getGame(row);
          switch (column) {
    case 0: return getLobbyGame(game.getType(),false).getIcon(game.getOptions());
    case 1: return game;
                case 2: return new Integer( game.getInGame() );
                case 3: return TimeoutUtil.formatPeriod( game.getTimeout()*1000L );
    case 4: return game.getNumOfPlayers()+"/"+game.getMaxPlayers();
                case 5: return new Integer( game.getState(myusername) );
                default: throw new RuntimeException();
          }
      }
View Full Code Here

        @Override
        public void setValueAt(Object aValue, int row, int column) {
            if (column == 1) {
                if (playerType >= Player.PLAYER_MODERATOR) {
                    Game game = getGame(row);
                    String newName = (String) aValue;
                    if (!game.getName().equals(newName)) {
                        game.setName(newName);
                        mycom.createNewGame(game);
                    }
                }
            }
            else {
View Full Code Here

TOP

Related Classes of net.yura.lobby.model.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.