/// <summary> /// c'tor of the command /// </summary> /// <param name="handler">the handler of this command</param> /// <param name="msgHandler">the handler of the play command handler of the game</param> /// <param name="model">the model</param> public MultiplayerCommand(IHandleOutput <Tuple <string, Tuple <IMaze, IMaze> > > handler, IHandlerUpdate msgHandler, IModel model) { this.handler = handler; this.msgHandler = msgHandler; this.model = model; }
/// <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> /// 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> /// 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*/ }