gameframe.java
来自「java 开源游戏源码 RISK 联机对战 战棋类」· Java 代码 · 共 1,480 行 · 第 1/3 页
JAVA
1,480 行
else if (e.getSource()==graphbutton) {
displayGraph();
}
else if (e.getSource()==gobutton) {
goOn();
}
else if (e.getSource()==savebutton) {
String name = RiskUtil.getSaveFileName(
GameFrame.this,
RiskUtil.SAVES_DIR,
RiskFileFilter.RISK_SAVE_FILES
);
if (name!=null) {
go("savegame " + name );
}
}
else if (e.getSource()==resumebutton) {
displayMenu();
}
else if (e.getSource()==AutoEndGo) {
if ( AutoEndGo.isSelected() ) {
go("autoendgo on");
}
else {
go("autoendgo off");
}
}
else if (e.getSource()==closebutton) {
closeleave();
}
else if (e.getSource()==AutoDefend) {
if ( AutoDefend.isSelected() ) {
go("autodefend on");
}
else {
go("autodefend off");
}
}
else if (e.getSource()==helpbutton) {
try {
RiskUtil.openDocs( resb.getString("helpfiles.flash") );
}
catch(Exception er) {
JOptionPane.showMessageDialog(GameFrame.this,"Unable to open manual: "+er.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
};
/** Exit the Application */
public void closeleave() {
if (graphOn) { graphdialog.setVisible(false); graphOn=false; }
//if (localGame) {
go("closegame");
//}
//else {
// go("leave");
//}
}
public void repaintCountries() {
pp.repaintCountries( mapView );
/*
if (mapView==1) {
pp.repaintCountries( PicturePanel.VIEW_CONTINENTS );
}
else if (mapView==2) {
pp.repaintCountries( PicturePanel.VIEW_OWNERSHIP );
}
else if (mapView==3) {
pp.repaintCountries( PicturePanel.VIEW_BORDER_THREAT );
}
else if (mapView==4) {
pp.repaintCountries( PicturePanel.VIEW_CARD_OWNERSHIP );
}
else if (mapView==5) {
pp.repaintCountries( PicturePanel.VIEW_TROOP_STRENGTH );
}
else if (mapView==6) {
pp.repaintCountries( PicturePanel.VIEW_CONNECTED_EMPIRE );
}
*/
}
public void setGameStatus(String state) {
gameStatus=state;
if (state!=null) {
// the colors for the bottom display r collected here
colors = myrisk.getPlayerColors();
}
else {
colors = new Color[] { Color.GRAY };
}
repaint();
}
public void needInput(int s) {
gameState=s;
String goButtonText=null;
switch (gameState) {
case RiskGame.STATE_TRADE_CARDS: {
// after wiping out someone if you go into trade mode
pp.setC1(255);
pp.setC2(255);
goButtonText = resb.getString("game.button.go.endtrade");
break;
}
case RiskGame.STATE_PLACE_ARMIES: {
if (setupDone==false) {
goButtonText = resb.getString("game.button.go.autoplace");
}
break;
}
case RiskGame.STATE_ATTACKING: {
pp.setC1(255);
pp.setC2(255);
note = resb.getString("game.note.selectattacker");
goButtonText = resb.getString("game.button.go.endattack");
break;
}
case RiskGame.STATE_FORTIFYING: {
note = resb.getString("game.note.selectsource");
goButtonText = resb.getString("game.button.go.nomove");
break;
}
case RiskGame.STATE_END_TURN: {
goButtonText = resb.getString("game.button.go.endgo");
break;
}
case RiskGame.STATE_GAME_OVER: {
if (localGame) {
goButtonText = resb.getString("game.button.go.closegame");
}
else {
goButtonText = resb.getString("game.button.go.leavegame");
}
break;
}
case RiskGame.STATE_SELECT_CAPITAL: {
note = resb.getString("game.note.happyok");
goButtonText = resb.getString("game.button.go.ok");
break;
}
case RiskGame.STATE_BATTLE_WON: {
movedialog.setVisible(true);
break;
}
// for gameState 4 look in FlashRiskAdapter.java
// for gameState 10 look in FlashRiskAdapter.java
default: break;
}
if (goButtonText!=null) {
gobutton.setEnabled(true);
gobutton.setText(goButtonText);
}
else {
gobutton.setEnabled(false);
gobutton.setText("");
}
// can not use this as it sometimes just does not work, no idea why, mainly a vista problem
//if (!(gobutton.getText().equals(""))) {
// gobutton.setEnabled(true);
//}
//else {
// gobutton.setEnabled(false);
//}
if (gameState!=RiskGame.STATE_DEFEND_YOURSELF) {
cardsbutton.setEnabled(true);
missionbutton.setEnabled(true);
if (localGame) {
undobutton.setEnabled(true);
savebutton.setEnabled(true);
}
AutoEndGo.setEnabled(true);
AutoEndGo.setBackground( Color.white );
AutoEndGo.setSelected( myrisk.getAutoEndGo() );
AutoDefend.setEnabled(true);
AutoDefend.setBackground( Color.white );
AutoDefend.setSelected( myrisk.getAutoDefend() );
}
repaint(); // SwingGUI has this here, if here then not needed in set status
}
public void armiesLeft(int l, boolean s) {
note = resb.getString("game.note.armiesleft").replaceAll( "\\{0\\}", "" + l);
setupDone = s;
}
/**
* checks if the coordinates are in one of the
* tabs at the top of the window
*/
public int insideButton(int x, int y) {
int B=-1;
if (y >=9 && y < 32 ) {
int W=115;
if (x >= 24 && x < (24 + W)) {
B=PicturePanel.VIEW_CONTINENTS;
}
else if (x >= 139 && x < (139 + W)) {
B=PicturePanel.VIEW_OWNERSHIP;
}
else if (x >= 254 && x < (254 + W)) {
B=PicturePanel.VIEW_BORDER_THREAT;
}
else if (x >= 369 && x < (369 + W)) {
B=PicturePanel.VIEW_CARD_OWNERSHIP;
}
else if (x >= 484 && x < (484 + W)) {
B=PicturePanel.VIEW_TROOP_STRENGTH;
}
else if (x >= 599 && x < (599 + W)) {
B=PicturePanel.VIEW_CONNECTED_EMPIRE;
}
}
return B;
}
/** calls the parser with the command */
private BattleDialog battledialog;
public void setBattleDialog(BattleDialog bd) {
battledialog=bd;
}
/**
* calls the parser
* @param command sends the input command to the parser via a string
*/
public void go(String command) {
blockInput();
myrisk.parser(command);
}
public void blockInput() {
pp.setHighLight(255);
c1Id = -1;
if (gameState==RiskGame.STATE_ROLLING || gameState==RiskGame.STATE_DEFEND_YOURSELF) {
//this does not close it, just resets its params
battledialog.exitForm();
}
if (gameState==RiskGame.STATE_BATTLE_WON || gameState==RiskGame.STATE_FORTIFYING) {
// this hides the dailog
movedialog.exitForm();
}
if (gameState!=RiskGame.STATE_PLACE_ARMIES || !myrisk.getGame().getSetup() ) { noInput(); }
}
public void noInput() {
cardsbutton.setEnabled(false);
missionbutton.setEnabled(false);
undobutton.setEnabled(false);
savebutton.setEnabled(false);
AutoEndGo.setEnabled(false);
AutoEndGo.setBackground( Color.lightGray );
AutoDefend.setEnabled(false);
AutoDefend.setBackground( Color.lightGray );
gobutton.setText("");
gobutton.setEnabled(false);
note="";
gameState=0;
}
/**
* Returns an image of a given country
* @param a Index position of country
*/
public BufferedImage getCountryImage(int a) {
return pp.getCountryImage(a, true);
}
public void openMove(int min, int c1num, int c2num, boolean tacmove) {
int src = myrisk.hasArmiesInt( c1num );
int des = myrisk.hasArmiesInt( c2num );
BufferedImage c1img = pp.getCountryImage(c1num ,true);
BufferedImage c2img = pp.getCountryImage(c2num ,true);
Country country1 = myrisk.getGame().getCountryInt( c1num);
Country country2 = myrisk.getGame().getCountryInt( c2num);
Color color = myrisk.getCurrentPlayerColor();
movedialog.setup(tacmove, min, src, des, c1img, c2img, country1, country2, color);
}
//**********************************************************************
// MouseListener Interface
//**********************************************************************
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
if (e.getComponent() == gm) {
}
else if (e.getComponent() == pp) {
if (pp.getHighLight() != 255) {
pp.setHighLight(255);
pp.repaint();
}
e.consume();
}
else {
}
}
public void mousePressed(MouseEvent e) {
}
/**
* Used in the playing of the game
* @param e The MouseEvent object
*/
public void mouseReleased(MouseEvent e) {
if (e.getComponent() == gm) { // click on the menu
}
else if (e.getComponent() == pp) { // click on the picture panel
//System.out.print("Map Click\n");
//if ((e.getX() < PicturePanel.PP_X) && (e.getY() < PicturePanel.PP_Y) && (e.getX() >= 0) && (e.getY() >= 0) ) {
int pixColor = pp.getCountryNumber(e.getX(),e.getY());
if ( e.getModifiers() == java.awt.event.InputEvent.BUTTON1_MASK ) {
if (pixColor == 255 ) {
}
else if (gameState == RiskGame.STATE_PLACE_ARMIES) {
if ( myrisk.isOwnedCurrentPlayerInt(pixColor) && (setupDone || myrisk.hasArmiesInt(pixColor) == 0) ) {
go( "placearmies " + pixColor + " 1" );
}
}
else if (gameState == RiskGame.STATE_ATTACKING) {
if ( pixColor == c1Id ) {
c1Id = -1;
note=resb.getString("game.note.selectattacker");
pp.setC1(255);
pp.setC2(255);
repaint();
}
else if ( myrisk.isOwnedCurrentPlayerInt(pixColor) && ( myrisk.hasArmiesInt(pixColor) > 1) ) {
note=resb.getString("game.note.selectdefender");
c1Id = pixColor;
pp.setC1(pixColor);
pp.setC2(255);
repaint();
}
else if ( c1Id != -1 && !(myrisk.isOwnedCurrentPlayerInt(pixColor)) && myrisk.canAttack( c1Id , pixColor) ) {
pp.setC2(pixColor);
go("attack " + c1Id + " " + pixColor);
note=resb.getString("game.note.selectattacker");
repaint();
}
}
else if (gameState == RiskGame.STATE_FORTIFYING) {
if ( pixColor == c1Id ) {
c1Id = -1;
note=resb.getString("game.note.selectsource");
pp.setC1(255);
pp.setC2(255);
repaint();
}
else if ( myrisk.isOwnedCurrentPlayerInt(pixColor) && ( myrisk.hasArmiesInt(pixColor) > 1) && c1Id == -1) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?