Exemple #1
0
	public GameEnded endGame(String gameUUID, String winnerUUID) {
		PersistenceManager pm = getPersistenceManager();
		GameEnded retObject;
		ArrayList<HashMap<String, String>> apnData =
				new ArrayList<HashMap<String, String>>();
		String winnerCode_Name;
		try {
			Game g = pm.getObjectById(Game.class, gameUUID);
			GameUser winner = pm.getObjectById(GameUser.class, winnerUUID);
			winnerCode_Name = winner.getUserCodeName();
			g.endGame(winner);
			winner.removeTarget(gameUUID);
			winner.addWin(); //Increments Winner's win count
			winner.setUserStatus("Registered");
			for (String usrUUID: g.getPlayerUUIDs()) {
				if (usrUUID != winnerUUID) {
					GameUser usr = pm.getObjectById(GameUser.class, usrUUID);
					usr.setUserStatus("Registered");
					HashMap<String, String> entry = 
							new HashMap<String, String>();
					entry.put("apn", usr.getAPN());
					entry.put("platformId", usr.getPlatformID());
					apnData.add(entry);
				}
			}
		} finally {
			pm.close();
		}
		retObject = new GameEnded(apnData, winnerCode_Name);
		return retObject;
	}
Exemple #2
0
	public UserKilled killUser(String gameUUID, String assassinUUID, String victimUUID) {
		PersistenceManager pm = getPersistenceManager();
		ArrayList<HashMap<String, String>> victimAPN = new ArrayList<HashMap<String, String>>();
		ArrayList<HashMap<String, String>> otherAPN = new ArrayList<HashMap<String, String>>();
		String victimCodeName;
		String nextTargetUUID;
		try {
			Game g = pm.getObjectById(Game.class, gameUUID);
			GameUser assassin = pm.getObjectById(GameUser.class, assassinUUID);
			GameUser victim = pm.getObjectById(GameUser.class, victimUUID);
			victim.setUserStatus("Playing - Dead");
			
			nextTargetUUID = killUser(gameUUID, assassin, victim);
			victimCodeName = victim.getUserCodeName();
			
			//Collects APN information
			for (String usrUUID: g.getPlayerUUIDs()) {
				GameUser usr = pm.getObjectById(GameUser.class, usrUUID);
				HashMap<String, String> entry = new HashMap<String, String>();
				entry.put("apn",usr.getAPN());
				entry.put("platformId", usr.getPlatformID());
				if (usrUUID == victimUUID) {
					victimAPN.add(entry);
				} else if (usrUUID != assassinUUID) {
					otherAPN.add(entry);
				}
			}
		} finally {
			pm.close();
		}
		UserKilled retObject = new UserKilled(otherAPN, victimAPN, 
				victimCodeName, nextTargetUUID);
		return retObject;
	}
Exemple #3
0
	public GameData getGamePlayData(String gameUUID) {
		PersistenceManager pm = getPersistenceManager();
		GameData retObject;
		try {
			Game g = pm.getObjectById(Game.class, gameUUID);
			retObject = pm.getObjectById(GameData.class, g.getGamePlayDataUUID());
		} finally {
			pm.close();
		}
		return retObject;
	}
Exemple #4
0
	//Game Management
	public GameCreated createGame(String hostUUID, ArrayList<String> playerUUIDs) {
		PersistenceManager pm = getPersistenceManager();
		HashMap<String,ArrayList<GameUserImage>> faceImages = new HashMap<String,ArrayList<GameUserImage>>();
		Game g = new Game(hostUUID, playerUUIDs);
		try {
			GameUser player;
			for (String a: playerUUIDs) {
				player = pm.getObjectById(GameUser.class, a);
				ArrayList<GameUserImage> playerImages = new ArrayList<GameUserImage>();
				for (String i: player.getUsrImageUUIDs()) {
					playerImages.add(pm.getObjectById(GameUserImage.class, i));
				}
				faceImages.put(a, playerImages);
			}
			pm.makePersistent(g);
		} finally {
			pm.close();
		}
		GameCreated retObject = new GameCreated(faceImages, g.getUUID());
		return retObject;
	}
Exemple #5
0
	public GameStarted startGame(String gameUUID, GameData data) {
		PersistenceManager pm = getPersistenceManager();
		GameStarted retObject;
		ArrayList<HashMap<String, String>> apnData =
				new ArrayList<HashMap<String, String>>();
		try {
			Game g = pm.getObjectById(Game.class, gameUUID);
			g.setGamePlayDataUUID(data.getUUID());
			g.startGame();
			pm.makePersistent(data);
			//Assigns Targets
			ArrayList<String> playerUUIDs = g.getPlayerUUIDs();
			Collections.shuffle(playerUUIDs, new Random(System.currentTimeMillis()));
			int numPlayers = playerUUIDs.size();
			for (int i= 0; i < numPlayers; i ++) {
				GameUser hunter = pm.getObjectById(GameUser.class, playerUUIDs.get(i));
				hunter.setTargetUUID(gameUUID, playerUUIDs.get((i+1)%numPlayers));
				hunter.setUserStatus("Playing - Alive");
			}
			
			//Collect APN Information
			String hostUUID = g.getHostUUID();
			for (String usrUUID: playerUUIDs) {
				if (usrUUID != hostUUID) {
					GameUser usr = pm.getObjectById(GameUser.class, usrUUID);
					HashMap<String, String> entry = 
							new HashMap<String, String>();
					entry.put("apn", usr.getAPN());
					entry.put("platformId", usr.getPlatformID());
					apnData.add(entry);
				}
			}
		} finally {
			pm.close();
		}
		retObject = new GameStarted(apnData);
		return retObject;
	}