Example #1
0
		private static async Task<PyramidGame> RunGameAsync()
		{
			var visualizationService = new ConsoleVisualizationService (false);

			// Set up local and opponent player.
			IPlayer localPlayer = new LocalConsolePlayer (visualizationService);
			//localPlayer = new AIConsolePlayer ();
			localPlayer.Name = "Local Player";

			IPlayer opponentPlayer = new AIConsolePlayer ();
			opponentPlayer.Name = "Opponent";

			var loggingService = new FileLoggingService ();

			// Create the game.
			var game = await PyramidGame.CreateGame (
				new CommonPlatformServicesImpl (),
				loggingService,
				visualizationService,
				localPlayer,
				opponentPlayer, false);

			// Quitting the console version is done by handling ESC during the local player's move.
			if (localPlayer is LocalConsolePlayer)
			{
				((LocalConsolePlayer)localPlayer).GameQuitRequested = () => game.Quit = true;
			}
			if (opponentPlayer is LocalConsolePlayer)
			{
				((LocalConsolePlayer)opponentPlayer).GameQuitRequested = () => game.Quit = true;
			}

			var pers = ServiceContainer.Resolve<IPersistenceService> ();
			bool success = await pers.PersistGameStateAsync (game.GameState);
			loggingService.Log ("Persisting game state succeeded: {0}", success);

			await game.StartGameLoop (new ConsoleProgress());

			return game;
		}
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PyramidApp_Console.LocalConsolePlayer"/> class.
 /// </summary>
 public LocalConsolePlayer(ConsoleVisualizationService visualizationService)
 {
     this.visualizationService = visualizationService;
     this.Name = "Console Player";
 }