Package net.sf.mrailsim.main

Source Code of net.sf.mrailsim.main.Game

/************************************************************************************

    MRailSim - a model railway simulation program - http://mrailsim.sourceforge.net/
    Copyright (C) 2004,2007  Bernd Arnold

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

   
************************************************************************************/


package net.sf.mrailsim.main;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.sf.mrailsim.rails.NodeManager;
import net.sf.mrailsim.rails.TrackManager;
import net.sf.mrailsim.trains.TrainManager;

public class Game {

  public static TrackManager trackManager;
  public static NodeManager nodeManager;
  public static TrainManager trainManager;
//  TrackManager trackManager = null;
 
  MapReader mapReader = null;
 

  public Game() {
    trackManager = new TrackManager();
    nodeManager = new NodeManager();
    trainManager = new TrainManager();
  }
 
  public void start() {
    System.out.println( "Game options:" );
    System.out.println( "  Number of tracks: " + trackManager.getTrackCount() );
    System.out.println( "  Number of nodes:  " + nodeManager.getNodeCount() );
    System.out.println( "Starting game now." );
  }
 
  void startMapReader( String s ) {
    Pattern pattern = Pattern.compile( "^X=(.*),Y=(.*),Grid=(.*)$" );
    Matcher matcher = pattern.matcher( s );
    if ( ! matcher.matches() ) {
      // TODO: Handle right
      System.err.println( "startMapReader mismatch: " + s );
      System.exit(1);
    }
   
    int x = Integer.parseInt( matcher.group( 1 ) );
    int y = Integer.parseInt( matcher.group( 2 ) );
    int grid = Integer.parseInt( matcher.group( 3 ) );
   
    mapReader = new MapReader( x, y, grid );
  }

  void passLineToMapReader(String msg) {
    mapReader.addRow( msg );
  }

  public void finishMapReader( Program program ) {
    mapReader.output();
    mapReader.generate();
    mapReader.passToProgram( program );
    mapReader = null;
  }
 
}
TOP

Related Classes of net.sf.mrailsim.main.Game

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.