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