void AddPeer(Peer obj) { var wel = new StyledStringElement (obj.DisplayName); wel.Tapped += () => { SelectWhite (wel, obj); }; white.Add (wel); var bel = new StyledStringElement (obj.DisplayName); bel.Tapped += () => { SelectBlack (bel, obj); }; black.Add (bel); ReloadData (); Peer.ColoursSelectedDelegate selectColours = (Peer sender, bool is_white) => { if (is_white) { SelectWhite (white_you, null, true); SelectBlack (bel, sender, true); } else { SelectWhite (wel, sender, true); SelectBlack (black_you, null, true); } }; obj.ColoursSelected += (Peer sender, bool is_white) => { BeginInvokeOnMainThread (() => { selectColours (sender, is_white); }); }; obj.StartGame += (Peer sender, bool is_white) => { BeginInvokeOnMainThread (() => { CreateGame (true); }); }; }
void SelectBlack(StyledStringElement el, Peer peer = null, bool from_event = false) { XamGame.PlayerBlack = peer; selected_black = el; if (selected_black == black_computer) Game.PlayerBlack.Intelligence = Player.PlayerIntelligenceNames.Computer; else Game.PlayerBlack.Intelligence = Player.PlayerIntelligenceNames.Human; if (peer != null && !from_event) peer.SendColoursSelected (false); Update (); }
void SelectWhite(StyledStringElement el, Peer peer = null, bool from_event = false) { XamGame.PlayerWhite = peer; selected_white = el; if (selected_white == white_computer) Game.PlayerWhite.Intelligence = Player.PlayerIntelligenceNames.Computer; else Game.PlayerWhite.Intelligence = Player.PlayerIntelligenceNames.Human; if (peer != null && !from_event) peer.SendColoursSelected (true); Update (); }
public static void Send(Peer peer, string data) { Send (peer.Address, data); }
static void Process(IPAddress from, string id, string message) { string c; if (!message.StartsWith ("XamChess: ")) return; message = message.Substring ("XamChess: ".Length); if (!message.StartsWith ("C: ")) return; c = message.Substring (3, message.IndexOf (' ', 3) - 3); message = message.Substring (3 + c.Length + 1); Peer peer = null; lock (peers) { peers.TryGetValue (id, out peer); } if (message.StartsWith ("Peer: ")) { // Peer broadcasting. lock (peers) { if (peer == null) { peer = new Peer () { Id = id, DisplayName = message.Substring ("Peer: ".Length), Address = from, }; peers.Add (id, peer); if (PeerAdded != null) PeerAdded (peer); } peer.Stamp = DateTime.Now; } } else if (message.StartsWith ("ColourSelected: ")) { peer.OnColoursSelected (message.Substring ("ColourSelected: ".Length) == "White"); } else if (message.StartsWith ("StartGame: ")) { peer.OnStartGame (message.Substring ("StartGame: ".Length) == "White"); } else if (message.StartsWith ("MoveCompleted: ")) { peer.OnMoveCompleted (message.Substring ("MoveCompleted: ".Length)); } }
void SelectWhite(RadioButton el, Peer peer = null, bool from_event = false) { XamGame.PlayerWhite = peer; selected_white = el; selected_white.Checked = true; if (selected_white == white_computer) { Game.PlayerWhite.Intelligence = Player.PlayerIntelligenceNames.Computer; } else { Game.PlayerWhite.Intelligence = Player.PlayerIntelligenceNames.Human; } if (peer != null && !from_event) peer.SendColoursSelected (true); }
void SelectBlack(RadioButton el, Peer peer = null, bool from_event = false) { XamGame.PlayerBlack = peer; selected_black = el; selected_black.Checked = true; if (selected_black == black_computer) { Game.PlayerBlack.Intelligence = Player.PlayerIntelligenceNames.Computer; } else { Game.PlayerBlack.Intelligence = Player.PlayerIntelligenceNames.Human; } if (peer != null && !from_event) peer.SendColoursSelected (false); }
void AddPeer(Peer obj) { var tag = new PeerWrapper () { WrappedPeer = obj }; var rgw = new RadioButton (this); rgw.Text = obj.DisplayName; rgw.Tag = tag; rgw.Click += (sender, e) => { SelectWhite (rgw, obj); }; white_group.AddView (rgw); white_buttons.Add (rgw); var rgb = new RadioButton (this); rgb.Text = obj.DisplayName; rgb.Tag = tag; rgb.Click += (sender, e) => { SelectBlack (rgb, obj); }; black_group.AddView (rgb); black_buttons.Add (rgb); tags [obj.Id] = tag; Peer.ColoursSelectedDelegate selectColours = (Peer sender, bool is_white) => { if (is_white) { SelectWhite (white_you, null, true); SelectBlack (rgb, sender, true); } else { SelectWhite (rgw, sender, true); SelectBlack (black_you, null, true); } }; obj.ColoursSelected += (Peer sender, bool white) => { RunOnUiThread (() => selectColours (sender, white)); }; obj.StartGame += (Peer sender, bool white) => { RunOnUiThread (() => { CreateGame (true); }); }; }