/// <summary> /// Initializes a new instance of the <see cref="MultiPlayerViewModel"/> class. /// </summary> public MultiPlayerViewModel() { this.m = new MultiPlayerModel(); this.m.PropertyChanged += M_PropertyChanged; m.MazeCols = MVVM.Properties.Settings.Default.MazeCols; m.MazeRows = MVVM.Properties.Settings.Default.MazeRows; }
public MultiPlayerViewModel(MultiPlayerModel model) { this.model = model; this.model.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e) { NotifyPropertyChanged("VM_" + e.PropertyName); }; }
public string[] List() { MultiPlayerModel model = MultiPlayerModel.GetInstance(); string[] gamesArray = model.GetListOfGames(); return(gamesArray); //JObject gamesArray = JObject.Parse(gamesArrayJsonStr); //string[] gamesArray = JsonConvert.DeserializeObject<string[]>(gamesArrayJsonStr); //return gamesArray; }
public JObject Start(string gameName, int rows, int cols) { //Clients.All.hello(); MultiPlayerModel model = MultiPlayerModel.GetInstance(); string clientID = Context.ConnectionId; string mazeAsString = model.Start(gameName, rows, cols, clientID); Maze maze = Maze.FromJSON(mazeAsString); JObject obj = JObject.Parse(maze.ToJSON()); return(obj); }
public JObject Join(string gameName) { MultiPlayerModel model = MultiPlayerModel.GetInstance(); string clientID = Context.ConnectionId; string mazeAsString = model.Join(gameName, clientID); Maze maze = Maze.FromJSON(mazeAsString); string otherPlayerID = model.GetOtherPlayerID(clientID); JObject obj = JObject.Parse(maze.ToJSON()); //TODO: Call to function to draw the mazes on other player client(by notify to otherPlayerID ). Clients.Client(clientID).drawMazes(obj); Clients.Client(otherPlayerID).drawMazes(obj); return(obj); }
/// <summary> /// Handles the Clicked event of the MultiplayerBtn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void MultiplayerBtn_Clicked(object sender, RoutedEventArgs e) { var location = this.PointToScreen(new Point(0, 0)); // create the multiplayer model and give it the server IMultiPlayerModel model = new MultiPlayerModel(server); // set up and launch the multiplayer window MultiPlayer multiPlayer = new MultiPlayer(model, this); multiPlayer.Left = location.X; multiPlayer.Top = location.Y; this.player.Pause(); multiPlayer.Show(); this.Hide(); }
public void Play(string direction, int oldRow, int oldCol) { MultiPlayerModel model = MultiPlayerModel.GetInstance(); string clientID = Context.ConnectionId; string otherPlayerID = model.GetOtherPlayerID(clientID); //TODO: Call to function to draw this move on the other client canvas. if (direction == "won") { Clients.Client(otherPlayerID).otherWon(); } else { Clients.Client(otherPlayerID).otherMoving(direction, oldRow, oldCol); } }
/// <summary> /// Initializes a new instance of the <see cref="MultiPlayerViewModel"/> class. /// </summary> /// <param name="model">The model.</param> public MultiPlayerViewModel(PlayerModel model) : base(model) { this.model = model as MultiPlayerModel; listOfGames = new ObservableCollection <string>(); this.model.MazeGenerated += delegate(Object sender, Maze maze) { MazeString = maze.ToString(); OtherMazeString = maze.ToString(); MazeName = maze.Name; Rows = maze.Rows;////maybe to minus 1 Cols = maze.Cols; NotifyPropertyChanged("mazeGenerated"); }; this.model.ListOfGames += delegate(Object sender, string list) { string[] gameList = null; if (list != null) { list = list.Replace("[", "").Replace("]", "").Replace("\n", "").Replace("\r", "").Replace("\"", "").Replace(" ", ""); this.model.ListOfGamesString = list; gameList = list.Split(','); for (int i = 0; i < gameList.Length; i++) { listOfGames.Add(gameList[i]); } ListOfGames = listOfGames; } }; model.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e) { if (e.PropertyName.Contains("close")) { CheckIfSomeoneWon(); } else if (e.PropertyName.Contains("Direction")) { Direction dir = getDirectionFromString(e.PropertyName); MoveOtherPlayer(dir); } else if (e.PropertyName.Contains("lostConnection")) { NotifyPropertyChanged(e.PropertyName); } }; }