private void OnError(object sender, Beetle.ChannelErrorEventArgs e) { Invoke(new Action<Beetle.ChannelErrorEventArgs>(r => { txtStatus.Text = r.Exception.Message; }), e); }
private void OnDisposed(object sender, Beetle.ChannelEventArgs e) { Invoke(new Action<Beetle.ChannelEventArgs>(s => { txtStatus.Text = "disconnect!"; }), e); }
public static void Send(Beetle.TcpChannel channel, object msg) { ProtobufAdapter adapter = new ProtobufAdapter(); adapter.Message = msg; channel.Send(adapter); //Beetle.ProtoBufAdapter.MessageAdapter.Send(channel, msg); }
private void OnDisposed(object sender, Beetle.ChannelDisposedEventArgs e) { Invoke(new Action<object>(o => { cmdSend.Enabled = false; cmdConnect.Enabled = true; }), new object()); }
public void ClientDisposed(Beetle.NetPackage.NetClient client) { Invoke(new Action<NetClient>(c => { txtStatus.Text = "close!"; }), client); }
public void Connected(Beetle.NetPackage.NetClient client) { Invoke(new Action<NetClient>(c => { txtStatus.Text = "connected!"; }), client); }
private void OnDisposed(object sender, Beetle.ChannelDisposedEventArgs e) { Invoke(new Action<Register>(o => { cmdRegister.Enabled = !(cmdConnect.Enabled = true); }), null); }
public void ClientError(Beetle.NetPackage.NetClient client, Exception e) { Invoke(new Action<Exception>(err => { txtError.Text = err.Message; }),e); }
public void Connected(Beetle.NetPackage.NetClient client) { this.Dispatcher.BeginInvoke(() => { txtStatus.Text = "connected!"; }); }
public static void Main() { var chatRoom = new ChatRoom(); Participant george = new Beetle("George"); // new Beetle("George", chatRoom); chatRoom.Register(george); Participant paul = new Beetle("Paul"); chatRoom.Register(paul); Participant ringo = new Beetle("Ringo"); chatRoom.Register(ringo); Participant john = new Beetle("John"); chatRoom.Register(john); Participant yoko = new NonBeetle("Yoko"); chatRoom.Register(yoko); yoko.Send("John", "Hi John!"); paul.Send("Ringo", "All you need is love"); ringo.Send("George", "My sweet Lord"); paul.Send("John", "Can't buy me love"); john.Send("Yoko", "My sweet love"); yoko.SendToAll("Hi, all!"); }
public void Save(Beetle.NetPackage.IDataWriter writer) { writer.WriteUTF(Name); writer.WriteUTF(EMail); writer.WriteUTF(City); writer.WriteUTF(Country); writer.WriteUTF(RegTime.ToString("yyyy-MM-dd HH:mm:ss")); }
public void ClientReceive(Beetle.NetPackage.NetClient client, object message) { if (message is Register) { Invoke(new Action<Register>(msg => { txtRegTime.Text = msg.RegTime.ToString(); }), message as Register); } }
public void OnLogin(Beetle.Express.IChannel channel, string id, string command, JToken token) { channel.Name = token["name"].ToString(); User user = new User(); user.Name = channel.Name; user.ID = channel.ID; user.Host = channel.EndPoint.ToString(); SendAll(id, command, user); }
protected override void OnReceive(object sender, Beetle.ChannelReceiveEventArgs e) { System.Threading.Interlocked.Increment(ref Count); string value = e.Channel.Coding.GetString(e.Data.Array, e.Data.Offset, e.Data.Count); C.WriteLine(value); Beetle.StringMessage msg = new Beetle.StringMessage(); msg.Value = value; e.Channel.Send(msg); }
public void OnTalk(Beetle.Express.IChannel channel, string id, string command, JToken token) { string content = token["content"].ToString(); Talk talk = new Talk(); talk.Content = content; talk.From = channel.Name; talk.Host = channel.EndPoint.ToString(); SendAll(id, command, talk); }
public override void Disposed(Beetle.Express.IServer server, Beetle.Express.ChannelEventArgs e) { base.Disposed(server, e); User user = new User(); user.Name = e.Channel.Name; user.ID = e.Channel.ID; user.Host = e.Channel.EndPoint.ToString(); SendAll(null, "exit", user); }
private void OnReceive(Beetle.PacketRecieveMessagerArgs e) { Register reg = (Register)e.Message; Invoke(new Action<Register>(r => { txtREMail.Text = r.EMail; txtRName.Text = r.Name; txtResponseTime.Text = r.ResponseTime.ToString(); }), reg); }
protected override Beetle.NetPackage.IMessage GetMessage(Beetle.NetPackage.IDataReader reader) { string Name = reader.ReadUTF(); switch (Name) { case "Register": return new Register(); } return null; }
public void Load(Beetle.BufferReader reader) { string type = reader.ReadString(); //Beetle.ByteArraySegment segment = mArrayPool.Pop(); byte[] data = reader.ReadByteArray(); using (System.IO.Stream stream = new System.IO.MemoryStream(data, 0, data.Length)) { Message = ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(stream, null, Type.GetType(type)); } }
private void OnReceive(object sender, Beetle.ChannelReceiveEventArgs e) { string value = e.Channel.Coding.GetString(e.Data.Array, e.Data.Offset, e.Data.Count); this.Invoke(new Action<string>(s => { richTextBox2.AppendText(value + "\r\n"); }), value); }
public void Load(Beetle.IDataReader reader) { Name = reader.ReadUTF(); EMail = reader.ReadUTF(); City = reader.ReadUTF(); Country = reader.ReadUTF(); string date = reader.ReadUTF(); Console.WriteLine(date); RegTime = DateTime.ParseExact(date, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); }
protected override Beetle.IMessage ReadMessageByType(Beetle.IDataReader reader, Beetle.ReadObjectInfo typeTag) { typeTag.TypeofString = reader.ReadUTF(); switch (typeTag.TypeofString) { case "Register": return new Register(); } return null; }
public void Load(Beetle.BufferReader reader) { string type = reader.ReadString(); Beetle.ByteArraySegment segment = mArrayPool.Pop(); reader.ReadByteArray(segment); using (System.IO.Stream stream = new System.IO.MemoryStream(segment.Array,0,segment.Count)) { Message = ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(stream, null, Type.GetType(type)); } mArrayPool.Push(segment); }
public void OnList(Beetle.Express.IChannel channel, string id, string command, JToken token) { List<User> users = new List<User>(); Server.GetOnlines(Onlines); for (int i = 0; i < Onlines.Count; i++) { Beetle.Express.IChannel client = Onlines.Channels[i]; users.Add(new User { Host = client.EndPoint.ToString(), ID = client.ID, Name = client.Name }); } SendAll(id, command, users); }
// 用于生成本地化 ApplicationBar 的示例代码 //private void BuildLocalizedApplicationBar() //{ // // 将页面的 ApplicationBar 设置为 ApplicationBar 的新实例。 // ApplicationBar = new ApplicationBar(); // // 创建新按钮并将文本值设置为 AppResources 中的本地化字符串。 // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // 使用 AppResources 中的本地化字符串创建新菜单项。 // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} public void ClientReceive(Beetle.NetPackage.NetClient client, object message) { if (message is Register) { Dispatcher.BeginInvoke(() => { Register reg = (Register)message; txtRegtime.Text = reg.RegTime.ToString(); }); } }
public void Save(Beetle.BufferWriter writer) { writer.Write(Message.GetType().FullName); byte[] data; using (System.IO.Stream stream = new System.IO.MemoryStream()) { ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, Message); data = new byte[stream.Length]; stream.Position = 0; stream.Read(data, 0, data.Length); } writer.Write(data); }
public override void Error(Beetle.Express.IServer server, Beetle.Express.ErrorEventArgs e) { if (e.Channel != null) { Console.WriteLine("{3}:{0}[{2}] channel error {1}", e.Channel.EndPoint, e.Error.Message, e.Channel.Name,GetType().Name); } else { Console.WriteLine("{1}: error {0}", e.Error.Message, GetType().Name); } base.Error(server, e); }
public void Error(Beetle.Express.IServer server, Beetle.Express.ErrorEventArgs e) { if (e.Channel != null) { "{0} channel error".Log4Error(e.Error, e.Channel.EndPoint); } else { "ec application error ".Log4Error(e.Error); } mApplication.OnError(new Events.EventApplicationErrorArgs { Application=mApplication,Info=e }); }
public void Save(Beetle.BufferWriter writer) { writer.Write(Message.GetType().Name); Beetle.ByteArraySegment segment = mArrayPool.Pop(); using(System.IO.Stream stream = new System.IO.MemoryStream(segment.Array)) { ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, Message); segment.SetInfo(0, (int)stream.Position); } writer.Write(segment); mArrayPool.Push(segment); }
public void Receive(Beetle.Express.IServer server, Beetle.Express.ChannelReceiveEventArgs e) { if (Encoding.UTF8.GetString(e.Data.Array, e.Data.Offset, e.Data.Count) == "GETSN") { byte[] sn = mCreate.GetValueData(); Beetle.Express.Data data = new Beetle.Express.Data(); data.SetBuffer(sn, 0, 8); e.Channel.Server.Send(data, e.Channel); } else { e.Channel.Dispose(); } }
public void CheckBeetleStackCloning() { Ant ant = new Ant(PieceColor.Black, 1); Beetle beetle = new Beetle(PieceColor.Black, 1); Beetle beetle2 = new Beetle(PieceColor.Black, 2); Beetle beetle3 = new Beetle(PieceColor.White, 1); Beetle beetle4 = new Beetle(PieceColor.White, 2); BeetleStack bs = new BeetleStack(beetle3, new BeetleStack(ant, beetle)); BeetleStack bs2 = new BeetleStack(beetle4, bs); Assert.IsFalse(bs.Equals(bs2)); Assert.IsTrue(bs.Contains(beetle3)); Assert.IsTrue(bs2.Contains(beetle3)); }
public static void Run() { var chatRoom = new ChatRoom(); Participant george = new Beetle("George"); // new Beetle("George", chatRoom); chatRoom.Register(george); Participant paul = new Beetle("Paul"); chatRoom.Register(paul); Participant ringo = new Beetle("Ringo"); chatRoom.Register(ringo); Participant john = new Beetle("John"); chatRoom.Register(john); Participant yoko = new NonBeetle("Yoko"); chatRoom.Register(yoko); yoko.Send("John", "Hi John!"); paul.Send("Ringo", "All you need is love"); ringo.Send("George", "My sweet Lord"); paul.Send("John", "Can't buy me love"); john.Send("Yoko", "My sweet love"); yoko.SendToAll("Hi, all!"); /* * Alternative: * Meet Paul with George and vice-versa * Meet Ringo with Paul and vice-versa * Meet Ringo with George and vice-versa * Meet John with Paul and vice-versa * Meet John with George and vice-versa * Meet John with Ringo and vice-versa * Meet Yoko with Paul and vice-versa * Meet Yoko with George and vice-versa * Meet Yoko with Ringo and vice-versa * Meet Yoko with John and vice-versa */ }
public void CheckBeetleStackEquality() { Ant ant = new Ant(PieceColor.Black, 1); Beetle beetle = new Beetle(PieceColor.Black, 1); Beetle beetle2 = new Beetle(PieceColor.Black, 2); Beetle beetle3 = new Beetle(PieceColor.White, 1); Beetle beetle4 = new Beetle(PieceColor.White, 2); BeetleStack bs = new BeetleStack(beetle3, new BeetleStack(ant, beetle)); BeetleStack bs2 = new BeetleStack(beetle3, new BeetleStack(ant, beetle)); BeetleStack bs3 = new BeetleStack(ant, beetle4); Assert.IsTrue(bs.Equals(bs2)); Assert.IsFalse(bs3.Equals(bs2)); Assert.IsFalse(bs2.Equals(beetle3)); }
private void OnReadyToFight(Beetle p1, Beetle p2) { Color p1Dom = p1.GetDominantColor(); Color p2Dom = p2.GetDominantColor(); Color outcome = DecideOutcome(p1Dom, p2Dom); bool p1wins = outcome == p1Dom; if (outcome == Color.None) { p1wins = true; } OnMatchOutcomeDecided?.Invoke(p1wins); return; }
private void HandleBeetleToStackMove(Beetle movingPiece, Piece referencePiece, Hex from, Hex to) { // beetle climbing BeetleStack newStack; if (referencePiece is BeetleStack) { newStack = new BeetleStack(movingPiece, (BeetleStack)referencePiece); } else { // new beetle stack newStack = new BeetleStack(referencePiece, movingPiece); } _playedPieces.Remove(referencePiece); _boardPieceArray[to.column, to.row] = newStack; _playedPieces.Add(newStack, to); }
void SpawnBeetles(int count, Vector2 JackPos) { int spawnCount = 0; while (spawnCount < count) { Vector2 randPos = GetRandomPointOnStreet(); if ((randPos - JackPos).magnitude < Beetle.NearJackThreshold) { continue; } Beetle b = new Beetle(this); b.SpawnAt(randPos); //Debug.Log("spawning beetle at " + randPos); Beetles.Add(b); spawnCount += 1; } }
public static void Main() { var airbus = new Airbus(); var boeing = new Boeing(); var dinghy = new Dinghy(); var titanic = new Yacht(); var sequoia = new Sequoia(); var beetle = new Beetle(); // Build a collection of all vehicles that fly // With a single `foreach`, have each vehicle Fly() var flyings = new List <Aircraft> { airbus, boeing }; foreach (var flying in flyings) { flying.Flying(); } // Build a collection of all vehicles that operate on roads // With a single `foreach`, have each road vehicle Drive() var drivings = new List <Car> { sequoia, beetle }; foreach (var driving in drivings) { driving.Driving(); } // Build a collection of all vehicles that operate on water // With a single `foreach`, have each water vehicle Drive() var waterings = new List <Watercraft> { dinghy, titanic }; foreach (var watering in waterings) { watering.Driving(); } }
internal static void Main() { var chatRoom = new ChatRoom(); Participant george = new Beetle("George"); Participant paul = new Beetle("Paul"); Participant ringo = new Beetle("Ringo"); Participant john = new Beetle("John"); Participant yoko = new NonBeetle("Yoko"); chatRoom.Register(george); chatRoom.Register(paul); chatRoom.Register(ringo); chatRoom.Register(john); chatRoom.Register(yoko); yoko.Send("John", "Hi John!"); paul.Send("Ringo", "All you need is love"); ringo.Send("George", "My sweet Lord"); paul.Send("John", "Can't buy me love"); john.Send("Yoko", "My sweet love"); }
public override void OnMovement(Mobile m, Point3D oldLocation) { base.OnMovement(m, oldLocation); if (m == null || m.Deleted || m == Beetle || !m.Alive || !m.InRange3D(this, 1, -5, 5) || (Beetle != null && !Beetle.CanBeHarmful(m))) { return; } if (Beetle != null) { Beetle.DoHarmful(m, true); } if (m is BaseCreature && m.IsControlled()) { m.Damage(25); } else if (m is PlayerMobile) { m.Damage(1); } if (m.Poisoned) { return; } if (m is PlayerMobile) { m.ApplyPoison(Beetle ?? m, Poison.Deadly); } else if (m is BaseCreature) { m.ApplyPoison(Beetle ?? m, Poison.Lethal); } }
private void OnCarriageSelected(Carriage c) { if (ReadyToFight) { Debug.Log("READY TO FIGHT"); OnReadyToFight?.Invoke(m_player1, m_player2); return; } CarriageDefinition.Color color = c.CarriageDefinition.GetColor(); if (color == CarriageDefinition.Color.Wild) { int rand = UnityEngine.Random.Range(0, 3); color = (CarriageDefinition.Color)rand; } CarriageDefinition.Ability ability = c.CarriageDefinition.GetAbility(); Beetle player = GetCurrentPlayer(); Beetle otherPlayer = GetOtherPlayer(); switch (ability) { case CarriageDefinition.Ability.None: player.AddCarriage(color); break; case CarriageDefinition.Ability.Copy: if (player.CarriageCount == 0) { return; } Carriage lastCarriage = player.GetLastCarriage(); color = lastCarriage.CarriageDefinition.GetColor(); player.AddCarriage(color); break; case CarriageDefinition.Ability.Send: if (otherPlayer.CarriageCount == GameConstants.MAX_CARRIAGE_CAPACITY) { player.AddCarriage(color); } else { otherPlayer.AddCarriage(color); } break; case CarriageDefinition.Ability.Swap: if (player.CarriageCount > 0 && otherPlayer.CarriageCount > 0) { Carriage c1 = player.RemoveLastCarriage(); Carriage c2 = otherPlayer.RemoveLastCarriage(); player.AddCarriage(c2.CarriageDefinition.GetColor()); otherPlayer.AddCarriage(c1.CarriageDefinition.GetColor()); Destroy(c1.gameObject); Destroy(c2.gameObject); } player.AddCarriage(color); break; case CarriageDefinition.Ability.DoubleDip: m_doubleDip = true; player.AddCarriage(color); break; case CarriageDefinition.Ability.Shuffle: player.AddCarriage(color); m_carriageContainer.GetComponent <CarriageMenu>().Reset(); m_currentHand.Clear(); DrawHand(); m_carriageContainer.GetComponent <CarriageMenu>().Init(); break; } c.gameObject.SetActive(false); if (m_doubleDip) { m_doubleDip = false; } else { NextTurn(); } if (ReadyToFight) { OnReadyToFight?.Invoke(m_player1, m_player2); } }
public void AbsorbTarget(Mobile from, object obj) { if (!(obj is Beetle)) { from.SendMessage("Ce pouvoir vous serait inutile pour la seule utilisation actuelle de ce crystal..."); return; } Beetle targ = (Beetle)obj; if (!targ.Controlled || targ.ControlMaster != from || !targ.IsBonded) { from.SendMessage("La créature à qui vous capturerez l'âme doit vous être fortement liée."); return; } bool skill = from.CheckSkill(SkillName.Mysticism, 10, 60); if (!skill) { from.SendMessage("Vous échouez dans votre tentative d'absorber l'âme de cette créature"); int bad = Utility.Random(1, 100); if (bad == 5) { targ.Emote("S'effondre au sol, inerte"); targ.IsBonded = false; targ.Kill(); } else if (bad > 5 && bad < 9) { targ.Emote("S'effondre au sol, inanimée"); targ.Kill(); } else if (bad < 4) { from.Emote("Le Crystal explore"); this.Delete(); } else if (bad > 10 && bad < 20) { targ.Emote("Faiblit"); targ.Str--; if (targ.Str == 0) { targ.Delete(); } } else if (bad > 20 && bad < 30) { targ.Emote("Faiblit"); targ.Dex--; if (targ.Dex == 0) { targ.Delete(); } } else if (bad > 30 && bad < 40) { targ.Emote("Faiblit"); targ.Int--; if (targ.Int == 0) { targ.Delete(); } } return; } from.SendMessage("Vous absorbez une partie de l'âme de la bête"); this.Completion += Math.Max(Utility.Random(1, 2), (int)from.Skills[SkillName.Mysticism].Value / 10); if (Completion > 100) { Completion = 100; } if (!from.CheckSkill(SkillName.AnimalLore, 0, 40)) { targ.Emote("Exprime une douleur intense et ne semble pas vous reconnaitre"); targ.IsBonded = false; targ.Controlled = false; targ.ControlMaster = null; } else if (!from.CheckSkill(SkillName.AnimalLore, 0, 120)) { targ.Emote("Exprime une douleur intense et vous observe avec crainte"); targ.IsBonded = false; } else { targ.Emote("Semble ne pas comprendre"); } return; }
private void GeneratePlacementMoves() { foreach (KeyValuePair <Hex, Hivailability> kvp in _hivailableHexes) { if (kvp.Value.BlackCanPlace && !_whiteToPlay) { // on turn 1 you cannot place a bee if (!(turnNumber == 2)) { QueenBee queenBee = _unplayedPieces.OfType <QueenBee>().Where(p => p.color == PieceColor.Black).FirstOrDefault(); if (null != queenBee) { _moves.Add(Move.GetMove(queenBee, kvp.Key)); } // on turn 4 you must place a bee if you haven't already if (!blackQueenPlaced && turnNumber == 8) { continue; } } Beetle beetle = _unplayedPieces.OfType <Beetle>().Where(p => p.color == PieceColor.Black).FirstOrDefault(); Ant ant = _unplayedPieces.OfType <Ant>().Where(p => p.color == PieceColor.Black).FirstOrDefault(); Spider spider = _unplayedPieces.OfType <Spider>().Where(p => p.color == PieceColor.Black).FirstOrDefault(); Hopper hopper = _unplayedPieces.OfType <Hopper>().Where(p => p.color == PieceColor.Black).FirstOrDefault(); if (null != beetle) { _moves.Add(Move.GetMove(beetle, kvp.Key)); } if (null != ant) { _moves.Add(Move.GetMove(ant, kvp.Key)); } if (null != spider) { _moves.Add(Move.GetMove(spider, kvp.Key)); } if (null != hopper) { _moves.Add(Move.GetMove(hopper, kvp.Key)); } } if (kvp.Value.WhiteCanPlace && _whiteToPlay) { // on turn 1 you cannot place a bee if (!(turnNumber == 1)) { QueenBee queenBee = _unplayedPieces.OfType <QueenBee>().Where(p => p.color == PieceColor.White).FirstOrDefault(); if (null != queenBee) { _moves.Add(Move.GetMove(queenBee, kvp.Key)); } // on turn 4 you must place a bee if you haven't already if (!whiteQueenPlaced && turnNumber == 7) { continue; } } Beetle beetle = _unplayedPieces.OfType <Beetle>().Where(p => p.color == PieceColor.White).FirstOrDefault(); Ant ant = _unplayedPieces.OfType <Ant>().Where(p => p.color == PieceColor.White).FirstOrDefault(); Spider spider = _unplayedPieces.OfType <Spider>().Where(p => p.color == PieceColor.White).FirstOrDefault(); Hopper hopper = _unplayedPieces.OfType <Hopper>().Where(p => p.color == PieceColor.White).FirstOrDefault(); if (null != beetle) { _moves.Add(Move.GetMove(beetle, kvp.Key)); } if (null != ant) { _moves.Add(Move.GetMove(ant, kvp.Key)); } if (null != spider) { _moves.Add(Move.GetMove(spider, kvp.Key)); } if (null != hopper) { _moves.Add(Move.GetMove(hopper, kvp.Key)); } } } }
public void WearHelmet(Beetle beetle) { ; helmet = beetle; protectionState.Helmet(); }