private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionState state) { switch (state.CurrentStage) { case MultiplayerSessionConnectionStage.AwaitingReservationCredentials: AuthenticationContext authenticationContext = new AuthenticationContext(userName); multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), authenticationContext); break; case MultiplayerSessionConnectionStage.SessionReserved: multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler; Multiplayer.Main.StartSession(); break; case MultiplayerSessionConnectionStage.SessionReservationRejected: Log.InGame($"Cannot join server: {multiplayerSession.Reservation.ReservationState.ToString()}"); multiplayerSession.Disconnect(); break; case MultiplayerSessionConnectionStage.Disconnected: multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler; break; default: Log.InGame($"Current Stage: {multiplayerSession.CurrentState.CurrentStage}"); break; } }
public static void Main() { var defaultChartGenerator = new DefaultChartGenerator(); var randomColorGenerator = new RandomColorGenerator(); var chartValidator = new ChartValidator(); var jsTemplateWriter = new JSTemplateWriter(@"/Users/iskandarchacra/Desktop/chartjssample/js/main.js"); var chartJsProgram = new SampleChartJsProgram(randomColorGenerator, chartValidator, jsTemplateWriter, defaultChartGenerator); //chartJsProgram.BarChart(); //chartJsProgram.MultiDatasetBarChart(); //chartJsProgram.PieChart(); NO X Y AXES //chartJsProgram.MultiDatasetPieChart(); //chartJsProgram.LineChart(); //chartJsProgram.MultiDatasetLineChart(); //chartJsProgram.RadarChart(); NO X Y AXES chartJsProgram.MultiDatasetRadarChart(); //chartJsProgram.BubbleChart(); //chartJsProgram.MultiDatasetBubbleChart(); //chartJsProgram.DoughnutChart(); NO X Y AXES //chartJsProgram.MultiDatasetDoughnutChart(); //chartJsProgram.HorizontalBarChart(); //chartJsProgram.MultiDatasetHorizontalBarChart(); }
public void ShouldBeAbleToRetrieveUpdatedPreferencesForAnExistingIpAddress() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color newColor = RandomColorGenerator.GenerateColor().ToUnity(); PlayerPreference newPlayerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, newColor); //When playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference); playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, newPlayerPreference); PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.RedAdditive.Should().Be(newColor.r); result.GreenAdditive.Should().Be(newColor.g); result.BlueAdditive.Should().Be(newColor.b); }
private void RenderJoinServerDialog(int windowId) { Event e = Event.current; if (e.isKey) { switch (e.keyCode) { case KeyCode.Return: multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), new AuthenticationContext(username)); break; case KeyCode.Escape: StopMultiplayerClient(); break; } } GUISkinUtils.RenderWithSkin(GetGUISkin("menus.server", 80), () => { using (new GUILayout.VerticalScope("Box")) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Username:"******"usernameField"); username = GUILayout.TextField(username); } if (GUILayout.Button("Join")) { multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), new AuthenticationContext(username)); } if (GUILayout.Button("Cancel")) { joiningServer = false; StopMultiplayerClient(); } } }); if (shouldFocus) { GUI.FocusControl("usernameField"); shouldFocus = false; } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); RandomColorGenerator cube = (RandomColorGenerator)target; GUILayout.BeginHorizontal(); if (GUILayout.Button("Generate Color")) { cube.GenerateColor(); } if (GUILayout.Button("Reset Color")) { cube.Reset(); } GUILayout.EndHorizontal(); }
private User AddUser(AddUserNetworkData addUserNetworkData) { var user = new User { AccountId = addUserNetworkData.AccountId, Name = addUserNetworkData.UserName, CurrentState = addUserNetworkData.State, Color = RandomColorGenerator.GetColor(), IsSelf = false, ID = addUserNetworkData.Id }; userList.Add(user); chatComponent.AddSystemMessage(String.Format(Utility.Language["UserEnterRoom"], user.Name)); return(user); }
internal ReturnPointData GetPoint(int dataPointId) { var point = db.T_DataPoint.Where(x => x.Id.Equals(dataPointId)).FirstOrDefault(); // var pointAndStrokeColor = RandomColorGenerator.GetRandomColor(); var pointAndStrokeColorRGBA = RandomColorGenerator.GetRandomColorRGBA(); return(new ReturnPointData { DataPointId = point.Id, StrokeColor = pointAndStrokeColorRGBA, PointColor = pointAndStrokeColorRGBA, Label = point.Name, PointHighlightFill = "#fff", PointHighlightStroke = "rgba(151,187,205,1)", PointStrokeColor = "#fff", FillColor = RandomColorGenerator.GetRandomColorRGBA() }); }
private void ConnectionStateChangedHandler(IMultiplayerSessionConnectionState state) { switch (state.CurrentStage) { case MultiplayerSessionConnectionStage.AwaitingReservationCredentials: multiplayerSession.RequestSessionReservation(new PlayerSettings(RandomColorGenerator.GenerateColor()), new AuthenticationContext(playerName, Steamworks.SteamUser.GetSteamID().m_SteamID)); break; case MultiplayerSessionConnectionStage.SessionReserved: multiplayerSession.JoinSession(); multiplayerSession.ConnectionStateChanged -= ConnectionStateChangedHandler; Log.InGame("SessionJoined to server"); break; case MultiplayerSessionConnectionStage.SessionReservationRejected: Log.InGame("Unable to connect to server"); multiplayerSession.ConnectionStateChanged -= ConnectionStateChangedHandler; break; } }
public PlayerPreference GetPreference(string ipAddress) { Validate.NotNull(ipAddress); if (state.Preferences.TryGetValue(ipAddress, out PlayerPreference preference)) { return(preference.Clone()); } if (state.LastSetPlayerPreference != null) { return(state.LastSetPlayerPreference.Clone()); } Color playerColor = RandomColorGenerator.GenerateColor().ToUnity(); PlayerPreference defaultPlayerPreference = new PlayerPreference(playerColor); state.LastSetPlayerPreference = defaultPlayerPreference; return(defaultPlayerPreference); }
//---------------------------------------------------------------------- public RandomColorTable(int numberOfColors) : base(numberOfColors) { ColorGenerator = new RandomColorGenerator(0); Seed = 0; CreateRandomColors(); }
private void ChangeBackColorOfEveryControlButton_Click(object sender, EventArgs e) { this.BackColor = RandomColorGenerator.Generate24BytesColor(); // TODO: дописать логику для изменения цвета BackColor для всех элементов управления на форме }
public RegularTetrahedron() { var random = new Random(); random.Next(1000); const float l = 0.20f; var vertices = new[] { new DcelVertex(new ColouredVertex(new Vector3(0, 0, 0), RandomColorGenerator.NextColor())), new DcelVertex(new ColouredVertex(new Vector3(l, 0, 0), RandomColorGenerator.NextColor())), new DcelVertex(new ColouredVertex(new Vector3(l / 2f, 0, -l), RandomColorGenerator.NextColor())), new DcelVertex(new ColouredVertex(new Vector3((1.5f * l) / 3, l, -l / 3f), RandomColorGenerator.NextColor())) }; var edges = Enumerable.Range(0, 12).Select(x => new DcelHalfEdge()).ToArray(); _faces = Enumerable.Range(0, 4).Select(x => new DcelFace()).ToArray(); //f0 _faces[0].HalfEdge = edges[0]; //e0 edges[0].IncidentFace = _faces[0]; edges[0].TargetVertex = vertices[1]; edges[0].Next = edges[1]; edges[0].Previous = edges[2]; edges[0].Twin = edges[3]; //e1 edges[1].IncidentFace = _faces[0]; edges[1].TargetVertex = vertices[2]; edges[1].Next = edges[2]; edges[1].Previous = edges[0]; edges[1].Twin = edges[6]; //e2 edges[2].IncidentFace = _faces[0]; edges[2].TargetVertex = vertices[0]; edges[2].Next = edges[0]; edges[2].Previous = edges[1]; edges[2].Twin = edges[9]; //f1 _faces[1].HalfEdge = edges[3]; //e3 edges[3].IncidentFace = _faces[1]; edges[3].TargetVertex = vertices[0]; edges[3].Next = edges[4]; edges[3].Previous = edges[5]; edges[3].Twin = edges[0]; //e4 edges[4].IncidentFace = _faces[1]; edges[4].TargetVertex = vertices[3]; edges[4].Next = edges[5]; edges[4].Previous = edges[3]; edges[4].Twin = edges[11]; //e5 edges[5].IncidentFace = _faces[1]; edges[5].TargetVertex = vertices[1]; edges[5].Next = edges[3]; edges[5].Previous = edges[4]; edges[5].Twin = edges[7]; //f2 _faces[2].HalfEdge = edges[6]; //e6 edges[6].IncidentFace = _faces[2]; edges[6].TargetVertex = vertices[1]; edges[6].Next = edges[7]; edges[6].Previous = edges[8]; edges[6].Twin = edges[1]; //e7 edges[7].IncidentFace = _faces[2]; edges[7].TargetVertex = vertices[3]; edges[7].Next = edges[8]; edges[7].Previous = edges[6]; edges[7].Twin = edges[5]; //e8 edges[8].IncidentFace = _faces[2]; edges[8].TargetVertex = vertices[2]; edges[8].Next = edges[6]; edges[8].Previous = edges[7]; edges[8].Twin = edges[10]; //f3 _faces[3].HalfEdge = edges[9]; //e9 edges[9].IncidentFace = _faces[3]; edges[9].TargetVertex = vertices[2]; edges[9].Next = edges[10]; edges[9].Previous = edges[11]; edges[9].Twin = edges[2]; //e10 edges[10].IncidentFace = _faces[3]; edges[10].TargetVertex = vertices[3]; edges[10].Next = edges[11]; edges[10].Previous = edges[9]; edges[10].Twin = edges[8]; //e11 edges[11].IncidentFace = _faces[3]; edges[11].TargetVertex = vertices[0]; edges[11].Next = edges[9]; edges[11].Previous = edges[10]; edges[11].Twin = edges[4]; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { bool runIt = false; if (!DA.GetData("Run", ref runIt)) { return; } // Setup variables List <string> paths = new List <string>(); if (!DA.GetDataList(1, paths)) { return; } List <string> outPaths = new List <string>(); if (!DA.GetDataList(4, outPaths)) { return; } if (paths.Count != outPaths.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Filepath counts do not match, please check your inputs"); } // Setup default inputs List <double> Pt1 = new List <double>(); DA.GetDataList(2, Pt1); if (Pt1.Count == 0) { Pt1.Add(0); Pt1.Add(0); } List <double> Pt2 = new List <double>(); DA.GetDataList(3, Pt2); if (Pt2.Count == 0) { Pt2.Add(0); Pt2.Add(0); } // Enumerate through shapefile paths for (int i = 0; i < paths.Count; i++) { // Get file patgs string path = paths[i]; string outPath = outPaths[i]; // Open shapefile + data Shapefile shp = Shapefile.OpenFile(path); string prjStr = shp.ProjectionString; // Find extents & centre of shapefile double minLng = shp.Extent.MinX; double minLat = shp.Extent.MinY; double maxLng = shp.Extent.MaxX; double maxLat = shp.Extent.MaxY; double centreLng = shp.Extent.Center.X; double centreLat = shp.Extent.Center.Y; // Reorder pts to ensure max and min are valid inputs List <double> Lats = new List <double>(); List <double> Lngs = new List <double>(); Lats.Add(Pt1[0]); Lats.Add(Pt2[0]); Lngs.Add(Pt1[1]); Lngs.Add(Pt2[1]); Lats.Sort(); Lngs.Sort(); PointLatLng minLatLng = new PointLatLng(Lats[0], Lngs[0]); PointLatLng maxLatLng = new PointLatLng(Lats[1], Lngs[1]); // Convert shp XY vals to Lat Lng and pass into Form properties helpers_Conversions.UTMToLatLongDSP(shp.Extent.MinX, shp.Extent.MinY, prjStr, out minLat, out minLng); helpers_Conversions.UTMToLatLongDSP(shp.Extent.MaxX, shp.Extent.MaxY, prjStr, out maxLat, out maxLng); PointLatLng minExtent = new PointLatLng(minLat, minLng); PointLatLng maxExtent = new PointLatLng(maxLat, maxLng); List <PointLatLng> uiCrop = new List <PointLatLng>(); // Apply random colour Color color = RandomColorGenerator.RandomColor(); // Create crop properties + increment CropProperties crop = new CropProperties(minExtent, maxExtent, minLatLng, maxLatLng, uiCrop, shp, outPath, color); // Limit properties added to persistent data if (properties.Count < paths.Count) { properties.Add(crop); } else if (properties.Count > paths.Count) { properties.Clear(); properties.Add(crop); } else if (properties.Count == paths.Count) { properties[i].shp = shp; properties[i].path = crop.path; properties[i].color = crop.color; properties[i].minExtent = crop.minExtent; properties[i].maxExtent = crop.maxExtent; // If there is GH input: replace crop if (Pt2[0] != 0 && Pt1[0] != 0) { properties[i].minCrop = crop.minCrop; properties[i].maxCrop = crop.maxCrop; } } } // Define extents CropProperties mainCrop = properties[0]; if (extents.Count != 2) { Point3d min = new Point3d(mainCrop.minCrop.Lng, mainCrop.minCrop.Lat, 0); Point3d max = new Point3d(mainCrop.maxCrop.Lng, mainCrop.maxCrop.Lat, 0); extents.Add(min); extents.Add(max); } // Button press show data if (runIt) { // Display form helpers_UI.DisplayForm(properties); } // Set output Point3d newmin = new Point3d(mainCrop.minCrop.Lng, mainCrop.minCrop.Lat, 0); Point3d newmax = new Point3d(mainCrop.maxCrop.Lng, mainCrop.maxCrop.Lat, 0); extents.Clear(); extents.Add(newmin); extents.Add(newmax); DA.SetData(0, extents[0]); DA.SetData(1, extents[1]); }
public override bool Load() { PPDFramework.Web.WebModInfo[] webMods = null; Action[] actions = { () => { webMods = PPDFramework.Web.WebManager.Instance.GetMods(); }, PPDScoreManager.Manager.Initialize, }; Parallel.ForEach(actions, (action) => action()); allowedModList = new AllowedModList { WebMods = webMods }; logger = new Logger(String.Format("{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"))); Sound.AddSound(notifySoundPath); version = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(this.GetType()).Location).FileVersion; userList = new ChangableList <User>(); userList.ItemChanged += userList_ItemChanged; movieManager = new MovieManager(device, GameHost); movieManager.MovieChanged += MovieManager_MovieChanged; movieManager.MovieChangeFailed += MovieManager_MovieChangeFailed; clientHandledData = new Queue <NetworkData>(); selfUser = new User { Name = PPDFramework.Web.WebManager.Instance.CurrentUserName, AccountId = PPDFramework.Web.WebManager.Instance.CurrentAccountId, CurrentState = UserState.NotReady, Color = RandomColorGenerator.GetColor(), IsSelf = true, IsHost = (bool)this.Param["AsHost"] }; this.AddChild(gameResultComponent = new GameResultComponent(device, GameHost, ResourceManager, Sound)); this.AddChild(leftMenu = new LeftMenu(device, GameHost, ResourceManager, Sound, movieManager, selfUser, userList, allowedModList)); leftMenu.SongSelected += leftMenu_SongSelected; leftMenu.ShowResult += leftMenu_ShowResult; leftMenu.UpdateScoreDB += leftMenu_UpdateScoreDB; leftMenu.RuleChanged += leftMenu_RuleChanged; leftMenu.TryToPlayGame += leftMenu_TryToPlayGame; leftMenu.ChangeLeader += leftMenu_ChangeLeader; leftMenu.KickUser += leftMenu_KickUser; this.AddChild(textBox = new DxTextBox(device, GameHost, ResourceManager)); this.AddChild((chatComponent = new ChatComponent(device, ResourceManager, GameHost) { Position = new SharpDX.Vector2(430, 0) })); this.AddChild(userListComponent = new UserListComponent(device, ResourceManager) { Position = new SharpDX.Vector2(10, 10) }); PictureObject bottom; this.AddChild(bottom = new PictureObject(device, ResourceManager, Utility.Path.Combine("menu_bottom.png")) { Position = new SharpDX.Vector2(0, 421) }); bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_triangle.png")) { Position = new SharpDX.Vector2(7, 7) }); bottom.AddChild(new TextureString(device, Utility.Language["Menu"], 16, PPDColors.White) { Position = new SharpDX.Vector2(30, 5) }); bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_circle.png")) { Position = new SharpDX.Vector2(157, 7) }); bottom.AddChild(stateString = new TextureString(device, Utility.Language["ChangeReadyState"], 16, PPDColors.White) { Position = new SharpDX.Vector2(180, 5) }); this.AddChild((bgd = new BackGroundDisplay(device, ResourceManager, "skins\\PPDMulti_BackGround.xml", "Menu"))); focusManager = new FocusManager(); focusManager.Focus(chatComponent); userList.Add(selfUser); chatComponent.Inputed += chatComponent_Inputed; textBox.LostFocused += textBox_LostFocused; leftMenu.Closed += leftMenu_Closed; if (selfUser.IsHost) { WebManager webManager = null; if (this.Param.ContainsKey("WebManager")) { webManager = this.Param["WebManager"] as WebManager; } RoomInfo roomInfo = null; if (this.Param.ContainsKey("RoomInfo")) { roomInfo = this.Param["RoomInfo"] as RoomInfo; } server = new PPDServer((int)Param["Port"], webManager, roomInfo, GameHost); server.FailedToCreateRoom += server_FailedToCreateRoom; client = new Client { Address = "127.0.0.1", Port = (int)Param["Port"] }; timer = new Timer(state => { server.Update(); }, null, 0, 1); } else { client = new Client { Address = (string)Param["IP"], Port = (int)Param["Port"] }; } client.Closed += client_Closed; client.Read += client_Read; byteReader = new TcpByteReader(); byteReader.ByteReaded += TcpByteReader_ByteReaded; if (server != null) { server.Start(); } client.Start(); if (client.HasConnection) { // send login data client.Write(MessagePackSerializer.Serialize(new AddUserNetworkData { UserName = selfUser.Name, AccountId = selfUser.AccountId, State = selfUser.CurrentState, Version = version })); } else { chatComponent.AddSystemMessage(Utility.Language["CannotConnectToHost"]); } // load SongInformation.All.ToArray(); return(true); }
public void SetPreferenceShouldThrowExceptionWhenGivenANullIpAddress() { //Arrange PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); //Act Action action = () => playerPreferenceManager.SetPreference(null, playerPreference); //Assert action.ShouldThrow <ArgumentNullException>(); }
public void ShouldBeAbleToRetrieveANewPreferenceEntry() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor()); Color preferredColor = playerPreference.PreferredColor(); //When playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference); PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(TestConstants.TEST_PLAYER_NAME); result.RedAdditive.Should().Be(preferredColor.r); result.GreenAdditive.Should().Be(preferredColor.g); result.BlueAdditive.Should().Be(preferredColor.b); }
public void ShouldGetTheLastSetPlayerPreferenceWhenJoiningANewServer() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference firstPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string firstIpAddress = "127.0.0.1"; playerPreferenceManager.SetPreference(firstIpAddress, firstPreference); PlayerPreference secondPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string secondIpAddress = "123.456.789.321"; playerPreferenceManager.SetPreference(secondIpAddress, secondPreference); PlayerPreference thirdPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color expectedColor = thirdPreference.PreferredColor(); string thirdIpAddress = "000.000.000.000"; playerPreferenceManager.SetPreference(thirdIpAddress, thirdPreference); //When PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(thirdPreference.PlayerName); result.RedAdditive.Should().Be(expectedColor.r); result.GreenAdditive.Should().Be(expectedColor.g); result.BlueAdditive.Should().Be(expectedColor.b); }
protected override void Initialize() { base.Initialize(); colorGenerator = GetComponent <RandomColorGenerator> (); UpdateColors(); }