public static IAppBuilder UseRequestTracer(this IAppBuilder builder) { var builderProperties = new BuilderProperties(builder.Properties); TraceSource traceSource = builderProperties.Get <TraceSource>("host.TraceSource"); return(builder.UseType <RequestTracer>(traceSource)); }
static bool CheckRequiredStartupData(IDictionary <string, object> properties, IList <string> warnings) { var builderProperties = new BuilderProperties(properties); if (builderProperties.Version == null) { warnings.Add("builder.Properties should contain \"owin.Version\""); } else if (builderProperties.Version != "1.0") { warnings.Add("builder.Properties[\"owin.Version\"] should be \"1.0\""); } if (builderProperties.TraceOutput == null) { warnings.Add("builder.Properties[\"host.TraceOutput\"] should be a TextWriter"); } // TODO: is this still true? //if (!properties.ContainsKey("server.Name")) //{ // warnings.Add("builder.Properties should contain \"server.Name\""); //} //else if (properties.Get<string>("server.Name") == null) //{ // warnings.Add("builder.Properties[\"server.Name\"] should be a string"); //} return(true); }
private string GetBoardBuildingInfo(BuilderProperties props, int shipSize) { string boardBuildingInfo = ""; boardBuildingInfo += DataUtils.Default + $" Current ship: {props.CurrentShipName} \n"; boardBuildingInfo += $" {Separator} \n"; boardBuildingInfo += " Press R to rotate your ship \n"; boardBuildingInfo += $" {Separator}" + Color.Reset + "\n"; return(boardBuildingInfo); }
public void RenderBoard(BuilderProperties props, int row, int col) { string outputString = ""; outputString += GetLevelDescription(props.Mode, props.PlayerName); outputString += GetFieldCoordinatesTemplate(props.Mode); outputString += DrawDefaultField(props, row, col); outputString += GetFieldFooter(props.Mode); outputString += GetBoardBuildingInfo(props, props.CursorLength); outputString += GetBattleMenu(props.MenuOptions, row, props.SelectableRowCount); RenderScreen(outputString); }
public void EventListener(BuilderProperties props, int row, int col) { bool shipPlaced = false; while (!shipPlaced) { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.RightArrow when col + 1 < props.PlayerField.GetLength(1): props.Renderer.RenderBoard(props, row, ++col); break; case ConsoleKey.LeftArrow when col - 1 >= 0: props.Renderer.RenderBoard(props, row, --col); break; case ConsoleKey.UpArrow when row - 1 >= 0: props.Renderer.RenderBoard(props, --row, col); break; case ConsoleKey.DownArrow when row + 1 < props.SelectableRowCount + props.MenuOptions.Count: props.Renderer.RenderBoard(props, ++row, col); break; case ConsoleKey.Enter when row >= props.SelectableRowCount: MenuEnterEvent(props.SelectableRowCount, row); props.Renderer.RenderBoard(props, row, col); break; case ConsoleKey.R: props.Direction = props.Direction == 0 ? 1 : 0; props.Renderer.RenderBoard(props, row, col); break; case ConsoleKey.Enter: if (props.Builder.ShipPlacement(props, row, col)) { shipPlaced = true; } break; case ConsoleKey.M: row = props.SelectableRowCount; props.Renderer.RenderBoard(props, row, 0); break; } } }
public static IAppBuilder UsePassiveValidator(this IAppBuilder builder) { IList<string> warnings = new List<string>(); if (!PassiveValidator.TryValidateProperties(builder.Properties, warnings)) { throw new InvalidOperationException(warnings.Aggregate("builder.Properties are invalid", (a, b) => a + "\r\n" + b)); } if (warnings.Count != 0) { var builderProperties = new BuilderProperties(builder.Properties); var output = builderProperties.TraceOutput ?? Console.Out; output.WriteLine(warnings.Aggregate("builder.Properties are invalid", (a, b) => a + "\r\n" + b)); } return builder.UseType<PassiveValidator>(); }
// Go through all ships from the settings and arrange them public void Start(Settings settings, BuilderProperties props) { props.PlayerFlotilla = new Flotilla(); for (int i = 0; i < settings.ShipCount.Length; i++) // ship count { for (int j = 0; j < settings.ShipCount[i]; j++) // ship size { props.CurrentShipName = props.ShipNames[i]; // ship name props.CursorLength = settings.ShipSettings[i]; // set ship size props.Direction = _lastDirection; // set direction props.Renderer.RenderBoard(props, _lastRow, _lastCol); // render props.EventListener.EventListener(props, _lastRow, _lastCol); } } _manager.SetPlayerField(props.PlayerField); // set field _manager.SetPlayerFlotilla(props.PlayerFlotilla); // set ship }
public static IAppBuilder UsePassiveValidator(this IAppBuilder builder) { IList <string> warnings = new List <string>(); if (!PassiveValidator.TryValidateProperties(builder.Properties, warnings)) { throw new InvalidOperationException(warnings.Aggregate("builder.Properties are invalid", (a, b) => a + "\r\n" + b)); } if (warnings.Count != 0) { var builderProperties = new BuilderProperties(builder.Properties); var output = builderProperties.TraceOutput ?? Console.Out; output.WriteLine(warnings.Aggregate("builder.Properties are invalid", (a, b) => a + "\r\n" + b)); } return(builder.UseType <PassiveValidator>()); }
private void LoadBoardBuilder(Settings settings, GameProperties gameProps, string playerName) { BuilderProperties builderProps = new BuilderProperties { Mode = "Board Building", PlayerFlotilla = playerName == gameProps.Player1Name ? gameProps.Player1Flotilla : gameProps.Player2Flotilla, PlayerField = new string[settings.BattlefieldSize[0], settings.BattlefieldSize[1]], ShipNames = settings.ShipNames, MenuOptions = new List <string> { "Main Menu", "Quit" }, PlayerName = playerName, ShipArrangement = settings.ShipArrangement, SelectableRowCount = settings.BattlefieldSize[0], Builder = new BoardBuilder(this), Renderer = new BuilderRenderer(settings.BattlefieldSize[1]), EventListener = new BuilderEventListener() }; builderProps.Builder.Start(settings, builderProps); }
private string DrawDefaultField(BuilderProperties props, int row, int col) { string fieldString = ""; string[,] fieldTemplate = GetFieldTemplate(props, row, col, props.CursorLength, props.Direction); for (int i = 0; i < props.PlayerField.GetLength(0); i++) { fieldString += DataUtils.Default + (i < 9 ? $" {i + 1} " : $"{i + 1} ") + Color.Reset; for (int j = 0; j < props.PlayerField.GetLength(1); j++) { switch (fieldTemplate[i, j]) { case null: fieldString += DataUtils.FieldCell; break; case "st true": fieldString += DataUtils.ValidTemplateCell; break; case "st false": fieldString += DataUtils.InvalidTemplateCell; break; case "border": fieldString += DataUtils.BorderCell; break; case "ship": fieldString += DataUtils.ShipCell; break; } } fieldString += "\n"; } TemporaryField = fieldTemplate; return(fieldString); }
private string[,] GetFieldTemplate(BuilderProperties props, int row, int col, int cursorLength, int direction) { string[,] currentField = new string[props.PlayerField.GetLength(0), props.PlayerField.GetLength(1)]; Array.Copy(props.PlayerField, currentField, props.PlayerField.Length); int height = props.PlayerField.GetLength(0); int weight = props.PlayerField.GetLength(1); if (row >= height) { return(currentField); } string shipTemplateName; List <string> availableDir = FieldManager.GetAvailableDirections(props.ShipArrangement, currentField, row, col, cursorLength); if (direction == 0 && availableDir.Contains("down") || direction == 1 && availableDir.Contains("right")) { shipTemplateName = "st true"; } else { shipTemplateName = "st false"; } for (int a = 0; a < cursorLength; a++) { if (direction == 0 && col + a < weight && row < height) { currentField[row, col + a] = shipTemplateName; } else if (direction == 1 && row + a < height && col < weight) { currentField[row + a, col] = shipTemplateName; } } return(currentField); }
private void UpdateLeader() { if (BuilderProperties == null) { GroupLeaderView = null; } GroupLeaderView = (ILeaderBuilderPropertyView)BuilderPropertiesItemsControl.BuilderPropertyViews.Value.FirstOrDefault( x => x.Value.PropertyPosition.IsGroupLeader && x.Value.PropertyPosition.BuilderCategory == BuilderCategory && x.Value.PropertyPosition.BuilderGroup == BuilderGroup).Value; var builderViewModel = BuilderProperties?.FirstOrDefault(x => x.BuilderProperty.GetType() == GroupLeaderView?.BuilderProperty); if (builderViewModel != null) { GroupLeaderProperty = builderViewModel.BuilderProperty; builderViewModel.BuilderPropertyView = GroupLeaderView; } }
// Does ship been placed or not public bool ShipPlacement(BuilderProperties props, int row, int col) { List <string> availableDirections = FieldManager.GetAvailableDirections(props.ShipArrangement, props.Renderer.TemporaryField, row, col, props.CursorLength); string directionString = props.Direction == 0 ? "down" : "right"; if (!availableDirections.Contains(directionString)) { return(false); } Ship ship; // Put ship if you can (props.PlayerField, ship) = FieldManager.PutShip(props.ShipArrangement, props.PlayerField, directionString, row, col, props.CursorLength); ship.Name = props.CurrentShipName; props.PlayerFlotilla.AddShip(ship); // Remember last coordinates _lastRow = row; _lastCol = col; _lastDirection = props.Direction; return(true); }
static bool CheckRequiredStartupData(IDictionary<string, object> properties, IList<string> warnings) { var builderProperties = new BuilderProperties(properties); if (builderProperties.Version == null) { warnings.Add("builder.Properties should contain \"owin.Version\""); } else if (builderProperties.Version != "1.0") { warnings.Add("builder.Properties[\"owin.Version\"] should be \"1.0\""); } if (builderProperties.TraceOutput == null) { warnings.Add("builder.Properties[\"host.TraceOutput\"] should be a TextWriter"); } // TODO: is this still true? //if (!properties.ContainsKey("server.Name")) //{ // warnings.Add("builder.Properties should contain \"server.Name\""); //} //else if (properties.Get<string>("server.Name") == null) //{ // warnings.Add("builder.Properties[\"server.Name\"] should be a string"); //} return true; }
public static IAppBuilder UseRequestTracer(this IAppBuilder builder) { var builderProperties = new BuilderProperties(builder.Properties); TraceSource traceSource = builderProperties.Get<TraceSource>("host.TraceSource"); return builder.UseType<RequestTracer>(traceSource); }