/// <summary> /// handle the output usign the abstract method /// </summary> /// <param name="output">the output that need to send</param> /// <param name="send">where send to</param> public void HandleOutput(T output, ISendableView send) { //convert string toSend = new ConvertJsonFormat().ConvertOutput( this.GetNumberCommandHandle(), this.Handle(output)); //send send.SendMessage(toSend); }
/// <summary> /// add the second player to the game, and start play /// </summary> /// <param name="playerMaze">the handler update of the maze</param> /// <param name="playerMsg">the handler update of the play</param> /// <param name="view">the view of the player</param> public void AddSecMember(IHandlerUpdate playerMaze, IHandlerUpdate playerMsg, ISendableView view) { this.SecPlayerMaze = playerMaze; this.updateSec += playerMsg.UpdateView; this.ViewSecPlayer = view; IsPlay = true; }
/// <summary> /// check if player is in the game /// </summary> /// <param name="theSender">the player</param> /// <returns>true if here, otherwise false</returns> public bool IsPlayerHere(ISendableView theSender) { if (this.viewFirstPlayer.Equals(theSender) || (this.ViewSecPlayer != null && this.ViewSecPlayer.Equals(theSender))) { return(true); } return(false); }
/// <summary> /// create the game and put the first player /// </summary> /// <param name="name">the name of the game</param> /// <param name="playerMaze">the handler update of the maze</param> /// <param name="playerMsg">the handler update of the play</param> /// <param name="view">the view of the player</param> public Game(string name, IHandlerUpdate playerMaze, IHandlerUpdate playerMsg, ISendableView view) { this.FirstPlayerMaze = playerMaze; this.updateFirst += playerMsg.UpdateView; this.viewFirstPlayer = view; this.NameGame = name; IsPlay = false; }
/// <summary> /// c'tor of the command handler /// </summary> /// <param name="convert">how to convert</param> /// <param name="model">the model</param> /// <param name="command">the command </param> /// <param name="view">who send</param> public CommandHandler(IConvertableView convert, IModel model, string command, ISendableView view) { this.nextCommand = command; this.whoSend = view; //create the dict this.commands = new Dictionary <string, ICommandable>(); PlayCommand playCommander = new PlayCommand(new PlayHandleView(convert), model); this.commands.Add(generateCommand, new GenerateCommand(new GenerateHandleView(convert), model)); this.commands.Add(solveCommand, new SolveCommand(new SolveHandleView(convert), model)); this.commands.Add(multiCommand, new MultiplayerCommand(new MultiHandleView(convert), playCommander, model)); this.commands.Add(clueCommand, new ClueCommand(new ClueHandleView(convert), model)); this.commands.Add(playCommand, playCommander); this.commands.Add(closeCommand, new CloseCommand(null, model)); }
/// <summary> /// update the other player that the player moved /// </summary> /// <param name="move">the movement</param> /// <param name="whoSend">who send the movemnt</param> public void PlayerMoved(string move, ISendableView whoSend) { Game game; //find the game that the player inside and send the other player that moved if ((game = this.games.Find(item => item.IsPlayerHere(whoSend))) != null) { if (whoSend.Equals(game.viewFirstPlayer)) { game.SendSecPlayer(move); } else { game.SendFirstPlayer(move); } } }
/// <summary> /// Add Player to game with this name /// </summary> /// <param name="nameGame">the name of the game</param> /// <param name="forStart">the handler of the start of the game</param> /// <param name="forMsg">the handler of the play</param> /// <param name="view">the view of this player</param> /// <returns>true if added, false if the player allready in game</returns> public void AddPlayerToGame(string nameGame, IHandlerUpdate forStart, IHandlerUpdate forMsg, ISendableView view) { List <Game> thePossibleGames; //if the //if the player allready in game if (this.games.Find(item => item.IsPlayerHere(view)) != null) { return; } //if got to here so the player doesn't play in any game. //find the all games that have that nameGame if ((thePossibleGames = this.games.FindAll(item => item.NameGame == nameGame)) != null) { /*find the first game that is't played allready and add the player to the * game and send to the players that in the game*/ foreach (Game theGame in thePossibleGames) { //check if (theGame.IsPlay != true) { theGame.AddSecMember(forStart, forMsg, view); Tuple <IMaze, IMaze> firstmazes = this.mazes.GetMazesForGame(nameGame); Tuple <IMaze, IMaze> secMazes = new Tuple <IMaze, IMaze>(firstmazes.Item2, firstmazes.Item1); theGame.FirstPlayerMaze.UpdateView(new Tuple <string, Tuple <IMaze, IMaze> >(nameGame, (firstmazes)), theGame.viewFirstPlayer); theGame.SecPlayerMaze.UpdateView(new Tuple <string, Tuple <IMaze, IMaze> >(nameGame, (secMazes)), theGame.ViewSecPlayer); return; } } } /*if got to here it's meen that there is no game with the nameGame that * have place to the new player*/ this.games.Add(new Game(nameGame, forStart, forMsg, view)); /* Game g = this.games.ElementAt(this.games.Count - 1); * Tuple < IMaze, IMaze > test = this.mazes.GetMazesForGame(nameGame); * g.FirstPlayerMaze.UpdateView(new Tuple<string, Tuple<IMaze, IMaze>>("one player", (test)), * g.viewFirstPlayer*/ }
public void Execute(List <string> args, ISendableView sender) { string toSend = this.model.GetClue(args[0], Int32.Parse(args[1]), Int32.Parse(args[2])); this.clueHandleView.HandleOutput(toSend, sender); }
/// <summary> /// update the view according the handler and the view /// </summary> /// <param name="theUpdate">what need to update</param> /// <param name="view">who need to update</param> public void UpdateView(object theUpdate, ISendableView view) { this.handler.HandleOutput(theUpdate as Tuple <string, Tuple <IMaze, IMaze> >, view); }
/// <summary> /// do the command /// </summary> /// <param name="args">the args of the command</param> /// <param name="sender">who send the command and to who send back</param> public void Execute(List <string> args, ISendableView view) { this.model.AddPlayerToGame(args[0], this, this.msgHandler, view); }
/// <summary> /// do the command /// </summary> /// <param name="args">the args of the command</param> /// <param name="sender">who send the command and to who send back</param> public void Execute(List <string> args, ISendableView sender) { IMaze maze = this.model.GetMaze(args[0], Int32.Parse(args[1])); this.handler.HandleOutput(maze, sender); }
/// <summary> /// close all the game that have the nameGame, even if they did't played yet /// </summary> /// <param name="nameGame">the name of the game</param> /// <param name="whoSend">who send it</param> public void ColseGame(string nameGame, ISendableView whoSend) { this.games.RemoveAll(item => item.IsPlayerHere(whoSend)); }
/// <summary> /// do the command /// </summary> /// <param name="args">the args of the command</param> /// <param name="sender">who send the command and to who send back</param> public void Execute(List <string> args, ISendableView sender) { this.model.ColseGame(args[0], sender); }
/// <summary> /// update the view /// </summary> /// <param name="theUpdate">the update</param> /// <param name="view">who to update</param> public void UpdateView(object theUpdate, ISendableView view) { this.handler.HandleOutput(theUpdate as string, view); }
/// <summary> /// do the command /// </summary> /// <param name="args">the args of the command</param> /// <param name="sender">who send the command and to who send back</param> public void Execute(List <string> args, ISendableView sender) { this.model.PlayerMoved(args[0], sender); }
/// <summary> /// get the command /// </summary> /// <param name="command">the command </param> /// <param name="whoSend">me</param> public void GetCommand(out string command, out ISendableView whoSend) { command = this.lastResv; whoSend = this as ISendableView; }