public Hero(Texture2D texture, IInputReader reader) { heroTexture = texture; walkRight = new WalkRightAnimation(texture, this); walkLeft = new WalkLeftAnimation(texture, this); currentAnimation = walkRight; //animatie = new Animatie(); //animatie.AddFrame(new AnimationFrame(new Rectangle(0, 0, 280, 385))); //animatie.AddFrame(new AnimationFrame(new Rectangle(280, 0, 280, 385))); //animatie.AddFrame(new AnimationFrame(new Rectangle(560, 0, 280, 385))); //animatie.AddFrame(new AnimationFrame(new Rectangle(840, 0, 280, 385))); //animatie.AddFrame(new AnimationFrame(new Rectangle(1120, 0, 280, 385))); //Read input for my hero class this.inputReader = reader; mouseReader = new MouseReader(); moveCommand = new MoveCommand(); moveToCommand = new MoveToCommando(); Position = new Vector2(0, 0); _collisionRectangle = new Rectangle((int)Position.X, (int)Position.Y, 280, 385); }
public void SendCommand(IGameCommand command) { _turnGame.SendCommand(new List <IGameCommand>() { command }); }
/// <summary> /// Registers all classes which implement the <see cref="IGameCommand"/> interface. (Searches all assemblies for types, instanciates them and registers them) /// </summary> private void SearchAndRegisterCommands() { Log("Searching for commands..."); IEnumerable <Type> commandTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(asm => asm.GetTypes()) .Where(p => p.GetInterfaces() .Contains(typeof(IGameCommand))); int registeredCommands = 0; foreach (Type cmdType in commandTypes) { if (cmdType.IsClass) { IGameCommand cmd = (IGameCommand)Activator.CreateInstance(cmdType); if (cmd.UIDString == null) { continue; } if (!CommandRegistry.ContainsKey(cmd.UIDString)) { CommandRegistry.Add(cmd.UIDString, cmd); registeredCommands++; } } } Log("Registered " + registeredCommands + " commands."); }
public Hero(List <Texture2D> textures, CollisionDetection objects) { //basic information of entity Position = new Vector2(400, 400); VerticalMovement = new Vector2(0, 0); // X: verticalmovement => 1 = ja 0= nee Y: current jump speed HorizontalMovement = new Vector2(0, 4); // X: richting -1 => links 0=> stil 1=> rechts Y: Current movespeed status = CharState.idle; richting = LoopRichting.rechts; herotexture = textures; //combat this.Attackbox = new Rectangle(0, 0, 60, 60); Attacklock = false; Health = 150; Damage = 80; //animations AnimationCreator creator = new AnimationCreator(); animations = creator.GetHeroAnimation(); //movement and input this.inputreader = new KeyboardReader(this); this.movecommand = new MoveCommand(objects); CollisionRectangle = new Rectangle((int)Position.X, (int)Position.Y, Hero.Width, Hero.height); }
/// <summary> /// Entry point for all commands execution. /// </summary> /// <param name="current"> Current session.</param> /// <param name="sessions">Collection of all sessions.</param> /// <param name="message">Message sent by chat cient.</param> internal static void HandleGameMessage(JigsawGameService current, GameSessions sessions, string message) { string command = string.Empty; string commandArgs = string.Empty; var index = message.IndexOf(":", StringComparison.OrdinalIgnoreCase); if (index > 0) { command = message.Substring(0, index); commandArgs = message.Substring(index + 1, message.Length - index - 1); } else { command = message; } Logger.LogMessage(command); Logger.LogMessage(commandArgs); IGameCommand handler = null; if (commands.TryGetValue(command, out handler)) { handler.Execute(current, sessions, commandArgs); } }
public PlayerLogicComponent(IGameCommand fireCommand, IConsoleWriter consoleWriter, IGeometryMathService geometryMathService) { _fireCommand = fireCommand; _consoleWriter = consoleWriter; _geometryMathService = geometryMathService; }
private void RemoveCommand(IGameCommand gameCommand) { var index = _commands.IndexOfValue(gameCommand); _commands.RemoveAt(index); gameCommand.Dispose(); }
private void RemoveLateCommand(IGameCommand gameCommand) { var index = _lateTickCommands.IndexOf(gameCommand); _commands.RemoveAt(index); gameCommand.Dispose(); }
public Enemy(Texture2D Texture, Vector2 position) // Iinputreader => hoe input uitlezen? { Position = position; //read input for hero class EnemyTexture = Texture; animatie = new Animatie(); move = new MoveCommand(); movecommand = new MoveCommand(); animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 2, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 3, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 4, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 5, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 6, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 7, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width / 9 * 8, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend animatie.AddFrame(new AnimationFrame(new Rectangle(Texture.Width, Texture.Height, Texture.Width / 9, Texture.Height))); // frame lopend collisionrectangle = new Rectangle((int)Position.X, (int)Position.Y, 68, 85); Moving(); }
public void Handle(IGameCommand command) { var board = boardManager.FindByConnectionId(command.ConnectionId); if (board == null) { broadcastService.Broadcast(command.ConnectionId, "No active games!"); return; } var shootCommand = command as ShootCommand; var player = board.FindPlayer(command.ConnectionId); var hitObject = board.ObjectAt(shootCommand.X, shootCommand.Y); if (hitObject == null) { broadcastService.Broadcast(command.ConnectionId, $"BOOM {player.Name} {player.Score}"); return; } board.RemoveGameObject(hitObject); if (board.GameObjects.Count < 1) { broadcastService.Broadcast(board, $"Oh no, they are respawning. Now there will be 2 zombies!"); boardActions.ScheduleNewZombie(board); boardActions.ScheduleNewZombie(board, 1000.Random(5000)); } player.Score += 1; broadcastService.Broadcast(board, $"BOOM {player.Name} {player.Score} {hitObject.Name}"); }
public void Handle(IGameCommand command) { var startGameCommand = command as StartGameCommand; var alreadyPlayingOnBoard = boardManager.FindByConnectionId(startGameCommand.ConnectionId); if (alreadyPlayingOnBoard != null) { broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {alreadyPlayingOnBoard.Name}"); return; } var board = boardManager.Find(startGameCommand.BoardName); if (board == null) { board = StartNewBoard(startGameCommand.BoardName); } if (board.IsAlreadyJoined(startGameCommand.ConnectionId)) { broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {board.Name}"); return; } board.Join(new Player(startGameCommand.PlayerName, startGameCommand.ConnectionId)); broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} joined board {board.Name}"); }
public static IGameCommand StringToCommand(string msg) { SerializableClass ctype = JsonUtility.FromJson <SerializableClass>(msg); Type t = Type.GetType(ctype.GetClassName()); IGameCommand gc = (IGameCommand)JsonUtility.FromJson(msg, t); return(gc); }
public Game() { _player = new PlayerCharacter(PLAYER_ID_UNKNOWN, 10, 10, "unknown", 1, 0, 0); _player.CurrentLocation = World.LocationByID(World.LOCATION_ID_HOME); _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1)); _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_HEALING_POTION), 2)); _prompt = new Prompt(); }
private void UpdateForCommand() { if (EventSystem.current.IsPointerOverGameObject()) { return; } CharacterModel caster = Player.Selection.Model; if (Input.GetMouseButtonUp(autoCurrentAbility ? InputExtensions.RightClick : InputExtensions.LeftClick)) { IGameCommand command = null; if (currentAbility == null) { command = new MoveCommand() { Character = caster, CharacterId = caster.Id, Path = currentPath ?? new List <Data.Vector2>(), }; } else { Data.Vector2 targetPosition = abilityCastView.TargetPosition.ToModelVector(); if (caster.ActionPoints < currentAbility.ActionPoints) { UserInterface.GameMessageView.AddMessage("Not enough action points"); } else if ((caster.Position - targetPosition).Norm > currentAbility.Range) { UserInterface.GameMessageView.AddMessage("Not in range"); } else { command = new CastAbilityCommand() { Character = caster, CharacterId = caster.Id, Ability = currentAbility, AbilityName = currentAbility.Name, Target = targetPosition, }; } } if (command != null) { Game.Model.ExecuteCommand(command); } ClearCurrentCommand(); } if (Input.GetMouseButtonUp(autoCurrentAbility ? InputExtensions.LeftClick : InputExtensions.RightClick)) { ClearCurrentCommand(); } }
protected override void OnUpdate() { base.OnUpdate(); if (DouDiZhuGameCtrl.Instance.CommandQueue.Count > 0) { IGameCommand command = DouDiZhuGameCtrl.Instance.CommandQueue.Dequeue(); command.Execute(); } }
public PlayerBuilder(IConsoleWriter consoleWriter, IGeometryMathService geometryMathService, IGameCommand fireCommand, PlayerData playerData) { _consoleWriter = consoleWriter; _geometryMathService = geometryMathService; _fireCommand = fireCommand; _playerData = playerData; }
private T CreateHandler <T>(IGameCommand response, string methodName) where T : class { Delegate action = Delegate.CreateDelegate(typeof(T), response, methodName); if (null != action) { return(action as T); } return(null); }
public void Handle(IGameCommand command) { Print(command, "Server commands:"); Print(command, " START <player_name> <board_name> - join or create a new game"); Print(command, " SHOOT <x> <y> - shoot a monster"); Print(command, " STATS - prints information about players and their scores"); Print(command, " QUIT - quit current game. You can join another one usin START"); Print(command, " CHAT <msg> - send a message to players in current game"); Print(command, " HELP - print this message"); }
/// <summary> /// Executes Command on local copy of GameState. Use it from DataHandler when JSON command arrives from server. /// </summary> /// <param name="cmd">Command to be executed</param> public void UpdateState(IGameCommand cmd) { if (cmd == null) { return; } cmd.Execute(gameState); stateUpdated?.Invoke(gameState); }
private void RunCommand(IGameCommand gameCommand) { var status = gameCommand.FixedStep(); if (status == GameCommandStatus.InProgress) { return; //if it is no longer in progress remove it } RemoveCommand(gameCommand); }
// Command executor methods public async Task ExecuteCommand(IGameCommand executableCommand) { try { switch (executableCommand.CommandType) { case GameCommandType.Register: var regResult = await this.ExecuteRegisterCommand(executableCommand as RegisterCommand); this.ConsoleOperator.Write(regResult); break; case GameCommandType.Login: var loginResult = await this.ExecuteLoginCommand(executableCommand as LoginCommand); this.ConsoleOperator.Write(loginResult); break; case GameCommandType.CreateGame: this.Requester.Authenticate(); var createdGameResult = await this.ExecuteCreateGameCommand(); this.ConsoleOperator.Write(SuccessfullGameCreationMessage + createdGameResult); break; case GameCommandType.AvailableGames: this.Requester.Authenticate(); var availableGamesResult = await this.ExecuteAvailableGamesCommand(); this.ConsoleOperator.Write(this.BuildAvailableGamesResponse(availableGamesResult)); break; case GameCommandType.JoinGame: this.Requester.Authenticate(); var joinGameResult = await this.ExecuteJoinGameCommand(executableCommand as JoinGameCommand); this.ConsoleOperator.Write(this.BuildGameField(joinGameResult)); break; case GameCommandType.Play: this.Requester.Authenticate(); var turnResult = await this.ExecutePlayCommand(executableCommand as PlayCommand); this.ConsoleOperator.Write(SuccessfullTurnPlayMessage); this.ConsoleOperator.Write(this.BuildGameField(turnResult.Field)); this.ConsoleOperator.Write(string.Format(PlayersTurnPlayMessage, turnResult.NextPlayerUsername)); break; } } catch (InvalidOperationException invalidOperationException) { this.ConsoleOperator.WriteError(invalidOperationException.Message); } catch (ApiException apiException) { foreach (var error in apiException.Errors) { this.ConsoleOperator.WriteError(error); } } }
private void SendResponseToTwitchChat(IGameCommand obj) { if (string.IsNullOrEmpty(obj.Destination)) { this.messageBus.Send(MessageBus.Broadcast, obj.Args.LastOrDefault()); } else { this.messageBus.Send(MessageBus.Message, obj.Destination + ", " + obj.Args.LastOrDefault()); } }
public EnemyBuilder(IConsoleWriter consoleWriter, IGameObjectLocator gameObjectLocator, IGeometryMathService geometryMathService, IGameCommand fireCommand, EnemyData enemyData) { _consoleWriter = consoleWriter; _gameObjectLocator = gameObjectLocator; _geometryMathService = geometryMathService; _fireCommand = fireCommand; _enemyData = enemyData; }
public Player(Texture2D text, IInputReader reader) { postieLevel = new PlayerPosition(); frames = new FramesPlayer(); playerTexture = text; animatie = new AnimatiePlayer(frames); Position = postieLevel.Postions[GameState.level]; this.inputReader = reader; moveCommand = new MoveCommand(); _collisionRectangle = new Rectangle((int)Position.X, (int)Position.Y, 80, 120); }
public void Update(GameTime gameTime, Rectangle hero, int x, IGameCommand moveCommand) { if (trans.positie.X < 0) { trans.positie = new Vector2(0, hero.Y); } if (trans.positie.X > x - hero.Width) { trans.positie = new Vector2(x - hero.Width, hero.Y); } foreach (Rectangle blok in detectedblokken) { if (VanBoven(hero, blok)) { moveCommand.snelheid = Vector2.Zero; moveCommand.spring = false; } // hero mag nooit onder de grond gaan // if (trans.positie.Y > 1595) { trans.positie = new Vector2(trans.positie.X, 1595); } if (!VanBoven(hero, blok) && trans.positie.Y < 1595 && input.LeesInput().X == 1 && !CheckCollision(hero, blok) || !VanBoven(hero, blok) && trans.positie.Y < 1595 && input.LeesInput().X == -1 && !CheckCollision(hero, blok)) { moveCommand.spring = true; } if (VanLinks(hero, blok) && input.LeesInput().X == 1) { if (input.LeesInput().X == -1) { break; } trans.positie = new Vector2(blok.X - hero.Width - 2, hero.Y); } if (VanRechts(hero, blok) && input.LeesInput().X == -1) { if (input.LeesInput().X == 1) { break; } trans.positie = new Vector2(blok.X + blok.Width + 2, hero.Y); } // ervoor zorgen dat die niet door de blok kan van onder // if (VanOnder(hero, blok)) { moveCommand.snelheid += new Vector2(0, +0.15f); } } }
public void ExecuteCommand(IGameCommand command) { if (isRunning == false) { return; } if (command.TryExecute(this)) { ReplayData.CommandHistory.Add(command); } }
public Hero(Texture2D texture, IInputReader inputReader, IGameCommand mvCommand) { this.heroTexture = texture; currentAnimation = walkDown; //Read input for hero class this.reader = inputReader; this.moveCommand = mvCommand; _collisionRectangle = new Rectangle((int)Position.X, (int)Position.Y, 62, 110); Position = new Vector2(0, 800); }
public async Task SendAsync(IGameCommand command) { var commandString = new DiceCommandString(command.Command); var packetSequenceId = await DiceConnection.GetNextSequenceIdAsync(); var commandStringWords = commandString.ToWords(); var packet = new DicePacket(new DicePacketSequence(packetSequenceId, PacketType.Request, PacketOrigin.Client), commandStringWords); await this.DiceConnection.SendAsync(packet); var eventArgs = new GameDataEventArgs(new GameData() { DataString = packet.ToString() }); this.OnGameDataSent(eventArgs); }
/// <summary> /// Executes a Command and broadcasts it to all clients. /// </summary> /// <param name="cmd">Command to be executed and broadcasted</param> public void Execute(IGameCommand cmd) { if (cmd == null) { return; } cmd.Execute(gameState); this.server.SendToAll(cmd); stateUpdated?.Invoke(gameState); }
public EnemyLogicNormalState(IGameObjectLocator gameObjectLocator, IGameCommand fireCommand, IGeometryMathService geometryMathService, EnemyData enemyData) { _gameObjectLocator = gameObjectLocator; _fireCommand = fireCommand; _geometryMathService = geometryMathService; _enemyData = enemyData; _updatesForReload = enemyData.UpdatesForReload; _currentUpdatesForReload = 0; }
public void Redo() { if (_redoStack.Count > 0) { IGameCommand cmd = (IGameCommand)_redoStack.Pop(); cmd.Redo(); _undoStack.Push(cmd); OnPropertyChanged("UndoStackCount"); OnPropertyChanged("RedoStackCount"); } }
public EnemyLogicComponent(IGameObjectLocator gameObjectLocator, IGameCommand fireCommand, IGeometryMathService geometryMathService, EnemyData enemyData) { _enemyState = new EnemyLogicNormalState(gameObjectLocator, fireCommand, geometryMathService, enemyData); _gameObjectLocator = gameObjectLocator; _fireCommand = fireCommand; _geometryMathService = geometryMathService; _enemyData = enemyData; }
public void ExecuteCommand(IGameCommand cmd) { cmd.Execute(); _undoStack.Push(cmd); OnPropertyChanged("UndoStackCount"); if (_redoStack.Count > 0) { _redoStack.Clear(); OnPropertyChanged("RedoStackCount"); } }
public void LoadGameCommand(IGameCommand gameCommand) { m_GameCommand = gameCommand; }
public void SendCommand(IGameCommand command) { _turnGame.SendCommand(new List<IGameCommand>() { command }); }