public NewGameViewModel() { Players = new ReactiveList <string>(); var canStart = this.Players.CountChanged.Select(count => count >= 3); StartGame = canStart.ToCommand(); RandomizeOrder = canStart.ToCommand(); RemovePlayer = ReactiveCommand.Create(); AddPlayer = this.WhenAnyValue(x => x.Players.Count, x => x.NewPlayerName, (count, newPlayerName) => count < 7 && !string.IsNullOrWhiteSpace(newPlayerName) && !this.Players.Contains(newPlayerName)) .ToCommand(); RandomizeOrder.Subscribe(_ => { using (Players.SuppressChangeNotifications()) { var r = new Random(); var newOrder = Players.OrderBy(x => r.NextDouble()).ToList(); Players.Clear(); Players.AddRange(newOrder); } }); RemovePlayer.Subscribe(player => { this.Players.Remove((string)player); }); AddPlayer.Subscribe(_ => { Players.Add(NewPlayerName.Trim()); NewPlayerName = string.Empty; }); }
public void RemovePlayer(RemovePlayer command) { if (Owner != default(Guid) && command.Requester != Owner) throw new DXGameException("unathorized_request"); if (!_players.Any(p => p == command.Player)) throw new DXGameException("playroom_does_not_contain_specified_player"); ApplyEvent(new PlayerLeft(this.Id, command.Player, Version, command.CommandId)); }
public IEnumerable Handle(RemovePlayer c) { if (_repository.GetByIdAsync(c.Id) == null) { throw new PlayerNotExist(); } _repository.RemoveAsync(c.Id); yield return(new PlayerRemoved(c.Id)); }
public async Task <Response> Handle(RemovePlayer request, CancellationToken cancellationToken) { var game = await _gameRepository.GetById(request.GameId); if (game == null) { throw new DomainException(ErrorCode.GameNotFound); } await _playerRepository.DeletePlayer(request.GameId, request.PlayerId); return(Response.Success); }
public void Execute_ShouldRemovePlayerFromAllPlayers() { // Given var allPlayers = Substitute.For <AllPlayers>(); var removePlayer = new RemovePlayer(allPlayers); var player = new Player("Test"); // When removePlayer.Execute(player); // Then allPlayers .Received() .Remove(player); }
public static Command UnpackCommand(BinaryReader reader) { var commandType = (CommandType)reader.ReadByte(); Command command; switch (commandType) { case CommandType.SetRandomSeed: command = new SetRandomSeed(); break; case CommandType.AddPlayer: command = new AddPlayer(); break; case CommandType.RemovePlayer: command = new RemovePlayer(); break; case CommandType.Respawn: command = new Respawn(); break; case CommandType.SetSpaceshipControls: command = new SetSpaceshipControls(); break; default: return(null); } command.LoadState(reader); return(command); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) { Exit(); } if (SERVER) { System.Console.WriteLine("You're the server"); //IDK WHAT YOU DO HERE RIVER... } else//CLIENT { //PARSING INCOMMING DATA IF ANY MyClient.Receive(); List <SendingClientInfo> clientInfo = null; MoveOther moveOther = new MoveOther(); MoveYou moveYou = new MoveYou(); RemovePlayer removePlayer = new RemovePlayer(); Command cmdHead = Command.Null; string command = CurrentCommand; //PARSE DATA SENT BY THE SERVER FOR EASY READING LATER if (command != "" && command != null) { System.Console.WriteLine("Received command: " + command); string[] tempCmdArgs = command.Split(','); cmdHead = (Command)int.Parse(tempCmdArgs[0]); switch ((Command)cmdHead) { case Command.MoveOther: moveOther = new MoveOther( int.Parse(tempCmdArgs[1]), int.Parse(tempCmdArgs[2]), int.Parse(tempCmdArgs[3]) ); System.Console.WriteLine("Move other ID: " + moveOther.id); break; case Command.MoveYou: moveYou = new MoveYou( int.Parse(tempCmdArgs[1]), int.Parse(tempCmdArgs[2]), int.Parse(tempCmdArgs[3]) ); System.Console.WriteLine("Move you ID: " + moveOther.id); break; case Command.SendingClientInfo: clientInfo = new List <SendingClientInfo>(); MyClient.ID = int.Parse(tempCmdArgs[1]); System.Console.WriteLine("MY ID SET TO: " + MyClient.ID); for (int i = 2; i < tempCmdArgs.Length; i++) { string[] arg = tempCmdArgs[i].Split(':'); SendingClientInfo plyStruct = new SendingClientInfo( int.Parse(arg[0]), int.Parse(arg[1]), int.Parse(arg[2]), int.Parse(arg[3]), int.Parse(arg[4]), int.Parse(arg[5]), new Color(int.Parse(arg[6]), int.Parse(arg[7]), int.Parse(arg[8])) ); clientInfo.Add(plyStruct); } break; case Command.MoveMe: System.Console.WriteLine("Why did the server send me this?"); break; case Command.RemovePlayer: removePlayer = new RemovePlayer(int.Parse(tempCmdArgs[1])); break; } Client.receiveDone = new System.Threading.ManualResetEvent(false); } switch (gameState) { case GameState.waiting: //If we got client info from the server, lets populate drawnEnts array if (cmdHead == Command.SendingClientInfo) { System.Console.WriteLine("Got initial client info"); gameState = GameState.playing; GetClientInfo(clientInfo); } break; case GameState.playing: switch (cmdHead) { case Command.Null: //NOTHING SHOULD EVER HAPPEN WHEN WE'RE NULL break; case Command.SendingClientInfo: System.Console.WriteLine("Got client info!"); ///I don't know how we could get here with clientInfo being null but you ///can never be too safe if (clientInfo != null) { GetClientInfo(clientInfo); } break; case Command.MoveMe: System.Console.WriteLine("We should not have gotten this. Wtf is the server doing?"); break; case Command.MoveYou: System.Console.WriteLine("Got a move you command"); ply.Position = new Rectangle( moveYou.x, moveYou.y, ply.Position.Width, ply.Position.Height ); break; case Command.MoveOther: System.Console.WriteLine("Got a move other command"); for (int i = 0; i < Ents.Count; i++) { //If we found an ent with the id of the ent we're supposed to move, move it if (Ents[i].Id == moveOther.id) { Ents[i].Position = new Rectangle( moveOther.x, moveOther.y, Ents[i].Position.Width, Ents[i].Position.Height); break; } } break; case Command.RemovePlayer: System.Console.WriteLine("Got a move player command"); for (int i = 0; i < Ents.Count; i++) { if (Ents[i].Id == removePlayer.id) { Ents.RemoveAt(i); break; } } break; } //CHECK FOR KEY PRESSES NOW if (Keyboard.GetState().IsKeyDown(Keys.A)) { MyClient.Send(string.Format( "{0},{1},{2},{3},{4},{5}", (int)Command.MoveMe, MyClient.ID, ply.Position.X - UniversalSpeed, ply.Position.Y, ply.Position.Width, ply.Position.Height)); } else if (Keyboard.GetState().IsKeyDown(Keys.D)) { MyClient.Send(string.Format( "{0},{1},{2},{3},{4},{5}", (int)Command.MoveMe, MyClient.ID, ply.Position.X + UniversalSpeed, ply.Position.Y, ply.Position.Width, ply.Position.Height)); } else if (Keyboard.GetState().IsKeyDown(Keys.W)) { MyClient.Send(string.Format( "{0},{1},{2},{3},{4},{5}", (int)Command.MoveMe, MyClient.ID, ply.Position.X, ply.Position.Y - UniversalSpeed, ply.Position.Width, ply.Position.Height)); } else if (Keyboard.GetState().IsKeyDown(Keys.S)) { MyClient.Send(string.Format( "{0},{1},{2},{3},{4},{5}", (int)Command.MoveMe, MyClient.ID, ply.Position.X, ply.Position.Y + UniversalSpeed, ply.Position.Width, ply.Position.Height)); } break; } //Clear the current command. command = null; CurrentCommand = command; } //client. // TODO: Add your update logic here base.Update(gameTime); }
public async Task <IActionResult> RemovePlayer([FromBody] RemovePlayer command) => await ProcessCommand(command);