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

📄 startarena.java

📁 一个简单的client server模式的游戏实例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		String panelFactoryClassName = propertyLoader.getStringProperty(gameClassName + ".factory", null);		if (panelFactoryClassName == null) {			panelFactoryClassName = gameClassName + "MatchPanelFactory";		}		MatchPanelFactory matchPanelFactory = (MatchPanelFactory)getInstanceOfClass(panelFactoryClassName);		arena.registerGame(game, gameName, gameDescription, matchPanelFactory);		return gameName;	}		private static void registerGames(PropertyLoader propertyLoader) {		String [] gameClassNames = propertyLoader.getStringArrayProperty("Games");		String gameClassName = null;		boolean loadingSucceeded = false;		try {			for (int i = 0; i < gameClassNames.length; i++) {				gameClassName = gameClassNames[i];				registerOneGame(propertyLoader, gameClassName);			}			loadingSucceeded = true;		} catch (ClassNotFoundException e) {			tellUser("Failed to load game class or associated match panel factory \"" + gameClassName + "\":" + e.getMessage());		} catch (NoSuchMethodException e) {			tellUser("Game class \"" + gameClassName + "\" does not define a static method getInstance().\n" + e.getMessage());		} catch (Exception e) {			tellUser("Game class \"" + gameClassName + "\" static method getInstance() threw exception: " + e.getMessage());		}		if (!loadingSucceeded) {			System.exit(1);		}	}			private static void setupDemo(PropertyLoader propertyLoader) {		if (!propertyLoader.getBooleanProperty("SetupDemo", false)) {			return;		}		String gameName = propertyLoader.getStringProperty("DemoGameName", "TicTacToe");		tellUser("Setting up demo for game " + gameName);				try {			arena.getGameByName(gameName);		} catch (GameNotFoundException e) {			tellUser("Demo game \"" + gameName + "\" is not registered with arena.");			tellUser("The Games and <game class>.name properties should be set for each game. For example:");			tellUser("Games=org.globalse.arena.ttt.TicTacToe");			tellUser("org.globalse.arena.ttt.TicTacToe.name=TicTacToe");			System.exit(1);		}				User alice = null, joe = null, mike = null, mark = null, mary = null, bob = null;		try {			// Create demo users			alice = arena.createUser("alice", "alicepass");			joe = arena.createUser("joe", "joepass");			mike = arena.createUser("mike", "mikepass");			mark = arena.createUser("mark", "markpass");			mary = arena.createUser("mary", "marypass");			bob = arena.createUser("bob", "bobpass");					} catch (Exception e) {			tellUser("Failed to create demo users.");			e.printStackTrace();			System.exit(1);		}				// register the KO tournament style if needed		try {			if (arena.getTournamentStyleByName(KNOCK_OUT) == null) {				TournamentStyle ko = (TournamentStyle)getInstanceOfClass(KNOCKOUT_CLASSNAME);				arena.registerTournamentStyle(KNOCK_OUT, ko);			}		} catch (Exception e) {			tellUser("Failed to load knock out tournament style.");			e.printStackTrace();			System.exit(1);		}				try {			String operatorName = propertyLoader.getStringProperty("Operator", "admin");			String operatorPassword = propertyLoader.getStringProperty("OperatorPassword", "adminpass");			String operatorTicket = arena.login(operatorName, operatorPassword);			tellUser("Operator logged in with ticket: " + operatorTicket);			String bobTicket = arena.login("bob", "bobpass");			tellUser("Bob logged in with ticket: " + bobTicket);			LeagueInfo linfo;			RemoteLeague l;			TournamentInfo tinfo;			RemoteTournament t;						linfo = arena.createLeague(operatorTicket, bob, "Expert " + gameName + " League", "A restricted league for insiders.", gameName, KNOCK_OUT);			l = linfo.getLeague();			l.addPlayer(bobTicket, alice);			l.addPlayer(bobTicket, joe);			tinfo = linfo.getLeague().createTournament(bobTicket, "2003 Championship", "");			t = tinfo.getTournament();			t.openRegistration(bobTicket);			t.acceptPlayer(bobTicket, alice);			t.acceptPlayer(bobTicket, joe);			t.closeRegistration(bobTicket);			t.launch(bobTicket);			tinfo = linfo.getLeague().createTournament(bobTicket, "2004 Championship", "");			t = tinfo.getTournament();			t.openRegistration(bobTicket);						linfo = arena.createLeague(operatorTicket, bob, "Novice " + gameName + " League", "A simple, unrestricted league for beginners.", gameName, KNOCK_OUT);			linfo.getLeague().unrestrict(bobTicket);			tinfo = linfo.getLeague().createTournament(bobTicket, "Paper Cup", "An adhoc knockout tournament.");			t = tinfo.getTournament();			t.openRegistration(bobTicket);			t.acceptPlayer(bobTicket, joe);			t.acceptPlayer(bobTicket, mike);			t.acceptPlayer(bobTicket, alice);			t.acceptPlayer(bobTicket, mark);			t.acceptPlayer(bobTicket, mary);			t.closeRegistration(bobTicket);			t.launch(bobTicket);		} catch (RemoteException e) {			e.printStackTrace();		} catch (ArenaException e) {			e.printStackTrace();		}		tellUser("Demo setup finished.");	}		public static void main(String[] args) {				// Load properties from the arena specified file or URL		String propertiesFileName = null;		if (args.length > 0) {			propertiesFileName = args[0];		}		//propertiesFileName = "arena.properties";		PropertyLoader propertyLoader = loadProperties(propertiesFileName);				// The code base property is used for loading games and tournament styles		// If the CodeBase property is specified, initialize the corresponding		// RMI code base property so that RMI clients can also dynamically load		// the same objects.		codeBase = propertyLoader.getStringProperty("CodeBase", null);		if (codeBase != null) {			System.setProperty("java.rmi.server.codebase", codeBase);		}				// Initialize the logger using the properties file.		initLogger(propertiesFileName);				// The RMI secutiry manager prevents dynamically loaded classes to access		// local resources (e.g., the file system). Allow the creation of sockets		// so that match front ends and game peers can still connect to this server,		// overriding the site policy.		System.setSecurityManager(new RMISecurityManager() {					// This enables the arena server to accept RMI calls from match front ends					// and game peers, regardless of the current policy					public void checkAccept(String host, int port) {}					// This enables the arena server to make connections to match front ends					// to send notification events over the listener interfaces					public void checkConnect (String host, int port) {}					public void checkConnect (String host, int port, Object context) {}				});				// Create an arena and register it as a remote object		initArena(propertyLoader);				// Register tournament styles		registerTournamentStyles(propertyLoader);				// Register games		registerGames(propertyLoader);				// Create test objects if the SetupDemo property is set to true.		setupDemo(propertyLoader);				// Wait for RMI connections. Connections will be handeled in separate		// threads created by RMI.		while (true) {			try { Thread.sleep(5000); } catch (InterruptedException e) {}		}	}}

⌨️ 快捷键说明

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