public void StartGame() //основа { if (!model.workingGame && model.workingServer) { model.workingGame = true; ControllersS.cMap.createdZone(); for (int i = 0; i < model.ListUsers.Count; i++) { if (model.ListUsers[i] != null) { GetZoneStartInfo nextZoneInfo = new GetZoneStartInfo(); nextZoneInfo.nextZone = model.Map.NextZone; GetPrevZoneInfo prevZoneInfo = new GetPrevZoneInfo(); prevZoneInfo.prevZone = model.Map.PrevZone; CTransfers.Writing(nextZoneInfo, model.ListNs[i]); // Инфа о стартовой зоне CTransfers.Writing(prevZoneInfo, model.ListNs[i]); } } ControllersS.cPlay.timerZone = new System.Timers.Timer(); ControllersS.cPlay.timerZone.Interval = 1000; ControllersS.cPlay.timerZone.Elapsed += (x, y) => { ControllersS.cPlay.timerZone_Tick(); }; ControllersS.cPlay.timerZone.Start(); ControllersS.cPlay.timerUsersInZone = new System.Timers.Timer(); ControllersS.cPlay.timerUsersInZone.Interval = 1000; ControllersS.cPlay.timerUsersInZone.Elapsed += (x, y) => { ControllersS.cPlay.timerUsersInZone_Tick(); }; ControllersS.cPlay.timerUsersInZone.Start(); StartGameEvent("Игра идёт"); } }
public void timerZone_Tick() //игра { if (model.Map.NextZone.TimeTocompression > 0) { GetZoneCompression Compress = new GetZoneCompression(); Compress.Count = model.Map.NextZone.TimeTocompression; foreach (NetworkStream n in model.ListNs) { CTransfers.Writing(Compress, n); } model.Map.NextZone.TimeTocompression -= 1; } else { GetZoneCompression Compress = new GetZoneCompression(); Compress.Count = model.Map.NextZone.TimeTocompression; foreach (NetworkStream n in model.ListNs) { CTransfers.Writing(Compress, n); } timerZone.Stop(); double x = model.Map.PrevZone.ZoneCenterCoordinates.X, y = model.Map.PrevZone.ZoneCenterCoordinates.Y, radius = model.Map.PrevZone.ZoneRadius;; double koef = Math.Sqrt(Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X, 2) + Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y, 2)) / 750; double k = Math.Sqrt(Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X, 2) + Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y, 2)) / koef; double speedX = (model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X) / k; double speedY = (model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y) / k; double speedRadius = (double)(model.Map.PrevZone.ZoneRadius - model.Map.NextZone.ZoneRadius) / 750; while (model.Map.PrevZone.ZoneRadius > model.Map.NextZone.ZoneRadius && model.workingGame) { x -= speedX; model.Map.PrevZone.ZoneCenterCoordinateX = (int)x; y -= speedY; model.Map.PrevZone.ZoneCenterCoordinateY = (int)y; radius -= speedRadius; model.Map.PrevZone.ZoneRadius = (int)radius; for (int i = 0; i < model.ListUsers.Count; i++) { if (model.ListUsers[i] != null && model.ListNs[i].CanWrite) { GetPrevZoneInfo prevZoneInfo = new GetPrevZoneInfo(); prevZoneInfo.prevZone = model.Map.PrevZone; CTransfers.Writing(prevZoneInfo, model.ListNs[i]); } } Thread.Sleep(40); } if (model.workingGame) { model.Map.PrevZone = model.Map.NextZone; model.Map.NextZone = new Zone(); model.Map.NextZone.ZoneRadius = (int)model.Map.PrevZone.ZoneRadius / 2; model.Map.NextZone.NewCenterZone(model.Map.MapBorders, model.Map.PrevZone.ZoneCenterCoordinates, model.Map.PrevZone.ZoneRadius); //не страдает ли тут MVC? for (int i = 0; i < model.ListUsers.Count; i++) { if (model.ListUsers[i] != null) { GetZoneStartInfo nextZoneInfo = new GetZoneStartInfo(); nextZoneInfo.nextZone = model.Map.NextZone; CTransfers.Writing(nextZoneInfo, model.ListNs[i]); } } model.Map.NextZone.TimeTocompression = 60; model.DamageZone += 2; timerZone.Start(); } } }