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

📄 gamesettings.java

📁 用java开发的一个实施策略游戏源码 值得学习一下
💻 JAVA
字号:
/*
	Netwar
	Copyright (C) 2002  Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.

	This file is part of Netwar.

	Netwar is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	Netwar is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Netwar; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package netwar.settings;
import netwar.Netwar;
import netwar.utils.*;
import java.io.Serializable;

/** STRUCT style class used for network coordination.
 * Contains a single GlobalSettings, plus one PlayerSettings per player.
 * When a setting is changed, it is submitted to the server, and propogated to all clients.
 * <p> The proper way to change a player's PlayerSettings, for example, is to alter
 * Netwar.netwar.pset (a PlayerSettings maintained for just this purpose) and then call:
 * Netwar.nc.clientBroadcastSettings(Netwar.nc.playerNumber, Netwar.netwar.pset, null);
 * @author Group N2 - Project Netwar
 * @author Daniel Grund
 */
public class GameSettings implements Serializable {
	/** The current collection of settings. This is updated by the server. */
	public static GameSettings currentSettings = null;
	/** The number of players currently connected to the game. This is subject to change until startGame() is called. */
	public int playerCount = 0;
	/** The GlobalSettings, which contains initialization data not specific to any one player. */
	public GlobalSettings global = new GlobalSettings(0);
	/** The PlayerSettings array, which contains the player-specific initialization data for each player. */
	public PlayerSettings players[] = new PlayerSettings[0];
	/** Creates a new instance of GameSettings */
	public GameSettings() {
	}
	/** Alters this GameSettings by replacing player pNumber's settings, or if pNumber == 0, replaces the GlobalSettings.
	 * This should only be called by the NetworkServer. This is part a thread-safing technique made
	 * necessary by the fact that all players will alter GameSettings.currentSettings at least once.
	 */
	public void reviseSettings(int pNumber, PlayerSettings pset, GlobalSettings gset) {
		if(pNumber == 0)
		{
			global = gset;
			return;
		}else{
			if(pNumber > playerCount) {
				Assert.notFalse(pNumber == playerCount + 1, "Player Count jump!");
				playerCount = pNumber;
				PlayerSettings ps[] = new PlayerSettings[pNumber];
				for(int i = 0; i < pNumber - 1; i++)
					ps[i] = players[i];
				ps[pNumber - 1] = pset;
				players = ps;
			}else{
				Assert.notFalse(pNumber > 0, "Player number less than one!");
				players[pNumber - 1] = pset;
			}
		}
		Netwar.netwar.getDataViewer().repaint();
	}
}

⌨️ 快捷键说明

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