private void btn_Play_Click(object sender, EventArgs e) { if (handler != null) { handler.End(); SetBtnToPlay(); return; } btn_Play.Text = "S T O P"; handler = gameManager.MakeHandler(currentGame); handler.Initialize(currentGameInfo, currentProfile); handler.Ended += handler_Ended; if (gameManager.Play(handler)) { if (handler.TimerInterval > 0) { handlerThread = new Thread(UpdateGameManager); handlerThread.Start(); } } else { handler = null; } this.WindowState = FormWindowState.Minimized; }
private void HandleReceive(string value) { var message = ParseMessage(value); switch (message["type"]) { case "prepare-new-game": gameHandler = GetHandler(message["game"]); gameHandler.PrepareNewGame(message); connection.Send("ready"); return; case "update-game-state": gameHandler.UpdateGameState(message); connection.Send("ready"); break; case "make-move": var newState = gameHandler.MakeMove(message); connection.Send("move " + newState.LastMoveDescription()); break; case "announce-results": // this will be logged automatically, clean up resources gameHandler = null; break; default: throw new Exception("Unknown message type received."); } }
/// <summary> /// Start tracking gamelogs with custom impelementaion of GameEventHandler /// </summary> /// <param name="gh"> Custom Game handler implementation </param> public void Start(IGameHandler gh) { _first = true; _doUpdate = true; _gameHandler = gh; ReadFileAsync(); }
/// <summary> /// Start tracking gamelogs with default impelementaion of GameEventHandler /// </summary> public void Start() { _first = true; _doUpdate = true; _gameHandler = new GameEventHandler(); ReadFileAsync(); }
public void Play(IGameHandler handler) { // Start the Play method in another thread, so the // handler can update while it's still loading error = null; ThreadPool.QueueUserWorkItem(play, handler); }
private void btn_Play_Click(object sender, EventArgs e) { if (btn_Play.Text == "S T O P") { if (handler.FakeFocus != null) { handler.FakeFocus.Abort(); } if (handler != null) { Log("Stop button clicked, calling Handler End function"); handler.End(); } SetBtnToPlay(); btn_Play.Enabled = false; this.Controls.Clear(); this.InitializeComponent(); RefreshGames(); return; } btn_Play.Text = "S T O P"; btnBack.Enabled = false; handler = gameManager.MakeHandler(currentGame); handler.Initialize(currentGameInfo, GameProfile.CleanClone(currentProfile)); handler.Ended += handler_Ended; gameManager.Play(handler); if (handler.TimerInterval > 0) { handlerThread = new Thread(UpdateGameManager); handlerThread.Start(); } if (currentGame.HideTaskbar) { User32Util.HideTaskbar(); } if (currentGame.HideDesktop) { foreach (Screen screen in Screen.AllScreens) { System.Windows.Forms.Form hform = new System.Windows.Forms.Form(); hform.BackColor = Color.Black; hform.Location = new Point(0, 0); hform.Size = screen.WorkingArea.Size; this.Size = screen.WorkingArea.Size; hform.FormBorderStyle = FormBorderStyle.None; hform.StartPosition = FormStartPosition.Manual; //hform.TopMost = true; hform.Show(); } } WindowState = FormWindowState.Minimized; }
public void SetUp() { _game = MockRepository.GenerateMock <IGame>(); _gameHandler = MockRepository.GenerateMock <IGameHandler>(); _gameState = MockRepository.GenerateMock <IHsGameState>(); _gameState.Stub(x => x.GameHandler).Return(_gameHandler); _assetHandler = new AssetHandler(); }
public void SetUp() { _game = MockRepository.GenerateMock<IGame>(); _gameHandler = MockRepository.GenerateMock<IGameHandler>(); _gameState = MockRepository.GenerateMock<IHsGameState>(); _gameState.Stub(x => x.GameHandler).Return(_gameHandler); _arenaHandler = new ArenaHandler(); }
private void EndPlay() { // Ends the game handler.End(); handler = null; gameManager.End(); button_Play.Text = " PLAY"; }
/// <summary> /// Closes the handler and the gameManager, so we can properly dispose of streams and everything else /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GamesViewer_FormClosed(object sender, FormClosedEventArgs e) { if (handler != null) { handler.End(); this.handler = null; } gameManager.End(); }
public void Start(IGameHandler gh, GameV2 game) { _gameState.AddToTurn = -1; _gameState.First = true; _gameState.DoUpdate = true; _gameState.GameHandler = gh; _gameState.GameEnded = false; ReadFileAsync(); }
/// <summary> /// Start tracking gamelogs with custom impelementaion of GameEventHandler /// </summary> /// <param name="gh"> Custom Game handler implementation </param> public void Start(IGameHandler gh) { _addToTurn = -1; _first = true; _doUpdate = true; _gameHandler = gh; _gameEnded = false; ReadFileAsync(); }
public void Play(IGameHandler handler) { //if (handler.HideTaskBar) //{ // User32.HideTaskbar(); //} handler.Play(); }
private void tsbGameSelect_SelectedIndexChanged(object sender, EventArgs e) { ToolStripItem tsi = (ToolStripItem)sender; _gameHandler = tsi.Tag as IGameHandler; tsbGameSelect.Text = tsi.Text; tsbGameSelect.Image = tsi.Image; }
/// <summary> /// Start tracking gamelogs with default impelementaion of GameEventHandler /// </summary> public void Start() { _addToTurn = -1; _first = true; _doUpdate = true; _gameEnded = false; _gameHandler = new GameEventHandler(); ReadFileAsync(); }
public void Destroy() { if (_handler != null) { _handler.Destroy(); } _handler = null; gameData = null; }
private bool CheckMovePermissibility(int i, int j, IGameHandler handler) { if (!_cells.IsCellEmpty(i, j)) { handler.BroadcastMessage(true, "You can't draw in non-empty cell"); return(false); } return(true); }
private void handler_Ended() { handler = null; if (handlerThread != null) { handlerThread.Abort(); handlerThread = null; } Invoke(new Action(SetBtnToPlay)); }
public Lobby( IGameHandler gameHandler, IRegistrationHandler registrationHandler, IUserHandler userHandler, IMappingHandler mappingHandler, IScenarioHandler scenarioHandler ) { this.gameHandler = gameHandler; this.registrationHandler = registrationHandler; this.userHandler = userHandler; this.mappingHandler = mappingHandler; this.scenarioHandler = scenarioHandler; }
public void Play(IGameHandler handler) { //if (handler.HideTaskBar) //{ // User32.HideTaskbar(); //} // Start the Play method in another thread, so the // handler can update while it's still loading handler.Play(); //ThreadPool.QueueUserWorkItem(play, handler); }
public Lobby(IGameHandler gameHandler, IRegistrationHandler registrationHandler, IUserHandler userHandler, IMappingHandler mappingHandler, IScenarioHandler scenarioHandler) { this.gameHandler = gameHandler; this.registrationHandler = registrationHandler; this.userHandler = userHandler; this.mappingHandler = mappingHandler; this.scenarioHandler = scenarioHandler; }
public void Init (IGameHandler gameHandler) { InitStateMachine (); this.gameHandler = gameHandler; if (this.gameHandler != null) { this.gameHandler.RaiseChangeState += OnGameHandlerChangeState; } DeathTrigger.RaiseDeath += ResetOnDeath; this.spriteRenderer = GetComponentInChildren<SpriteRenderer>(); this.spriteRenderer.enabled = false; this.catInventory = new CatInventory (); }
private void setGameHandler(IGameHandler handler) { if (handler == null) throw new ArgumentNullException("handler"); if (this.gameHandler != null) this.gameHandler.Stopped -= this.setGameHandler; this.gameHandler = handler; this.gameDrawer = handler as IGameDrawer; this.gameHandler.Stopped += this.setGameHandler; }
// UI Toolbars private void tsbGameSelect_SelectedIndexChanged(object sender, EventArgs e) { ToolStripItem tsi = (ToolStripItem)sender; _gameHandler = (IGameHandler)tsi.Tag; tsbGameSelect.Text = tsi.Text; tsbGameSelect.Image = tsi.Image; UpdateTextView(); UpdatePreview(); UpdateForm(); Settings.Default.SelectedGameHandler = tsi.Text; Settings.Default.Save(); }
/// <summary> /// Handle the update /// </summary> /// <param name="update">Update to be handled</param> /// <returns></returns> public async Task HandleUpdateAsync(Update update) { if (update.Message != null) { logger?.LogInformation("Incoming update: {0}", $"chatId: {update.Message?.Chat?.Id} // message: {update.Message?.Text}"); } bool anyHandlerExists = false; try { var handlers = _updateParser.FindHandlersForUpdate(_bot, update); foreach (IUpdateHandler handler in handlers) { anyHandlerExists = true; if (handler is IGameHandler) { IGameHandler gameHandler = handler as IGameHandler; var options = BotGameOptions .Single(g => g.ShortName == gameHandler.ShortName); options.Url = ReplaceGameUrlTokens(options.Url, options.ShortName); options.ScoresUrl = ReplaceGameUrlTokens(options.ScoresUrl, options.ShortName); gameHandler.Options = options; } var result = await handler.HandleUpdateAsync(_bot, update); if (result == UpdateHandlingResult.Handled) { return; } } if (!anyHandlerExists) { await _bot.HandleUnknownUpdate(update); } } catch (Exception e) { await _bot.HandleFaultedUpdate(update, e); } }
public void CreateGameHandler() { EventManager._init.Game.Invoke_InitAll(); switch (gameData.GameType) { case GameTypeEnum.MultyReplay: _handler = new ReplayHandler(); break; case GameTypeEnum.MultyJoin: _handler = new ReplayHandler(); break; case GameTypeEnum.MultyNew: _handler = new RecordHandler(); break; case GameTypeEnum.MultyNewFB: _handler = new RecordHandler(); break; case GameTypeEnum.MultyRecord: _handler = new RecordHandler(); break; case GameTypeEnum.SingleNew: _handler = new SingleRecordHandler(); break; case GameTypeEnum.TutorialGame: _handler = new TutorialHandler(); break; default: _handler = null; #region DEBUG #if UNITY_EDITOR Debug.Log("[ERROR] wrong GameTypeEnum = " + gameData.GameType + " !"); #endif #endregion break; } _handler.Init(gameData); }
static void Main(string[] args) { GameManager manager = new GameManager(); IGameInfo borderlands2 = manager.Games["720CE71B-FCBF-46C8-AC9D-C4B2BF3169E3"]; UserGameInfo borderInfo = manager.AddGame(borderlands2, @"C:\Program Files (x86)\Steam\steamapps\common\Borderlands 2\Binaries\Win32\Borderlands2.exe"); GameProfile profile = new GameProfile(); profile.InitializeDefault(borderlands2); PlayerInfo p1 = new PlayerInfo(); p1.MonitorBounds = new Rectangle(0, 0, 960, 540); p1.ScreenIndex = 0; profile.PlayerData.Add(p1); PlayerInfo p2 = new PlayerInfo(); p2.MonitorBounds = new Rectangle(0, 540, 960, 540); p2.ScreenIndex = 0; profile.PlayerData.Add(p2); borderInfo.Profiles.Add(profile); manager.WaitSave(); // try to play game with custom profile handler = manager.MakeHandler(borderlands2); handler.Initialize(borderInfo, profile); ThreadPool.QueueUserWorkItem(Play); //handler.Play(); for (; ;) { Thread.Sleep(16); handler.Update(16); if (handler.HasEnded) { break; } } }
private void setGameHandler(IGameHandler handler) { if (handler == null) { throw new ArgumentNullException("handler"); } if (this.gameHandler != null) { this.gameHandler.Stopped -= this.setGameHandler; } this.gameHandler = handler; this.gameDrawer = handler as IGameDrawer; this.gameHandler.Stopped += this.setGameHandler; }
public void OnClick(int x, int y, string playerId, IGameHandler handler) { if (_players.Count < 2) { handler.BroadcastMessage(true, "Please, wait for the second player before starting the game"); return; } var i = x / CellSize + _players[0].ViewportLeft; var j = y / CellSize + _players[0].ViewportTop; UpdateCell(i, j, playerId, handler); if (IsWinMove(i, j)) { handler.BroadcastMessage(false, "The " + (_isFirstPlayerTurn ? "Second" : "First") + " player won!"); } }
/// <summary> /// Handle the update /// </summary> /// <param name="update">Update to be handled</param> /// <returns></returns> public async Task HandleUpdateAsync(Update update) { bool anyHandlerExists = false; try { var handlers = _updateParser.FindHandlersForUpdate(_bot, update); foreach (IUpdateHandler handler in handlers) { anyHandlerExists = true; if (handler is IGameHandler) { IGameHandler gameHandler = handler as IGameHandler; var options = BotGameOptions .Single(g => g.ShortName == gameHandler.ShortName); options.Url = ReplaceGameUrlTokens(options.Url, options.ShortName); options.ScoresUrl = ReplaceGameUrlTokens(options.ScoresUrl, options.ShortName); gameHandler.Options = options; } var result = await handler.HandleUpdateAsync(_bot, update); if (result == UpdateHandlingResult.Handled) { return; } } if (!anyHandlerExists) { await _bot.HandleUnknownUpdate(update); } } catch (Exception e) { await _bot.HandleFaultedUpdate(update, e); } }
private void btn_Play_Click(object sender, EventArgs e) { if (handler != null) { return; } handler = gameManager.MakeHandler(currentGame); handler.Initialize(currentGameInfo, currentProfile); handler.Ended += handler_Ended; if (handler.TimerInterval > 0) { Thread t = new Thread(UpdateGameManager); t.Start(); } gameManager.Play(handler); }
public bool Play(IGameHandler handler) { //if (handler.HideTaskBar) //{ // User32.HideTaskbar(); //} // Start the Play method in another thread, so the // handler can update while it's still loading string play = handler.Play(); if (!string.IsNullOrEmpty(play)) { MessageBox.Show(play, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); //ThreadPool.QueueUserWorkItem(play, handler); }
private void button_Play_Click(object sender, EventArgs e) { if (handler == null) { if (this.info == null) { return; } string starter = this.info.ExecutablePath; Type t = gameInfo.HandlerType; handler = (IGameHandler)Activator.CreateInstance(t); Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle); int titleHeight = screenRectangle.Top - this.Top; bool worked = handler.Initialize(starter, this.monitorControl1.Players, gameInfo.Options, addSteps, titleHeight); if (worked) { string error = handler.Play(); if (string.IsNullOrEmpty(error)) { button_Play.Text = " STOP"; gameManager.Play(handler); } else { handler = null; MessageBox.Show(error); } } else { handler = null; } } else { EndPlay(); } }
static void Main(string[] args) { GameManager manager = new GameManager(); GameInfo borderlands2 = manager.Games["720CE71B-FCBF-46C8-AC9D-C4B2BF3169E3"]; UserGameInfo borderInfo = manager.AddGame(borderlands2, @"C:\Program Files (x86)\Steam\steamapps\common\Borderlands 2\Binaries\Win32\Borderlands2.exe"); GameProfile profile = new GameProfile(); profile.InitializeDefault(borderlands2); PlayerInfo p1 = new PlayerInfo(); p1.monitorBounds = new Rectangle(0, 0, 960, 540); p1.screenIndex = 0; profile.PlayerData.Add(p1); PlayerInfo p2 = new PlayerInfo(); p2.monitorBounds = new Rectangle(0, 540, 960, 540); p2.screenIndex = 0; profile.PlayerData.Add(p2); borderInfo.Profiles.Add(profile); manager.WaitSave(); // try to play game with custom profile handler = manager.MakeHandler(borderlands2); handler.Initialize(borderInfo, profile); ThreadPool.QueueUserWorkItem(Play); //handler.Play(); for (; ; ) { Thread.Sleep(16); handler.Update(16); if (handler.HasEnded) { break; } } }
private void UpdateCell(int i, int j, string playerId, IGameHandler handler) { if (_isFirstPlayerTurn && _players[0].PlayerId == playerId && CheckMovePermissibility(i, j, handler)) { _cells[i, j] = CellType.Zero; handler.DrawZero(i - _players[0].ViewportLeft, j - _players[0].ViewportTop); _isFirstPlayerTurn = false; } else if (!_isFirstPlayerTurn && _players[1].PlayerId == playerId && CheckMovePermissibility(i, j, handler)) { _cells[i, j] = CellType.X; handler.DrawX(i - _players[0].ViewportLeft, j - _players[0].ViewportTop); _isFirstPlayerTurn = true; } else { handler.BroadcastMessage(true, "Please, wait... it's not your turn"); } }
private void Redraw(IGameHandler handler) { handler.Clear(); foreach (var cell in _cells.AsEnumerable()) { int i = cell.Key.Item1 - _players[0].ViewportLeft; int j = cell.Key.Item2 - _players[0].ViewportTop; if (0 > i || i >= CellsCount || 0 > j || j >= CellsCount) { continue; } if (cell.Value == CellType.X) { handler.DrawX(i, j); } else { handler.DrawZero(i, j); } } }
/// <summary> /// Subscribes and adds the handler to the gameloop. /// </summary> /// <param name="handler">The handler.</param> public void Subscribe(IGameHandler handler) { Logger.Log("Subscribed {0} to the game loop", handler.GetType().Name); _handlers.Add(handler); }
private void handler_Ended() { handler = null; }
/// <summary> /// Unsubscribes the gameloop and removes the handler. /// </summary> /// <param name="handler">The handler.</param> public void Unsubscribe(IGameHandler handler) { Logger.Log("Removed {0} from game loop", handler.GetType().Name); _handlers.Remove(handler); }
/// <summary> /// Start tracking gamelogs with default impelementaion of GameEventHandler /// </summary> public void Start() { _addToTurn = -1; _first = true; _doUpdate = true; _gameEnded = false; _gameHandler = new GameEventHandler(); _gameHandler.ResetConstructedImporting(); _lastGameStart = DateTime.Now; ReadFileAsync(); }
public void Start(IGameHandler gh, GameV2 game) { throw new NotImplementedException(); }