private void ShowText(int fromTick, string text, TextColour colour, int x, int y) { if (TickPassed(fromTick)) { _display.WriteLine(text, colour, x, y); } }
public void ShowUp(float count, TextColour counterColor = TextColour.RED, float duration = 5.0f) { InitialShowUp(duration); moveUp = true; counterText.color = colorsAvailable[(int)counterColor]; counterText.text = count.ToString(); }
public XmlNode ToXml(XmlNode parent) { XmlNode result = parent.OwnerDocument.CreateNode(XmlNodeType.Element, "BalloonStyle", string.Empty); if (_id.Length > 0) { XmlAttribute attId = result.OwnerDocument.CreateAttribute("id"); attId.Value = _id; result.Attributes.Append(attId); } if (null != BgColour) { XmlNode nodColour = BgColour.ToXml(result); result.AppendChild(nodColour); } if (null != TextColour) { XmlNode nodTextColour = TextColour.ToXml(result); result.AppendChild(nodTextColour); } XmlNode nodText = result.OwnerDocument.CreateNode(XmlNodeType.Element, "text", string.Empty); nodText.InnerText = Text; result.AppendChild(nodText); XmlNode nodDisplayMode = result.OwnerDocument.CreateNode(XmlNodeType.Element, "displayMode", string.Empty); nodDisplayMode.InnerText = (Visible ? "default" : "hide"); result.AppendChild(nodDisplayMode); return(result); }
public void WriteLine(string text, TextColour colour, int x, int y) { foreach (var c in text) { Update(_spriteSet.Character(colour, c), x, y); x++; } }
private static TextColour GetInstance(string cssClass) { if (!_instances.ContainsKey(cssClass)) { _instances[cssClass] = new TextColour(cssClass); } return(_instances[cssClass]); }
private void DrawGhostAfter(int fromTick, GhostColour colour, int y, TextColour textColour, string text1, string text2) { if (_attractTick >= fromTick) { _display.AddSprite(_spriteSet.Ghost(colour, Direction.Right, false), new Location(4.5m, y)); } ShowText(fromTick + 60, text1, textColour, 7, y); ShowText(fromTick + 90, text2, textColour, 18, y); }
/// <summary> /// Attempts to save the lottery number to the results list /// </summary> /// <param name="number">The number to save</param> /// <param name="textColour">The colour associated with the number</param> /// <returns>True or false</returns> public bool TrySaveLotteryNumber(int number, TextColour textColour) { if (!this.IsNumberAlreadyStored(number)) { this.LotteryNumbers.Add(number, textColour); return(true); } return(false); }
/// <summary> /// Converts from <see cref="TextColour"/> to <see cref="ConsoleColor"/> /// </summary> /// <param name="textColour">The <see cref="TextColour"/> to convert</param> /// <returns>A <see cref="ConsoleColor"/></returns> internal static ConsoleColor ConvertTextColourToConsoleColour(TextColour textColour) { return(textColour switch { TextColour.Grey => ConsoleColor.DarkGray, TextColour.Blue => ConsoleColor.Blue, TextColour.Pink => ConsoleColor.Magenta, TextColour.Green => ConsoleColor.Green, TextColour.Yellow => ConsoleColor.Yellow, _ => throw new InvalidCastException($"Unexpected {nameof(TextColour)} was passed to {nameof(ConvertTextColourToConsoleColour)} - value passed was {textColour}"), });
/// <summary> /// Text character upper case letters numbers etc. /// </summary> /// <param name="character"></param> /// <returns></returns> public SpriteSource Character(TextColour colour, char character) { if (_characters.ContainsKey(colour)) { if (_characters[colour].ContainsKey(character)) { return(_characters[colour][character]); } } return(_blueMapPieces[MapDisplayPiece.Blank]); }
/// <summary> /// The entry point of the application /// </summary> static void Main() { // Configure simple configuration var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) .Build(); // Setup Inversion of Control/ DI var serviceProvider = new ServiceCollection() .AddSingleton <ILotteryNumberGenerator, LotteryNumberGenerator>() .BuildServiceProvider(); // Set default required lottery numbers incase config is not present int requiredNumberOfLotteryNumbers = 6; // Allow override of number of required lottery numbers so that a rebuild/retest of application is not required if (configuration["requiredNumberOfLotteryNumbers"] != null) { int.TryParse(configuration["requiredNumberOfLotteryNumbers"], out requiredNumberOfLotteryNumbers); } try { // The below could be called also with no param to get default functionaility of 6 numbers also GeneratedLotteryNumbersResult generatedLotteryNumbers = serviceProvider.GetService <ILotteryNumberGenerator>().GenerateLotteryNumbers(requiredNumberOfLotteryNumbers); if (generatedLotteryNumbers.IsSuccess) { foreach (var lotteryNumber in generatedLotteryNumbers.LotteryNumbers) { TextColour textColour = lotteryNumber.Value; ConsoleColor consoleColour = Converters.ConvertTextColourToConsoleColour(textColour); Console.ForegroundColor = consoleColour; Console.WriteLine(lotteryNumber.Key); } Console.ForegroundColor = ConsoleColor.White; } else { WriteErrorMessage(generatedLotteryNumbers.ErrorMessage); } } catch (Exception ex) { WriteErrorMessage(ex.Message); } Console.WriteLine("Press <Return> to continue"); Console.ReadLine(); }
public void DetermineTextColour_BoundaryTests_ExpectCorrectColourReturned(int lotteryNumber, TextColour expectedTextColour) { // Arrange MethodInfo determineTextColourMethodInfo = this.objectUnderTest.GetType().GetMethod("DetermineTextColour", BindingFlags.Static | BindingFlags.NonPublic); if (determineTextColourMethodInfo == null) { throw new Exception($"Unable to find method DetermineTextColour on {objectUnderTest.GetType().Name}"); } // Act TextColour testResult = (TextColour)determineTextColourMethodInfo.Invoke(objectUnderTest, new object[] { lotteryNumber }); // Assert Assert.Equal(expectedTextColour, testResult); }
/// <summary> /// Generates a sequence of the required count of numbers, unique (in the sequence) lottery numbers with an associated required colour /// </summary> /// <param name="numbersToCreate">The number of lottery numbers to create</param> /// <returns>A <see cref="GeneratedLotteryNumbersResult"/></returns> public GeneratedLotteryNumbersResult GenerateLotteryNumbers(int numbersToCreate) { GeneratedLotteryNumbersResult lotteryNumbersResult = new GeneratedLotteryNumbersResult(numbersToCreate); Random rand = new Random(); // Loop while we haven't built up the required number of lottery numbers yet while (!lotteryNumbersResult.HasRequiredNumbersCount()) { int randomNumber = rand.Next(LotteryStartNumber, LotteryEndNumber); TextColour requiredTextColour = DetermineTextColour(randomNumber); if (requiredTextColour != TextColour.Unknown) { // Try adding the number, if the number is not unique the loop will continue and generate the next number to try lotteryNumbersResult.TrySaveLotteryNumber(randomNumber, requiredTextColour); } else { // This failure scenario is not testable as when the TextColour enum is correct & StartNUmber and EndNUmber are in synch with it // it will never return back TextColour.Unknown. This untestability is somewhat mitigated by the fact that the testing of the testing of the // DetermineTextColour method with boundary testing to ensure it only ever returns back valid Colours lotteryNumbersResult.IsSuccess = false; lotteryNumbersResult.ErrorMessage = $"Could not determine required colour for number {randomNumber}"; } } // The following is belt and braces approach to ensure we have valid lottery numbers before returning // again a failure in this scenario is impossible to unit test as there is code above that ensures the count is correct and that the // numbers are unique. This is mitigated by the fact that the AreLotterNumbersValid is tested seperately if (!lotteryNumbersResult.AreLotteryNumbersValid()) { lotteryNumbersResult.IsSuccess = false; lotteryNumbersResult.ErrorMessage = $"Numbers generated were not each unique, values generated were {string.Join(",", lotteryNumbersResult.LotteryNumbers.Keys)}"; } lotteryNumbersResult.IsSuccess = true; return(lotteryNumbersResult); }
public void ShowUp(string text, TextColour counterColor = TextColour.RED, float duration = 5.0f) { InitialShowUp(duration); counterText.color = colorsAvailable[(int)counterColor]; counterText.text = text; }
public void ConvertTextColourToConsoleColour_WithValidColour_ExpectCorrectColourReturned(TextColour textColour, ConsoleColor expectedColour) { // Arrange // Act // Assert Assert.Equal(expectedColour, Converters.ConvertTextColourToConsoleColour(textColour)); }
public SystemGroup(TextColour Col) { Action = System.COLOUR; Colour = Col; }