예제 #1
0
 public ClientThread(View view,Game game, string server, int port)
 {
     this.view = view;
     this.port = port;
     this.server = server;
     this.game = game;
 }
예제 #2
0
 public void GetMove(NetworkStream ns, View view, Game game )
 {
     BinaryFormatter formatter = new BinaryFormatter();
     Position from = (Position)formatter.Deserialize(ns);
     Position to = (Position)formatter.Deserialize(ns);
     // view
     view.Invoke(new Action(
         () => { game.Cell_Click(from); Thread.Sleep(100); game.Cell_Click(to); }));
 }
예제 #3
0
 public ServerThread(View view, Game game, int port=12000)
 {
     this.view = view;
     this.game = game;
     this.port = port;
 }
예제 #4
0
 public void SendMove(NetworkStream ns, View view, Game game)
 {
     //MessageBox.Show("Send move");
     lock (from)
     {
         WriteString(ns, commov);
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(ns, from);
         formatter.Serialize(ns, to);
         newmove = false;
     }
 }
예제 #5
0
 protected void GetSuperiority(NetworkStream ns, View view, Game game)
 {
     BinaryFormatter formatter = new BinaryFormatter();
     FigureTypes figtype = (FigureTypes)formatter.Deserialize(ns);
     Position pos = (Position)formatter.Deserialize(ns);
     view.Invoke(new Action(
         () =>
         {
             game.DirectStateCycle();
             game.Field.TransformPawn(pos, figtype);
             view.DrawField();
             game.Field.ShahCheck(game.Field.GetFigureAt(pos));
             view.SetTurnText();
             view.WhiteCount(game.Player1.GetCount());
             view.BlackCount(game.Player2.GetCount());
          }));
 }
예제 #6
0
        protected void GetDefeat(NetworkStream ns, View view, Game game)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            Side side = (Side)formatter.Deserialize(ns);

            view.Invoke(new Action(
            () =>{game.EndGame(game.Field.SideToPlayer(side).King);}));
        }
예제 #7
0
 protected void CommandLoop(NetworkStream ns, View view, Game game)
 {
     bool docycle = true;
     string command;
     while (docycle)
     {
         if (ns.DataAvailable)
         {// command
             command = ReadString(ns);
             switch (command)
             {
                 case commov:
                     {
                         GetMove(ns, view, game);
                         break;
                     }
                 case comend:
                     {
                         docycle = false;
                         break;
                     }
                 case comdef:
                     {
                         GetDefeat(ns, view, game);
                         docycle = false;
                         break;
                     }
                 case comsuperiority:
                     {
                         GetSuperiority(ns, view, game);
                         break;
                     }
             }
         }
         lock (lockobj)
         {
             if (newmove)
             {
                 SendMove(ns, view, game);
             }
             if (hasdefeat)
             {
                 SendDefeat(ns, defeatside);
                 docycle = false;
             }
             if (hassuperiority)
             {
                 SendSuperiority(ns, superiorityfigtype, superioritypos);
             }
             if (hasclosed)
             {
                 docycle = false;
             }
         }
         Thread.Sleep(100);
     }
 }
예제 #8
0
 public ServerThread(View view, Game game, int port = 12000)
 {
     this.view = view;
     this.game = game;
     this.port = port;
 }
예제 #9
0
파일: Game.cs 프로젝트: peleccom/chess
 public Game(View view)
 {
     this.view = view;
     view.ShowgbHUD(false);
 }