private static bool OnProcessBorn(NetServer server, int id, NetIncomingMessage msg) { var r = new Msg_AgarBorn(); r.R(msg); uint uid = r.UserId; string name = r.Name; int x = RandomMaker.Next(GameWidth); int y = RandomMaker.Next(GameHeight); int radius = PlayerBall.DefaultPlayerRadius; uint c = CustomColors.RandomColor; // 添加Player到Manager PlayerBall player = new PlayerBall(); player.X = x; player.Y = y; player.Radius = radius; player.Color = c; player.Name = name; PlayerBallMgr.Add(uid, player); MarkMgr.Update(uid, radius); // 更新链接对应的ID AgarConnMgr.Modify(msg.SenderConnection, uid); // 向自身发送出生位置等信息 var selfMsg = new Msg_AgarSelf(); selfMsg.Operat = Msg_AgarSelf.Born; selfMsg.X = x; selfMsg.Y = y; selfMsg.Radius = radius; selfMsg.Color = c; SendMessage(server, selfMsg, msg.SenderConnection); // 向之前加入的玩家推送新用户出生信息 var oMsg = new Msg_AgarPlayInfo(); oMsg.Operat = Msg_AgarPlayInfo.Add; oMsg.UserId = uid; oMsg.Tag = GameMessageHelper.ALL_TAG; oMsg.X = x; oMsg.Y = y; oMsg.Radius = radius; oMsg.Color = c; oMsg.Name = name; SendMessageExceptOne(server, oMsg, msg.SenderConnection); return(true); }
private static bool OnProcessHappyLogin(NetServer server, int id, NetIncomingMessage msg) { var r = new Msg_HappyPlayerLogin(); r.R(msg); uint uid = HappyGameId; int x = RandomMaker.Next(10); int y = RandomMaker.Next(10); uint sid = (uint)RandomMaker.Next(83); var selfMsg = new Msg_HappyPlayerLoginRsp(); selfMsg.Uid = uid; selfMsg.X = x; selfMsg.Y = y; selfMsg.SpriteId = sid; SendMessage(server, selfMsg, msg.SenderConnection); // 更新链接对应的ID HappyConnMgr.Modify(msg.SenderConnection, uid); var playerPackMsg = new Msg_HappyPlayerPack(); // 为新玩家推送旧玩家信息 var playerList = HappyPlayerMgr.ToList(); var playerPackList = from f in playerList select Tuple.Create <uint, int, int, bool, uint>(f.Key, f.Value.X, f.Value.Y, f.Value.IsAlive, f.Value.SpriteId); playerPackMsg.PlayerPack = playerPackList.ToList(); SendMessage(server, playerPackMsg, msg.SenderConnection); // 为旧玩家推送新玩家信息 var otherMsg = new Msg_HappyOtherPlayerLogin(); otherMsg.Uid = uid; otherMsg.X = x; otherMsg.Y = y; otherMsg.SpriteId = sid; SendMessageExceptOne(server, otherMsg, msg.SenderConnection); // 添加新玩家到玩家管理中 var player = new HappyPlayer(); player.X = x; player.Y = y; player.IsAlive = true; player.SpriteId = sid; HappyPlayerMgr.Add(uid, player); return(true); }
public AccountService( IStoredProcedureService storedProcedure, RandomMaker randomMaker, Cryptograph cryptograph, IAccountProfileService accountProfileService, IAccountDeviceService accountDeviceService, JwtHandler jwtHandler) { _storedProcedure = storedProcedure; _randomMaker = randomMaker; _cryptograph = cryptograph; _accountProfileService = accountProfileService; _accountDeviceService = accountDeviceService; _jwtHandler = jwtHandler; }
public AccountController( IAccountService accountService, IAccountProfileService accountProfileService, RandomMaker randomMaker, Cryptograph cryptograph, IEmailService emailService, ISMSService smsService, IMemoryCache memoryCache) { _accountService = accountService; _accountProfileService = accountProfileService; _randomMaker = randomMaker; _cryptograph = cryptograph; _emailService = emailService; _smsService = smsService; _memoryCache = memoryCache; }
private void OnSelf(MsgBase b) { var selfMsg = (Msg_AgarSelf)b; if (selfMsg.Operat == Msg_AgarSelf.Born) { float x = selfMsg.X; float y = selfMsg.Y; int r = selfMsg.Radius; uint c = selfMsg.Color; DefaultRadius = r; Player = new DefaultUserCircle(new Vector2(x, y), r, c, Name); this.AddChind(Player, PlayerZOrder); if (ScoreShow != null) { ScoreShow.Text = String.Format("Score : {0}", Player.Radius - DefaultRadius); } } else if (selfMsg.Operat == Msg_AgarSelf.GroupUp) { Player.Radius = selfMsg.Radius; if (ScoreShow != null) { ScoreShow.Text = String.Format("Score : {0}", Player.Radius - DefaultRadius); } } else if (selfMsg.Operat == Msg_AgarSelf.Dead) { this.RemoveChild(Player); Player = null; // 玩家重生 string RdName = "TestName-" + RandomMaker.NextString(5); var bornMsg = new Msg_AgarBorn(); bornMsg.UserId = Uid; bornMsg.Name = RdName; Name = RdName; client.SendMessage(bornMsg); } }
private void OnLoginRsp(MsgBase b) { var selfMsg = (Msg_AgarLoginRsp)b; Uid = selfMsg.Uid; int X_Size = selfMsg.Width; int Y_Size = selfMsg.Height; MapSize = new Point(X_Size, Y_Size); string RdName = "TestName-" + RandomMaker.NextString(5); var bornMsg = new Msg_AgarBorn(); bornMsg.UserId = Uid; bornMsg.Name = RdName; Name = RdName; client.SendMessage(bornMsg); }
public PositionSetEditSet getRandomPositionSet(int pointNum) { unchecked { int seed = (int)DateTime.Now.Ticks; this.pointNum = pointNum; LaplaceDistribution distributionX = new LaplaceDistribution(new StandardGenerator(seed++)); distributionX.Alpha = X_Alpha; LaplaceDistribution distributionY = new LaplaceDistribution(new StandardGenerator(seed++)); distributionY.Alpha = Y_Alpha; for (int i = 0; i < clusterPointNum; i++) { distributionX.Mu = RandomMaker.RapidBetween(minMu, maxMu); distributionY.Mu = RandomMaker.RapidBetween(minMu, maxMu); RandomPositionSet randomPositionSet = new RandomPositionSet((int)(pointNum / clusterPointNum), 1000, distributionX, distributionY); positionSetEditSet.AddPositionSet(randomPositionSet); } } return(positionSetEditSet); }
public AccountDeviceServiceUnitTest() { _accountDeviceService = ServiceLocator.Current.GetInstance <IAccountDeviceService>(); _randomMaker = ServiceLocator.Current.GetInstance <RandomMaker>(); }
public static List <IPosition_Connected_Edit> generateRandomPositionSet_Connected(List <IPosition_Connected_Edit> all, int amount1, int amount2, int amount3, double probability1, double probability2, double probability3) { if (all.Count > 0) { IPositionSet_Connected positionSet = new PositionSet_Connected(all); IPositionSet nearSet; IPosition_Connected_Edit near_p; float distance; bool unconnected; IPositionSet_Connected_AdjacencyEdit adjSet; //存储计算好的点数量和概率以备重复使用 int[] amount = new int[3]; //获得周围amount个点来建立连接 double[] probability = new double[3]; //建立连接的概率为probability amount[0] = amount1; amount[1] = amount2; amount[2] = amount3; probability[0] = probability1; probability[1] = probability2; probability[2] = probability3; M2M_NN m2m = new M2M_NN(); m2m.PreProcess(positionSet); //每个节点都随机地与周围的一些节点建立连接 foreach (IPosition_Connected_Edit p in all) { for (int i = 0; i < amount.Length; i++) { nearSet = m2m.ApproximateKNearestNeighbor(p, amount[i]); nearSet.InitToTraverseSet(); while (nearSet.NextPosition()) { if (RandomMaker.RapidBetween01() < probability[i]) { near_p = (IPosition_Connected_Edit)nearSet.GetPosition(); if (near_p != p) { unconnected = true; adjSet = p.GetAdjacencyPositionSetEdit(); adjSet.InitToTraverseSet(); while (adjSet.NextPosition()) { if (adjSet.GetPosition_Connected_Edit() == near_p) { unconnected = false; break; } } if (unconnected) { distance = (float)Math.Sqrt((p.GetX() - near_p.GetX()) * (p.GetX() - near_p.GetX()) + (p.GetY() - near_p.GetY()) * (p.GetY() - near_p.GetY())); adjSet.AddAdjacency(near_p, distance); near_p.GetAdjacencyPositionSetEdit().AddAdjacency(p, distance); } } } } //while } //for } //foreach //清除没有连接的孤立节点 int index = 0; while (index < all.Count) { near_p = all[index]; adjSet = near_p.GetAdjacencyPositionSetEdit(); adjSet.InitToTraverseSet(); if (!adjSet.NextPosition()) { all.Remove(near_p); } else { index++; } } } return(all); }
public IPosition Get() { return(new Position_Point(RandomMaker.RapidBetween(minX, maxX), RandomMaker.RapidBetween(minY, maxY))); }
//产生一个随机点 KD2DPoint getRandomPoint() { //return new KD2DPoint(random.Next(mapWidth - 1), random.Next(mapHeight - 1)); return(new KD2DPoint(RandomMaker.RapidBetween(minX, maxX), RandomMaker.RapidBetween(minY, maxY))); }
//产生一个随机点 KD2DPoint getRandomPoint(int mapWidth, int mapHeight) { //return new KD2DPoint(random.Next(mapWidth - 1), random.Next(mapHeight - 1)); return(new KD2DPoint(RandomMaker.RapidBetween(0.0f, mapWidth - 1.0f), RandomMaker.RapidBetween(0.0f, mapHeight - 1.0f))); }
public AccountServiceUnitTest() { _accountService = ServiceLocator.Current.GetInstance <IAccountService>(); _randomMaker = ServiceLocator.Current.GetInstance <RandomMaker>(); _cryptograph = ServiceLocator.Current.GetInstance <Cryptograph>(); }