public void Process() { try { int stepCounter = 0; Console.OutputEncoding = Encoding.Unicode; Stream = client.GetStream(); string message = GetMessage(); Username = message; WriteUsernameToDb(this); message = WhoIam; server.BroadcastMessage(message, this.Id); Console.WriteLine("{0}: присоединился к игре!", Username); T_Game game = NewGameToDb(); if (game != null) { _gameIsCreated = true; } while (true) { try { message = GetMessage(); //message = String.Format(message); if (!_gameIsCreated) { game = NewGameToDb(); _gameIsCreated = true; } AddStepGame(message, game); serverMessage = String.Format("{0}: {1}", Username, message); Console.WriteLine(serverMessage); server.BroadcastMessage(message, this.Id); } catch (Exception ex) { message = String.Format("{0}: покинул игру", Username); server.RemoveConnection(Id); Console.WriteLine(message); break; } } } catch (Exception ex) { Console.Write("Process(): "); Console.WriteLine(ex.Message); Console.ReadKey(); } }
private T_Game NewGameToDb() { if (server.clients.Count != 2) { return(null); } T_Game _game = new T_Game(); try { using (var db = new ChessDataBaseDataContext()) { var user = db.T_Users.Select(q => q).ToArray(); foreach (var u in user) { _game = db.T_Games.FirstOrDefault(q => q.Black == u.Id && u.Nickname == server.clients[1].Username); } if (_game != null) { return(_game); } var newGame = new T_Game(); foreach (var cl in server.clients) { foreach (var u in user) { if (cl.Username == u.Nickname && cl.WhoIam == "w") { newGame.White = u.Id; } if (cl.Username == u.Nickname && cl.WhoIam == "b") { newGame.Black = u.Id; } } } db.T_Games.InsertOnSubmit(newGame); db.SubmitChanges(); _game = newGame; return(_game); } } catch (Exception ex) { Console.Write("NewGameToDb(): "); Console.WriteLine(ex.Message); Console.ReadKey(); } return(null); }
private void AddStepGame(string step, T_Game game) { try { if (game == null) { return; } using (var db = new ChessDataBaseDataContext()) { var stepArray = step.ToCharArray(); var count = db.T_Courses.Count(q => q.GameID == game.Id) + 1; var newStep = new T_Course { Course = step, GameID = game.Id, Number = count }; if (stepArray[0] == 'w') { newStep.WhoGone = game.White; } if (stepArray[0] == 'b') { newStep.WhoGone = game.Black; } db.T_Courses.InsertOnSubmit(newStep); db.SubmitChanges(); } } catch (Exception ex) { Console.Write("AddStepGame(): "); Console.WriteLine(ex.Message); Console.ReadKey(); } }
private void detach_T_Games1(T_Game entity) { this.SendPropertyChanging(); entity.T_User1 = null; }
private void attach_T_Games1(T_Game entity) { this.SendPropertyChanging(); entity.T_User1 = this; }
partial void DeleteT_Game(T_Game instance);
partial void UpdateT_Game(T_Game instance);
partial void InsertT_Game(T_Game instance);