Code Search for Developers
 
 
  

NewGameAction.java from The Geronimo Project at Krugle


Show NewGameAction.java syntax highlighted

package geronimo.hoshigo.control.game;

import geronimo.hoshigo.control.MainController;
import geronimo.hoshigo.model.external.ComputerPlayer;
import geronimo.hoshigo.model.external.ComputerReferee;
import geronimo.hoshigo.model.external.GoProgram;
import geronimo.hoshigo.model.external.GtpProgram;
import geronimo.hoshigo.model.game.Game;
import geronimo.hoshigo.model.game.HumanPlayer;
import geronimo.hoshigo.model.game.InvalidHandicapException;
import geronimo.hoshigo.model.game.Player;
import geronimo.hoshigo.model.game.Referee;
import geronimo.hoshigo.model.goban.GoColor;
import geronimo.hoshigo.model.goban.IllegalGobanSize;
import geronimo.hoshigo.view.IconRegistry;
import geronimo.hoshigo.view.IconRegistry.IconSize;
import geronimo.hoshigo.view.newgame.NewGameWizard;

import java.util.Vector;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.wizard.WizardDialog;

public class NewGameAction extends Action
{
	private static NewGameAction instance;

	private NewGameAction()
	{
		super();
		this.setText("&Nouvelle partie@Ctrl+N");
		this.setImageDescriptor(IconRegistry.getDescriptor("new_game",
				IconSize.SMALL));
	}


	public void setActiveGame(Game game)
	{
	}
	
	public synchronized static NewGameAction getInstance()
	{
		if (instance == null)
		{
			instance = new NewGameAction();
		}
		return instance;
	}

	public void run()
	{
		NewGameWizard wizard = new NewGameWizard();
		WizardDialog dialog = new WizardDialog(MainController.getMainWindow()
				.getShell(), wizard);
		dialog.setBlockOnOpen(true);
		dialog.open();
		
		if(dialog.getReturnCode() == WizardDialog.OK)
		{
			// Création du joueur noir
			Player black;
			if( wizard.isBlackPlayerHuman() )
			{
				black = new HumanPlayer( wizard.getBlackPlayerHumanName(), GoColor.BLACK);
			}
			else
			{
				GoProgram program = new GtpProgram( wizard.getBlackPlayerConfig(), new Vector<String>() );
				black = new ComputerPlayer(program, GoColor.BLACK);
			}
			
			// Création du joueur blanc
			Player white;
			if( wizard.isWhitePlayerHuman() )
			{
				white = new HumanPlayer( wizard.getWhitePlayerHumanName(), GoColor.WHITE);
			}
			else
			{
				GoProgram program = new GtpProgram( wizard.getWhitePlayerConfig(), new Vector<String>() );
				white = new ComputerPlayer(program, GoColor.WHITE);
			}
			
			// Création de l'arbitre
			GoProgram program = new GtpProgram( wizard.getWhitePlayerConfig(), new Vector<String>() );
			Referee referee = new ComputerReferee(program);
			
			try
			{
				// Création de la partie
				Game game = new Game
				(
					wizard.getGobanSize(),
					wizard.getHandicap(),
					wizard.getKomi(),
					wizard.isFreeHandicap(),
					black,
					white,
					referee
				);
				
				// Ajout de la partie dans le répertoire des jeux
				MainController.getGameDirectory().addFreeGame(game);			
			}
			catch (InvalidHandicapException e)
			{
				e.printStackTrace();
			}
			catch (IllegalGobanSize e)
			{
				e.printStackTrace();
			}
		}
	}
}




See more files for this project here

The Geronimo Project

The Geronimo project concists of two software :\n- Geronimo Hoshigo : a playable graphical user interface to play Go\n- Geronimo Margo : a artificial intelligence program which plays Go

Project homepage: http://sourceforge.net/projects/geronimo
Programming language(s): Java,Pascal,Perl,PHP
License: gpl2

  CloseGameAction.java
  GameActionManager.java
  NewGameAction.java
  OpenGameAction.java
  SaveGameAction.java
  SaveGameAsAction.java