Skip to content

Commit

Permalink
new: allow game creator to add an AI player
Browse files Browse the repository at this point in the history
  • Loading branch information
kroc702 committed Jun 8, 2016
1 parent c8eb5ee commit d55feb6
Show file tree
Hide file tree
Showing 17 changed files with 1,255 additions and 1,006 deletions.
Binary file added misc/stai.pdn
Binary file not shown.
15 changes: 11 additions & 4 deletions src/com/fullmetalgalaxy/client/game/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.fullmetalgalaxy.model.persist.gamelog.EbAdmin;
import com.fullmetalgalaxy.model.persist.gamelog.EbEvtCancel;
import com.fullmetalgalaxy.model.persist.gamelog.EbEvtMessage;
import com.fullmetalgalaxy.model.persist.gamelog.EbEvtMove;
import com.fullmetalgalaxy.model.persist.gamelog.EbEvtPlayerTurn;
import com.fullmetalgalaxy.model.persist.gamelog.EbGameJoin;
import com.fullmetalgalaxy.model.persist.gamelog.EventsPlayBuilder;
Expand Down Expand Up @@ -489,11 +490,12 @@ public void nextEvent()
AnEvent event = m_modelUpdate.getGameEvents().get( index );
index++;

// if we receive and end turn event after an hidden parallel time step
// we need to unexec my private event logs
// new turn event
if( event instanceof EbEvtPlayerTurn && getGame().getCurrentPlayerIds().size() == 1 )
{
isNewPlayerTurn = true;
// if we receive and end turn event after an hidden parallel time step
// we need to unexec my private event logs
if( getGame().isTimeStepParallelHidden( getGame().getCurrentTimeStep() ) && getMyRegistration() != null
&& !getMyRegistration().getTeam( getGame() ).getMyEvents().isEmpty() )
{
Expand Down Expand Up @@ -521,7 +523,6 @@ && getGame().isTimeStepParallelHidden( getGame().getCurrentTimeStep() )
event.exec( getGame() );
getGame().updateLastTokenUpdate( null );
AppRoot.getEventBus().fireEvent( new GameActionEvent( event, this ) );
// nextEvent();
}
else
{
Expand All @@ -534,7 +535,12 @@ && getGame().isTimeStepParallelHidden( getGame().getCurrentTimeStep() )
getGame().addEvent( event );
getGame().updateLastTokenUpdate( null );
AppRoot.getEventBus().fireEvent( new GameActionEvent( event, this ) );
// nextEvent();
// this allow player to select his token before the animation end
if( event instanceof EbEvtMove
&& AppMain.instance().getMyAccount().getId() == ((EbEvtMove)event).getAccountId() )
{
nextEvent();
}
}
} catch( Throwable e )
{
Expand All @@ -554,6 +560,7 @@ && getMyRegistration() != null
&& (getGame().getCurrentPlayerIds().size() == 0 || getGame().getCurrentPlayerIds().contains(
getMyRegistration().getId() )) )
{
isNewPlayerTurn = false;
Window.alert( MAppBoard.s_messages.yourTurnToPlay() );
}
}
Expand Down
155 changes: 155 additions & 0 deletions src/com/fullmetalgalaxy/client/game/board/DlgAIJoinGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/* *********************************************************************
*
* This file is part of Full Metal Galaxy.
* http://www.fullmetalgalaxy.com
*
* Full Metal Galaxy is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Full Metal Galaxy 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Full Metal Galaxy.
* If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 to 2015 Vincent Legendre
*
* *********************************************************************/
package com.fullmetalgalaxy.client.game.board;

import com.fullmetalgalaxy.model.persist.EbPublicAccount;
import com.fullmetalgalaxy.model.persist.gamelog.EbGameJoin;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
* @author Kroc
*
* During the game join process, this dialog inform player that other players are real
* and ask password if game is private
*/

public class DlgAIJoinGame extends DialogBox implements ClickHandler
{
// UI
private Button m_btnCancel = new Button( MAppBoard.s_messages.cancel() );
private Button m_btnOk = new Button( MAppBoard.s_messages.ok() );
private Panel m_panel = new VerticalPanel();
private ListBox listAI = new ListBox();
IntegerBox intAPBonus = new IntegerBox();


private static DlgAIJoinGame s_dlg = null;

public static DlgAIJoinGame instance()
{
if( s_dlg == null )
{
s_dlg = new DlgAIJoinGame();
}
return s_dlg;
}


/**
*
*/
public DlgAIJoinGame()
{
// auto hide / modal
super( false, true );

// Set the dialog box's caption.
setText( MAppBoard.s_messages.joinTitle() );

// TODO ask server to get this list
listAI.addItem( "stai", "5180826044071936" );
listAI.addItem( "killerai", "5087341249036288" );
listAI.addItem( "niceai", "5148254354276352" );
// localhost account
// listAI.addItem( "test", "5629499534213120" );
listAI.setItemSelected( 0, true );
listAI.setVisibleItemCount( 3 );

m_btnCancel.addClickHandler( this );
m_btnOk.addClickHandler( this );


setWidget( m_panel );
}


/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.ClickHandler#onClick(com.google.gwt.user.client.ui.Widget)
*/
@Override
public void onClick(ClickEvent p_event)
{
if( p_event.getSource() == m_btnCancel )
{
this.hide();
return;
}
else if( p_event.getSource() == m_btnOk )
{
EbPublicAccount account = new EbPublicAccount();
account.setId( Long.parseLong( listAI.getValue( listAI.getSelectedIndex() ) ) );
account.setPseudo( listAI.getItemText( listAI.getSelectedIndex() ) );
account.setAI( true );
EbGameJoin joinEvent = new EbGameJoin();
joinEvent.setAccountId( account.getId() );
joinEvent.setAccount( account );
joinEvent.setActionPointBonus( intAPBonus.getValue() );

this.hide();

DlgJoinChooseColor.instance().setJoinEvent( joinEvent );
DlgJoinChooseColor.instance().show();
DlgJoinChooseColor.instance().center();
return;
}

}


/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.PopupPanel#show()
*/
@Override
public void show()
{
m_panel.clear();

m_panel.add( new HTML( "Add an automatic player<hr/>Action point bonus:" ) );

intAPBonus.setValue( 0 );
m_panel.add( intAPBonus );

m_panel.add( new HTML( "Select avaliable player" ) );

m_panel.add( listAI );



HorizontalPanel hPanel = new HorizontalPanel();
hPanel.add( m_btnCancel );
hPanel.add( m_btnOk );
m_panel.add( hPanel );

super.show();
}

}
Loading

0 comments on commit d55feb6

Please sign in to comment.