Exemple #1
0
 public ClientThread(View view,Game game, string server, int port)
 {
     this.view = view;
     this.port = port;
     this.server = server;
     this.game = game;
 }
Exemple #2
0
 public View()
 {
     InitializeComponent();
     buttons = new Button[8, 8];
     game = new Game(this);
     InitializeButtons();
 }
Exemple #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); }));
 }
Exemple #4
0
 public ServerThread(View view, Game game, int port=12000)
 {
     this.view = view;
     this.game = game;
     this.port = port;
 }
Exemple #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;
     }
 }
Exemple #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());
          }));
 }
Exemple #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);}));
        }
Exemple #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);
     }
 }