void Awake() { if (Instance != null && Instance != this) { Destroy(Instance); } else { Instance = this; } chessGame = GameModeFactory.Create((GameMode)modeIndex); chessGame.PopulateBoard(); }
/// <summary> /// Changes game mode to the specified one. /// </summary> /// <param name="command">The Mode command.</param> private void ChangeGameMode(Command command) { var modeNameArgument = command.GetArgument <string>(0); var modeNameParseResult = Enum.TryParse(modeNameArgument, true, out GameModeType modeType); if (!modeNameParseResult) { _consoleManager.WriteLine($"$rInvalid mode type ($R{modeNameArgument}$r)"); return; } _commandsManager.RemoveCommandHandlers(CommandGroup.GameMode); _mode = _modeFactory.Create(modeType); _mode.LoadContent(Content); }
/// <summary> /// Initializes a new instance of the <see cref="GUICore"/> class. /// </summary> /// <param name="consoleManager">The console manager instance.</param> /// <param name="commandsManager">The commands manager instance.</param> public GUICore(ConsoleManager consoleManager, CommandsManager commandsManager) { _consoleManager = consoleManager; _commandsManager = commandsManager; _graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = (int)Constants.WindowSize.X, PreferredBackBufferHeight = (int)Constants.WindowSize.Y }; _modeFactory = new GameModeFactory(_consoleManager, _commandsManager); _mode = _modeFactory.Create(GameModeType.Editor); _inputManager = new InputManager(); Content.RootDirectory = "Content"; IsMouseVisible = true; SetCommandHandlers(); }
public void Awake() { ApplicationModels.RegisterModel <BattleModel>(new BattleModel()); var gameModel = ApplicationModels.GetModel <GameModel>(); var mode = gameModel.SelectedMode; _gameMode = GameModeFactory.Create(mode); _view = Instantiate(ScriptableObjectsDatabase.GameViews[mode]); _view.Initialize(); for (int i = 0; i < NB_COLUMNS; ++i) { for (int j = 0; j < NB_ROWS; ++j) { _tiles[i, j] = new Tile(i, j); } } var playerModels = gameModel.Players; int playersCount = playerModels.Count; UpdateTilesWithContent <Wall>(_terrain, null); var nbSpawns = Math.Min(_spawnPointPositions.Length, playersCount); _spawnPoints = new SpawnPoint[nbSpawns]; for (int i = 0; i < nbSpawns; ++i) { var tile = GetTile(_spawnPointPositions[i].position); _spawnPoints[i].Tile = tile; _spawnPoints[i].Position = GetTileCenter(tile); // Flag all nearby tiles as SpawnArea to avoid spawning blocks on them var coords = tile.Coords; for (int offsetX = -1; offsetX <= 1; ++offsetX) { for (int offsetY = -1; offsetY <= 1; ++offsetY) { var x = coords.x + offsetX; var y = coords.y + offsetY; if (x >= 0 && x < NB_COLUMNS && y >= 0 && y < NB_ROWS) { var areaTile = _tiles[x, y]; if (!areaTile.IsWall) { areaTile.Content.Add(SpawnArea.Instance); } } } } } _players = new List <PlayerController>(playerModels.Count); for (int i = 0; i < playersCount; ++i) { var model = playerModels[i]; var controller = Instantiate(ScriptableObjectsDatabase.PlayerSettings.PlayerPrefab, _groundMesh.transform); controller.Initialize(model); var playerView = controller.GetComponent <PlayerView>(); playerView.Initialize(model.Color); _players.Add(controller); } ResetBoard(); GameFacade.SpawnPlayer.Connect(SpawnPlayer); GameFacade.PlayerMoved.Connect(OnPlayerMoved); GameFacade.BombExploded.Connect(OnBombExploded); GameFacade.BombInputPressed.Connect(OnBombInputPressed); GameFacade.BattleEnd.Connect(OnBattleEnd); GameFacade.AllPlayersReadyForNextGame.Connect(OnLeave); }