/// <summary> /// sends to server their move /// </summary> /// <param name="direction">direction they moved</param> public void MovePlayer(string direction) { string s = "play "; s += direction; TcpMessenger.Write(s); }
/// <summary> /// Gets a list of the games the player can join /// </summary> /// <returns>list of games</returns> public ObservableCollection <string> GetListOfGames() { string request = "list"; TcpMessenger.Write(request); string response = TcpMessenger.Read(); response = response.Replace("\n", ""); response = response.Replace("[", ""); response = response.Replace("]", ""); response = response.Replace("\"", ""); string[] games = response.Split(','); games = games.Take(games.Count() - 1).ToArray(); List <string> list = games.ToList <string>(); gameList = new ObservableCollection <string>(list); return(gameList); }
/// <summary> /// Starts or joins the game, and begins the /// task of receiving the opponents moves /// </summary> /// <param name="action"> start or join</param> public void StartGame(string action) { string s; if (action == "join") { s = "join "; s += Name; } else { s = "start "; s += Name + " " + Rows + " " + Cols; } TcpMessenger.Write(s); string maze = TcpMessenger.Read(); MyMaze = Maze.FromJSON(maze); InitialPos = MyMaze.InitialPos; GoalPos = MyMaze.GoalPos; if (action == "join") { Rows = MyMaze.Rows; Cols = MyMaze.Cols; } new Task(() => { while (true) { string pos = TcpMessenger.Read(); if (pos.Contains("Left")) { OnOpponentMoved(Key.Left); } else if (pos.Contains("Right")) { OnOpponentMoved(Key.Right); } else if (pos.Contains("Up")) { OnOpponentMoved(Key.Up); } else if (pos.Contains("Down")) { OnOpponentMoved(Key.Down); } else if (pos.Contains("close")) { OnOpponentMoved(Key.Delete); } else if (pos.Contains("quit")) { OnOpponentMoved(Key.Back); } } }).Start(); }
public DebuggerClient(string ip, int port) { messenger = new TcpMessenger(ip, port); messenger.TcpMessengerRecieved += messenger_TcpMessengerRecieved; Pointers = new List <string>(); }