Android Open Source - GameTimer Group






From Project

Back to project page GameTimer.

License

The source code is released under:

Apache License

If you think the Android project GameTimer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.solidnw.gametimer.model;
//  w  w  w. jav a  2  s .  c o  m
import java.util.ArrayList;
import java.util.Collections;


/**
 * @author  SickSta
 * @since   21:21:59 - 21.01.2013
 * @project AndroidGameTimer
 */
public class Group {
  
  private String mName;
  private ArrayList<Player> mPlayers;
  private ArrayList<String> mPlayerNames;
  private Player mCurrentPlayer;
  
  public Group(String name, ArrayList<Player> players, Time gameTime, String gameMode) {
    mName = name;
    mPlayers = players;
    
    if(mPlayers != null) {
      if(mPlayers.size() != 0) {
        mCurrentPlayer = mPlayers.get(0);
      }
    }
    
    setPlayersInfo(gameTime, gameMode);
  }
  
  public void addPlayer(Player player) {
    if(player != null) {
      mPlayers.add(player);
      mPlayerNames.add(player.getName());
      // ask if this should be persisted in the database
    }
  }
  
  public void removePlayer(Player player) {
    if(player != null) {
      mPlayers.remove(player);
      mPlayerNames.remove(player.getName());
      // ask if this should be persisted in the database
    }
  }
  
  public void nextPlayer() {
    if(mPlayers != null) {
      int indexCurrent = mPlayers.indexOf(mCurrentPlayer);
      if( indexCurrent < (mPlayers.size() - 1) ) {
        mCurrentPlayer = mPlayers.get(indexCurrent + 1);
      }
      else {
        if(indexCurrent != -1) {
          mCurrentPlayer = mPlayers.get(0);
        }
      }
    }
  }
  
  public void reverseDirection() {
    Collections.reverse(mPlayers);
    nextPlayer();
  }
  
  public Player getPreviousPlayer() {
    if(mPlayers != null) {
      int indexCurrent = mPlayers.indexOf(mCurrentPlayer);
      if( indexCurrent > 0 ) {
        return mPlayers.get(indexCurrent - 1);
      }
      else {
        if(indexCurrent == 0 && mPlayers.size() != 0) {
          return mPlayers.get(mPlayers.size() - 1);
        }
      }
    }
    return null;
  }
  
  public Player getNextPlayer() {
    if(mPlayers != null) {
      int indexCurrent = mPlayers.indexOf(mCurrentPlayer);
      if( indexCurrent < (mPlayers.size() - 1) ) {
        return mPlayers.get(indexCurrent + 1);
      }
      else {
        if(indexCurrent != -1) {
          return mPlayers.get(0);
        }
      }
    }
    return null;
  }
  
  private void setPlayersInfo(Time gameTime, String gameMode) {
    for(Player player : mPlayers) {
      player.initializeTime(gameTime);
      player.initializeMode(gameMode);
    }
  }
  
  // ===========================================================
  // Getter & Setter
  // ===========================================================
  /**
   * @return the name
   */
  public String getName() {
    return mName;
  }
  
  /**
   * @return the players
   */
  public ArrayList<Player> getPlayers() {
    return mPlayers;
  }
  
  /**
   * @retun the playerNames
   */
  public ArrayList<String> getPlayerNames() {
    return mPlayerNames;
  }
  
  /**
   * @return the currentPlayer
   */
  public Player getCurrentPlayer() {
    return mCurrentPlayer;
  }
  
  /**
   * @param currentPlayer the currentPlayer to set
   */
  public void setCurrentPlayer(Player currentPlayer) {
    mCurrentPlayer = currentPlayer;
  }

  /**
   * @param name the name to set
   */
  public void setName(String name) {
    mName = name;
  }
  
  /**
   * @param players the players to set
   */
  public void setPlayers(ArrayList<Player> players) {
    if(players != null)
    {
      mPlayers = players;
      mPlayerNames.clear();
      for(int i = 0; i < players.size(); i++)
      {
        mPlayerNames.add(players.get(i).getName());
      }
    }
  }
  
  // ===========================================================
  // Inner and Anonymous Classes
  // ===========================================================
}




Java Source Code List

com.solidnw.gametimer.activities.GameActivity.java
com.solidnw.gametimer.activities.GroupActivity.java
com.solidnw.gametimer.activities.GroupManagementActivity.java
com.solidnw.gametimer.activities.MainActivity.java
com.solidnw.gametimer.activities.PlayerActivity.java
com.solidnw.gametimer.activities.PlayerManagementActivity.java
com.solidnw.gametimer.adapter.AbstractRemoveItemAdapter.java
com.solidnw.gametimer.adapter.ColorAdapter.java
com.solidnw.gametimer.adapter.DrawerListAdapter.java
com.solidnw.gametimer.adapter.GameModePagerAdapter.java
com.solidnw.gametimer.adapter.GroupAdapter.java
com.solidnw.gametimer.adapter.RemoveGroupListAdapter.java
com.solidnw.gametimer.adapter.RemoveMemberListAdapter.java
com.solidnw.gametimer.adapter.RemovePlayerListAdapter.java
com.solidnw.gametimer.database.DatabaseHelper.java
com.solidnw.gametimer.database.DatabaseLayer.java
com.solidnw.gametimer.fragments.GameFragment.java
com.solidnw.gametimer.fragments.GameModeFragment.java
com.solidnw.gametimer.fragments.GameModePagerFragment.java
com.solidnw.gametimer.fragments.GroupFragment.java
com.solidnw.gametimer.fragments.GroupManagementFragment.java
com.solidnw.gametimer.fragments.PlayerFragment.java
com.solidnw.gametimer.fragments.PlayerManagementFragment.java
com.solidnw.gametimer.listener.DrawerItemClickListener.java
com.solidnw.gametimer.model.DrawerConstants.java
com.solidnw.gametimer.model.GameModeConstants.java
com.solidnw.gametimer.model.GradientHelper.java
com.solidnw.gametimer.model.Gradient.java
com.solidnw.gametimer.model.Group.java
com.solidnw.gametimer.model.IntentConstants.java
com.solidnw.gametimer.model.Player.java
com.solidnw.gametimer.model.PreferencesConstants.java
com.solidnw.gametimer.model.Time.java