示例#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
文件: View.cs 项目: peleccom/chess
 public View()
 {
     InitializeComponent();
     buttons = new Button[8, 8];
     game = new Game(this);
     InitializeButtons();
 }
示例#3
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); }));
 }
示例#4
0
 public ServerThread(View view, Game game, int port=12000)
 {
     this.view = view;
     this.game = game;
     this.port = port;
 }
示例#5
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;
     }
 }
示例#6
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());
          }));
 }
示例#7
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);}));
        }
示例#8
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);
     }
 }