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

📄 risk.java

📁 java 开源游戏源码 RISK 联机对战 战棋类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

						}
						else {


							// @todo, do we set needinput to flase, so that ai wont go twice, if its there go
							// but then if there needinput was ignored coz this command was in the inbox, no needinput will get called

							// if it is NOT there go the set needinput to false
							if (game.getCurrentPlayer()!=null && !(game.getCurrentPlayer().getAddress().equals(Addr) && game.getCurrentPlayer().getType() == Player.PLAYER_HUMAN)) {

								needInput = false;

							}
							// if this command stopped the last needInput from being called, then this will be screwed
							// at worst AI or human wont get a chance to put any input in, game stalled

							output = "someone has gone: ";

							// get all the players and make all with the ip of the leaver become nutral
							Vector leavers = game.getPlayers();

							String newPlayerAddress="";

							// find the first player that is NOT playing on this computer
							// this happens in the same way on each computer
							for (int c=0; c< leavers.size() ; c++) {

								if ( !((Player)leavers.elementAt(c)).getAddress().equals(Addr) ) {


									newPlayerAddress = ((Player)leavers.elementAt(c)).getAddress();
									break;
								}

							}


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

								Player patc = ((Player)leavers.elementAt(c));

								if ( patc.getAddress().equals(Addr) ) {

									if ( patc.getType() == Player.PLAYER_HUMAN ) {

										output = output + patc.getName()+" ";

										if (game.getState() == RiskGame.STATE_NEW_GAME ) {

											// should never return false
											if ( game.delPlayer( patc.getName() ) ) {

												c--;

												controller.delPlayer( patc.getName() );

												patc = null;
											}

										}
										else {

											patc.setType( Player.PLAYER_AI_CRAP );

										}
									}

									if (patc!=null) {

										if (newPlayerAddress!=null) {
											patc.setAddress( newPlayerAddress );
										}
										else {

											// this means there are only spectators left
											// so nothing really needs to be done
											// game will stop, but hay there r no more players
										}
									}

								}

							}

						}


					}


					if (doclose) {

						// does not work from here
						closeBattle();

						controller.closeGame();
						output=resb.getString( "core.close.closed");

						game = null;
					}
					//else {
					//	output=resb.getString( "core.close.error.unable");
					//}





				}
				else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "closegame"); }

			}

/* THIS DOES NOT WORK AT ALL, ONLY HERE FOR HISTORY

			// LEAVE GAME
			else if (input.equals("leave")) {

				if (StringT.hasMoreTokens()==false) {

					if (chatSocket != null) {

						if (game.getState() != RiskGame.STATE_NEW_GAME ) {

							// get all the players and make all with the ip of the leaver become nutral
							Vector leavers = game.getPlayers();

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

								if ( ((Player)leavers.elementAt(c)).getAddress().equals(Addr) ) {

									((Player)leavers.elementAt(c)).setType(3); WRONG!
									((Player)leavers.elementAt(c)).setAddress("all"); WRONG!
								}

							}

						}

						try {

							// shut down the client
							if (chatSocket !=null && myAddress.equals(Addr) ) {
								game = null;
								outChat.close();
								inChat.close();
								chatSocket.close();
								chatSocket = null;
							}

						}
						catch (IOException except) {
							//System.out.println("IOException in main");
						}

						if (game == null) {

							// does not work from here
							closeBattle();

							controller.closeGame();
							output=resb.getString( "core.leave.left");
						}
						else {
							//{0} has left the game.
							if (game.getState()==RiskGame.STATE_NEW_GAME) {
								output = "someone has gone";
							}
							else {
								This will not work if the player quits when its not there go

								output = resb.getString("core.leave.otherhasleft").replaceAll("\\{0\\}", ((Player)game.getCurrentPlayer()).getName());
							}
						}

					}
					else {
						output=resb.getString( "core.leave.error.nonetwork");
					}

				}
				else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "leave"); }

			}
*/
			else if (game.getState()==RiskGame.STATE_NEW_GAME) {

				if (input.equals("choosemap")) {

					if (StringT.countTokens() >= 1) {
						String filename=GetNext();

						while ( StringT.hasMoreElements() ) {
							filename = filename + " " + GetNext();
						}

						try {

							boolean yesmissions = game.setMapfile(filename);

							setupPreview();

							controller.showCardsFile( game.getCardsFile() , yesmissions );
							//New map file selected: "{0}" (cards have been reset to the default for this map)
							output=resb.getString( "core.choosemap.mapselected").replaceAll( "\\{0\\}", filename);

						}
						catch (Exception e) {
							output=resb.getString( "core.choosemap.error.unable");
						}

					}
					else  { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "choosemap filename"); }

				}
				else if (input.equals("choosecards")) {

					if (StringT.countTokens() >= 1) {
						String filename=GetNext();
						while ( StringT.hasMoreElements() ) {
							filename = filename + " " + GetNext();
						}

						try {

							boolean yesmissions = game.setCardsfile(filename);

							controller.showCardsFile( game.getCardsFile() , yesmissions );
							//New cards file selected: "{0}"
							output=resb.getString( "core.choosecards.chosen").replaceAll( "\\{0\\}", filename);
						}
						catch (Exception e) {
							output=resb.getString( "core.choosecards.error.unable");
						}
					}
					else  { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "choosecards filename"); }

				}
				else if (input.equals("newplayer")) {

					if (StringT.countTokens()>=3) {

						String type=GetNext();

						if (type.equals("ai")) {

							type = type+" "+GetNext();
						}

						int t=getType(type);

						String c=GetNext();
						Color color=RiskGame.getColor( c );

						String name="";

						while ( StringT.hasMoreElements() ) {
							name = name + GetNext();
							if ( StringT.hasMoreElements() ) { name = name + " "; }
						}
						name = name.replaceAll("\\$","").replaceAll("\\\\","").replaceAll(" +"," ");

						// YURA:LOBBY CHANGE
						// ( ( chatSocket != null && game.addPlayer(t, name, color, Addr) ) || ( chatSocket == null && game.addPlayer(t, name, color, "all") ) )
						// name.replaceAll(" ","")+"#"+String.valueOf( Math.round(Math.random()*Long.MAX_VALUE) )

						if ( color != null && t != -1 && !name.equals("") && (   (  unlimitedLocalMode && game.addPlayer(t, name, color, "LOCALGAME" ) ) || ( !unlimitedLocalMode && game.addPlayer(t, name, color, Addr)    )    ) ) {
							//New player created, name: {0} color: {1}
							output=resb.getString( "core.newplayer.created")
										.replaceAll( "\\{0\\}", name)
										.replaceAll( "\\{1\\}", c);

							controller.addPlayer(t, name, color, Addr);
							//System.out.print("New player has Address: "+Addr+"\n");

						}
						else { output=resb.getString( "core.newplayer.error.unable"); }



					}
					else  { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "newplayer type (skill) color name"); }

				}
				else if (input.equals("delplayer")) {

					if (StringT.countTokens()>=1) {
						String name=GetNext();

						while ( StringT.hasMoreElements() ) {
							name = name +" "+ GetNext();
						}

						if ( game.delPlayer(name) ) {
							controller.delPlayer(name);
							output=resb.getString( "core.delplayer.deleted").replaceAll( "\\{0\\}", name);
						}
						else { output=resb.getString( "core.delplayer.error.unable"); }
					}
					else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "delplayer name"); }

				}
				else if (input.equals("info")) {

					if (StringT.hasMoreTokens()==false) {

						output=resb.getString( "core.info.title") + "\n";

						Vector players = game.getPlayers();

						for (int a=0; a< players.size() ; a++) {

							output = output + resb.getString( "core.info.player") + " " + ((Player)players.elementAt(a)).getName() +"\n";

						}

						output = output + resb.getString( "core.info.mapfile") + " "+ game.getMapFile() +"\n";
						output = output + resb.getString( "core.info.cardsfile") + " "+ game.getCardsFile() ;

					}
					else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "info"); }

				}
				else if (input.equals("autosetup")) {

					if (StringT.hasMoreTokens()==false) {

						if ( game.getPlayers().size() == 0) {

						    if (!replay) {

							for (int c=1;c<=RiskGame.MAX_PLAYERS;c++) {

								parser("newplayer " + riskconfig.getProperty("default.player"+c+".type")+" "+ riskconfig.getProperty("default.player"+c+".color")+" "+ riskconfig.getProperty("default.player"+c+".name") );

							}

							output = resb.getString( "core.info.autosetup");

						    }
						    else {

							output = "replay mode, nothing done";

						    }

						}
						else {

							output = resb.getString( "core.info.autosetup.error");

						}

					}
					else { output=resb.getString( "core.error.syntax").replaceAll( "\\{0\\}", "autosetup"); }

				}
				else if (input.equals("startgame")) {
					if (StringT.countTokens() >= 2 && StringT.countTokens() <= 4) {

						int n=((Vector)game.getPlayers()).size();

						int newgame_type = -1;
						int newgame_cardType = -1;
						boolean newgame_autoplaceall = false;
						boolean newgame_recycle = false;

						boolean nocrap = true;

						while (StringT.hasMoreTokens()) {

							String newOption = GetNext();

							if ( newOption.equals("domination") ) {

								newgame_type = RiskGame.MODE_DOMINATION;

							}
							else if ( newOption.equals("capital") ) {

								newgame_type = RiskGame.MODE_CAPITAL;

							}
							else if ( newOption.equals("mission") ) {

								newgame_type = RiskGame.MODE_SECRET_MISSION;

							}
							else if ( newOption.equals("increasing") ) {

								newgame_cardType = RiskGame.CARD_INCREASING_SET;

							}
							else if ( newOption.equals("fixed") ) {

								newgame_cardType = RiskGame.CARD_FIXED_SET;

							}
							else if ( newOption.equals("autoplaceall") ) {

								newgame_autoplaceall = true;

							}
							else if ( newOption.equals("recycle") ) {

								newgame_recycle = true;

							}
							else {

								nocrap = false;

							}

						}


						// checks all the options are correct to start a game

						if ( newgame_type!=-1 && newgame_cardType!=-1 && n>=2 && n<=RiskGame.MAX_PLAYERS && nocrap) {

							autoplaceall = newgame_autoplaceall;

							try {

								game.startGame(newgame_type,newgame_cardType,newgame_recycle);

							}
							catch (Exception e) {

								e.printStackTrace();

							}

						}


						// this checks if the game was able to start or not

						if (game.getState() != RiskGame.STATE_NEW_GAME ) {


						    controller.noInput();


							controller.startGame( unlimitedLocalMode );



						    if (!replay) {

							// this cant be if(unlimitedLocalMode) as then it wont get called on the lobby server, as it IS restricted
							if ( chatSocket == null ) {
								GameParser( "PLAYER " + game.getRandomPlayer() );
							}
							else if ( myAddress.equals(Addr) ) { // if this is a network game
								outChat.println( "PLAYER " + game.getRandomPlayer() ); // recursive call
							}


							// do that mission thing
							if (game.getGameMode()== RiskGame.MODE_SECRET_MISSION ) {

								// do that mission thing

								if ( chatSocket == null || myAddress.equals(Addr) ) {

									// give me a array of random numbers
									Random r = new Random();
									int a = game.getNoMissions();
									int b = game.getNoPlayers();

									String outputa="MISSION";

									for (int c=0; c< b ; c++) {

										outputa=outputa + " " + r.nextInt(a) ;
										a--;

									}

									if (chatSocket == null) {
										GameParser( outputa );
									}
									else if ( myAddress.equals(Addr) ) {
										outChat.println( outputa );
									}

								}

							}

⌨️ 快捷键说明

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