⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessionserviceimpl.java

📁 Java mulitplayer strategy game. Adaptation of KDE Galaxy Conquest. (rules are changed - but still th
💻 JAVA
字号:
package net.sf.jawp.gf.server;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Collection;
import net.sf.jawp.gf.api.domain.GameOptions;

import net.sf.jawp.gf.api.domain.GameWorld;
import net.sf.jawp.gf.api.domain.Player;
import net.sf.jawp.gf.api.domain.User;

import net.sf.jawp.gf.api.services.SessionService;
import net.sf.jawp.gf.domain.GameWorldBase;
import net.sf.jawp.gf.domain.GameWorldRO;
import net.sf.jawp.gf.persistence.PersistenceController;
import net.sf.jawp.gf.system.RootSystem;
import net.sf.jawp.gf.system.RootSystemUnmodifiable;
import net.sf.jawp.gf.system.transaction.CreateGame;
import net.sf.jawp.gf.system.transaction.JoinGame;
/**
 * 
 * @author jarek
 * @version $Revision: 1.11 $
 *
 * @param <GAME> game type
 * @param <GAMEVIEW> RO view of game
 * @param <GAMESERVICE> service definition for game 
 */
public class SessionServiceImpl<GAMESERVICE , GAME extends GameWorldBase<GAMEVIEW>, GAMEVIEW extends GameWorldRO> implements SessionService<GAMESERVICE>
{
	private final User loggedUser; 
	
	private final PersistenceController<RootSystem<GAME, GAMEVIEW, GAMESERVICE>, RootSystemUnmodifiable< GAMEVIEW> > persistence;
	
	public SessionServiceImpl(final User user, final PersistenceController<RootSystem<GAME, GAMEVIEW, GAMESERVICE>, RootSystemUnmodifiable<GAMEVIEW> > persistence)
	{
		super();
		this.loggedUser = user;
		this.persistence = persistence;
	}

	public User getLoggedUser()
	{
		return this.loggedUser;
	}

	public GameWorld createGame(final String name, final GameOptions options)
	{
		final CreateGame<GAME, GAMEVIEW, GAMESERVICE> createCmd = new CreateGame<GAME, GAMEVIEW, GAMESERVICE>( name, options );
		return this.persistence.runCommand( createCmd);
	}
	
	public Collection<GameWorld> getGames()
	{
		return this.persistence.getUnmodifiableObject().getGameWorlds();
	}

	public final Player joinGame(final long gameKey)
	{
		final JoinGame<GAME, GAMEVIEW, GAMESERVICE> joinCmd = new JoinGame<GAME, GAMEVIEW, GAMESERVICE>(getLoggedUser(), gameKey);
		return this.persistence.runCommand(joinCmd);
	}

	public final void quitGame(final long gameKey, final long playerKey)
	{
		throw new UnsupportedOperationException();
	}

	public final Collection<Player> getUserPlayersForGame(final long gameKey)
	{
		final GAMEVIEW game = this.persistence.getUnmodifiableObject().findGameView(gameKey);
		return game.getPlayersForUser(getLoggedUser().getKey());
	}

	
	
	public GAMESERVICE getGameService(final long gameKey, final long playerKey)
	{
		final GAMEVIEW game = this.persistence.getUnmodifiableObject().findGameView( gameKey);
		final Player player = game.findPlayer( playerKey);
		return this.persistence.getSystemObject().createGameService( this.persistence, game, player );
	}

	
	public Remote getGameServiceRemote(final long gameKey, final long playerKey)
	throws RemoteException
	{
		final GAMEVIEW game = this.persistence.getUnmodifiableObject().findGameView( gameKey);
		final Player player = game.findPlayer( playerKey);
		return this.persistence.getSystemObject().createGameServiceRemote( this.persistence, game, player );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -