Android Open Source - FriendScore Game Object






From Project

Back to project page FriendScore.

License

The source code is released under:

MIT License

If you think the Android project FriendScore 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.prnk.friendscore;
/*w w w .j a v  a2s .c om*/
import java.util.ArrayList;
import java.util.List;

public class GameObject {
  private long id;
  private String title;
  public ArrayList<TeamObject> teams;
  private final String defaultTitle = "New Scoreboard";

  public GameObject() {
    this.title = defaultTitle;
    this.teams = new ArrayList<TeamObject>();
    this.id = 0;
  }
  
  public GameObject(String title) {
    this.title = title;
    this.teams = new ArrayList<TeamObject>();
    this.id = 0;
  }
  
  public String Title() {
    return this.title;
  }
  
  public TeamObject Team(int index) {
    if(index < 0 || index >= teams.size()) {
      return null;
    }
    return this.teams.get(index);
  }
  
  public void SetTitle(String title) {
    title = title.trim();
    if(title.equals("") || title.isEmpty()) {
      this.title = defaultTitle;
    } else {
      this.title = title;
    }
  }
  
  public long GetId(){
    return this.id;
  }
  
  public void SetId(long identifier){
    this.id = identifier;
  }
  
  public void AddTeam(TeamObject team) {
    this.teams.add(team);
  }
  
  public void SetTeams(ArrayList<TeamObject> teams) {
    this.teams = teams;;
  }
  
  public void RemoveTeam(int index) {
    this.teams.remove(index);
  }
  
  public int TeamIndex(TeamObject team) {
    return this.teams.indexOf(team);
  }

  public TeamObject GetTeamByName(String name) {
    for(TeamObject team : teams) {
      if(team.Name().equals(name)) {
        return team;
      }
    }
    return null;
  }
  
  public void RemoveSelectedTeams() {
    ArrayList<TeamObject> newTeams = new ArrayList<TeamObject>();
    for(TeamObject team : teams) {
      if(!team.Selected()) {
        newTeams.add(team);
      }
    }
    this.teams = newTeams;
  }
  
  public boolean ContainsTeamName(String name) {
    for(TeamObject team : teams) {
      if(team.Name().equals(name)) {
        return true;
      }
    }
    return false;
  }
  
  public static GameObject GetGameByName(List<GameObject> games, String title) {
    for(GameObject game : games) {
      if(game.Title().equals(title)) {
        return game;
      }
    }
    return null;
  }
}




Java Source Code List

com.prnk.friendscore.DashboardActivity.java
com.prnk.friendscore.DataBaseWrapper.java
com.prnk.friendscore.EditActivity.java
com.prnk.friendscore.GameObject.java
com.prnk.friendscore.PlayerObject.java
com.prnk.friendscore.ScoreObject.java
com.prnk.friendscore.TeamObject.java