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

📄 riskgame.java

📁 java 开源游戏源码 RISK 联机对战 战棋类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * @return Riskgame Returns the game, which is already set to null
	 */
	public static RiskGame closeGame() {
		RiskGame game = null;
		return game;
	}

	/**
	 * Saves the current game to a file
	 * @param file The filename of the save
	 * @return boolean Return trues if you saved, returns false if you cannot
	 */
	public boolean saveGame(String file) { //added RiskGame parameter g, so remember to change in parser

		try {

			risk.engine.RiskUtil.saveFile(file,this);

			//XMLEncoder e = new XMLEncoder( new BufferedOutputStream( new FileOutputStream(file)));
			//e.writeObject(this);
			//e.close();

		}
		catch (Exception e) {
			//e.printStackTrace();
			//System.out.println(e.getMessage());
			return false;
		}
		return true;
	}

	/**
	 * Gets the state of the game
	 * @return int Returns the game state
	 */
	public int getState() {
		return gameState;
	}

	/**
	 * Checks if there are any empty countries
	 * @return boolean Return trues if no empty countries, returns false otherwise
	 */
	public boolean NoEmptyCountries() {

		// find out if there are any empty countries

		Country empty=null;


		for (int c=0; c< Countries.length ; c++) {

			if ( Countries[c].getOwner() == null ) {
				empty = Countries[c];
				c=Countries.length;
			}

		}
		if (empty != null ) {
			return false;
		}
		else {
			return true;
		}

	}

	/**
	 * Checks if the set up is completely
	 * @return boolean Return trues if the set up is complete, returns false otherwise
	 */
	public boolean getSetup() {

		return ( setup == Players.size() );

		//if (setup != Players.size() ) {
		//	return false;
		//}
		//else {
		//	return true;
		//}

	}

	/**
	 * get the value od the trade-cap
	 * @return boolean Return trues if tradecap is true and false otherwise
	 */
	public boolean getTradeCap() {
		return tradeCap;
	}

	/**
	 * Gets the game mode
	 * @return int Return the game mode
	 */
	public int getGameMode() {
		return gameMode;
	}

	/**
	 * Gets the current player
	 * @return player Return the current player
	 */
	public Player getCurrentPlayer() {
		return currentPlayer;
	}

	/**
	 * Gets all the players
	 * @return Vector Return all the players
	 */
	public Vector getPlayers() {
		return Players;
	}

	/**
	 * Gets all the players
	 * @return Vector Return all the players
	 */
	public Vector getPlayersStats() {

		for (int c=0; c< Players.size() ; c++) {
			workOutEndGoStats( (Player)Players.elementAt(c) );
		}

		return Players;
	}

	/**
	 * Gets the attacking country
	 * @return Country the attacking country
	 */
	public Country getAttacker() {
		return attacker;
	}

	/**
	 * Gets the defending country
	 * @return Country the defending country
	 */
	public Country getDefender() {
		return defender;
	}

	/**
	 * Gets the ImagePic
	 * @return URL ImagePic
	 */
	public String getImagePic() {
		return ImagePic;
	}

	public String getPreviewPic() {
		return previewPic;
	}

	public String getMapName() {
		return mapName;
	}

	/**
	 * Gets the ImageMap
	 * @return URL ImageMap
	 */
	public String getImageMap() {
		return ImageMap;
	}

	public String getCardsFile() {

		return cardsfile; //.getFile().substring( cardsfile.getFile().lastIndexOf("/")+1 );
	}

	public String getMapFile() {

		return mapfile; //.getFile().substring( mapfile.getFile().lastIndexOf("/")+1 );
	}

	public Vector getCards() {
		return Cards;
	}

	/**
	 * Rolls a certain number of dice
	 * @param nod Number of dice you want to roll
	 * @return int[] Returns an array which was the results of the roll, ordered from highest to lowest
	 */
	public int[] rollDice(int nod) {

		int[] dice = new int[nod];

		for (int j=0; j<nod; j++) {
			dice[j]=r.nextInt( 6 );
		}

		// NOW SORT THEM, biggest at the beggining
		for (int i=0; i<nod-1; i++) {
			int temp, pos=i;

			for(int j=i+1; j<nod; j++)
				if(dice[j]>dice[pos])
					pos=j;
			temp = dice[i];
			dice[i] = dice[pos];
			dice[pos] = temp;
		}

/*
System.out.print("After sorting, the dice are:\n");

String str="[";
if(dice.length>0) {
str+=(dice[0]+1);
for(int i=1; i<dice.length; i++)
str+="|"+(dice[i]+1);
}
System.out.print(str+"]\n");
*/
		return dice;

	}

	/**
	 * Gets the number of continents which are owned by a player
	 * @param p The player you want to find continents for
	 * @return int Return the number of continents a player owns
	 */
	public int getNoContinentsOwned(Player p) {

		int total=0;

		for (int c=0; c< Continents.length ; c++) {

			if ( Continents[c].isOwned(p) ) {
				total++;
			}

		}
		return total;
	}

	/**
	 * Gets a country
	 * @param name The name of the country
	 * @return Country Return the country you are looking for, if it exists. Otherwise returns null
	 *
	// * @deprecated

	public Country getCountry(String name) {

		for (int c=0; c< Countries.length ; c++) {

			if ( name.equals(Countries.[c].getName()) ) {
				return Countries[c];
			}

		}
		System.out.println( "ERROR: Country not found: " + name );
		return null;

	}
	 */


	/**
	 * Tries to find a country by its name.
	 * This function should only be used if a user has entered the name manually!
	 *
	 * @param name The name of the country
	 * @return Country Return the country you are looking for, if it exists. Otherwise returns null

	public Country getCountryByName(String name) {

		for (int c=0; c< Countries.length ; c++) {

			if ( name.equals(Countries[c].getName()) ) {
				return Countries[c];
			}

		}
		System.out.println( "ERROR: Country not found: " + name );
		return null;

	}//public Country getCountryByName(String name)
	 */


	/**
	 * returns the country with the given color (ID)
	 */
	public Country getCountryInt(int color) {

		if (color <= 0 || color > Countries.length ) { return null; }
		else return Countries[color-1];

	}



	/**
	 * returns the country with the given color (ID)
	 * the string is converted to an int value

	public Country getCountryInt(String strId)
	{
		int nId = -1;
		try {
			nId = Integer.parseInt( strId);
		} catch( NumberFormatException e) {
			System.out.println( "ERROR: Can't convert number \"" + strId + "\" to a number." );
			return null;
		}

		return getCountryInt(nId);
	}//public Country getCountryInt(String nId)
	 */


	/**
	 * Gets a cards
	 * @param name
	 * @return Card Return the card you are looking for, if it exists. Otherwise returns null
	 */
	public Card[] getCards(String name1,String name2,String name3) {

		Card[] c = new Card[3];

		Vector playersCards = new Vector( currentPlayer.getCards() );

		jumppoint: for (int a=0;a<3;a++) {

			String name;

			if (a==0) { name = name1; }
			else if (a==1) { name = name2; }
			else { name = name3; } // if (a==2)

			for (int b=0; b< playersCards.size(); b++) {

				if (name.equals(Card.WILDCARD) && name.equals( ((Card)playersCards.elementAt(b)).getName() ) ) {
					c[a] = (Card) playersCards.remove(b);
					continue jumppoint;
				}
				else if ( (Country)((Card)playersCards.elementAt(b)).getCountry() != null && name.equals( ((Country)((Card)playersCards.elementAt(b)).getCountry()).getColor()+"" ) ) {
					c[a] = (Card) playersCards.remove(b);
					continue jumppoint;
				}

			}

		}

		return c;

	}

	public Card findCard(String name) {

		for (int c=0; c< Cards.size() ; c++) {

			if (name.equals(Card.WILDCARD) && name.equals( ((Card)Cards.elementAt(c)).getName() ) ) {
				return ((Card)Cards.elementAt(c));
			}
			else if ( (Country)((Card)Cards.elementAt(c)).getCountry() != null && name.equals( ((Country)((Card)Cards.elementAt(c)).getCountry()).getColor()+"" ) ) {
				return ((Card)Cards.elementAt(c));
			}

		}
		return null;

	}

	/**
	 * Gets a color
	 * @param s The color you want
	 * @return Color Return the color you are looking for, if it exists. Otherwise returns null
	 */
	public static Color getColor(String s) {

		if (s.equals("black"))      { return Color.BLACK; }
		if (s.equals("blue"))       { return Color.BLUE; }
		if (s.equals("cyan"))       { return Color.CYAN; }
		if (s.equals("darkgray"))   { return Color.DARK_GRAY; }
		if (s.equals("gray"))       { return Color.GRAY; }
		if (s.equals("green"))      { return Color.GREEN; }
		if (s.equals("lightgray"))  { return Color.LIGHT_GRAY; }
		if (s.equals("magenta"))    { return Color.MAGENTA; }
		if (s.equals("orange"))     { return Color.ORANGE; }
		if (s.equals("pink"))       { return Color.PINK; }
		if (s.equals("red"))        { return Color.RED; }
		if (s.equals("white"))      { return Color.WHITE; }
		if (s.equals("yellow"))     { return Color.YELLOW; }

		try {

			return Color.decode(s);

		}
		catch(Exception ex) {

			//System.out.print("Error: unable to find color "+s+".\n"); // testing
			return null;

		}


	}

	/**
	 * Gets a cards
	 * @param s The number you want to parse
	 * @return int The number you wanted
	 * @throws NumberFormatException You cannot parse the string
	 */
	public static int getNumber(String s) {
		try {
			return Integer.parseInt(s);
		}
		catch (NumberFormatException e) {
			return -1;
		}
	}

	/**
	 * Gets the number of players in the game
	 * @return int Return the number of number of players
	 */
	public int getNoPlayers() {
		return Players.size();
	}

	/**
	 * Gets the countries in the game
	 * @return Vector Return the Countries in the current game
	 */
	public Country[] getCountries() {

		return Countries;
	}

	/**
	 * Gets the continents in the game
	 * @return Vector Return the Continents in the current game
	 */
	public Continent[] getContinents() {
		return Continents;
	}

	/**
	 * Gets the number of countries in the game
	 * @return int Return the number of countries in the current game
	 */
	public int getNoCountries() {
		return Countries.length;
	}

	public int getNoContinents() {

		return Continents.length;

	}

	/**
	 * Gets the allocated Missions in the game
	 * @return Vector Return the Missions in the current game
	 */
	public Vector getMissions() {
		return Missions;
	}

	/**
	 * Gets the number of Missions in the game
	 * @return int Return the number of Missions in the game
	 */
	public int getNoMissions() {
		return Missions.size();
	}

	public int getNoCards() {
		return Cards.size();
	}

	/**
	 * Set the Default Map and Cards File
	 */
	public static void setDefaultMapAndCards(String a,String b) {

		defaultMap=a;
		defaultCards=b;

		// not needed as is reset each time a new RiskGame object is created
		//risk.engine.translation.MapTranslator.setMap( a );
		//risk.engine.translation.MapTranslator.setCards( b );

	}
	/**
	 * @return the current Card Mode
	 */
	public int getCardMode()
	{
	 return cardMode;
	}

	public static Color getRandomColor() {

		return Color.getHSBColor( (float)Math.random(), 0.5F, 1.0F );

	}

}

⌨️ 快捷键说明

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