/// <summary> /// Zeichnet den Superman an der Postion die übergeben wird /// </summary> private void DrawSupermanAt(int x, int y, ConsoleAttribute color) { for (int i = 0; i < 3; i++) { gr.WriteToBuffer(x, y + i, Superman.superman[i], color); } }
/// <summary> /// One-time initialization for property info dictionary /// </summary> private void InitializePropertyInfoDictionary() { propertyInfoDictionary = new Dictionary <string, PropertyInfo>(); typeList.ForEach(type => { type.GetProperties(BindingFlagsConstantInternal.allBindingFlags).ToList().ForEach(property => { ConsoleAttribute attribute = property.GetCustomAttribute <ConsoleAttribute>(); if (attribute == null) { return; } string name = attribute.name; if (name == null || !name.IsMatch(RegexConstant.alphanumericOrUnderscore)) { StringConstantInternal.propertyUnsupportedNameError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } if (fieldInfoDictionary != null && fieldInfoDictionary.ContainsKey(name) || propertyInfoDictionary.ContainsKey(name) || methodInfoDictionary != null && methodInfoDictionary.ContainsKey(name)) { StringConstantInternal.propertyDuplicatedError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } propertyInfoDictionary[name] = property; }); }); }
public static void RegisterAssembly(Assembly assembly) { Type[] types = assembly.GetTypes(); foreach (Type t in types) { FieldInfo[] fieldInfos = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); foreach (FieldInfo field in fieldInfos) { object[] attributes = field.GetCustomAttributes(typeof(ConsoleAttribute), false); for (int i = 0; i < attributes.Length; i++) { if (attributes[i] is ConsoleAttribute) { ConsoleAttribute attribute = attributes[i] as ConsoleAttribute; bool containsField = false; foreach (FieldInvocation fieldCheck in fields) { if (fieldCheck.Name == attribute.InvocationName) { containsField = true; break; } } if (!containsField) { fields.Add(new FieldInvocation(attribute.InvocationName, attribute.Description, field)); } } } } MethodInfo[] methodInfos = t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); foreach (MethodInfo method in methodInfos) { object[] attributes = method.GetCustomAttributes(typeof(ConsoleAttribute), false); for (int i = 0; i < attributes.Length; i++) { if (attributes[i] is ConsoleAttribute) { ConsoleAttribute attribute = attributes[i] as ConsoleAttribute; bool containsMethod = false; foreach (MethodInvocation methodCheck in methods) { if (methodCheck.Name == attribute.InvocationName) { containsMethod = true; break; } } if (!containsMethod) { methods.Add(new MethodInvocation(attribute.InvocationName, attribute.Description, attribute.Usage, method)); } } } } } }
private ConsoleCommand CreateConsoleCommand(ConsoleAttribute attribute, ConsoleCommandHandler handler) { ConsoleCommand scommand = new ConsoleCommand(); if (attribute != null) { scommand.description = attribute.Description; scommand.syntax = attribute.Syntax; scommand.mingmlevel = attribute.GmLevel; scommand.handler = handler; } return(scommand); }
public bool WriteToBuffer(int x, int y, char c, ConsoleAttribute attribute = ConsoleAttribute.FG_WHITE) { // if out of bounds if (y * this.CONSOLE_WIDTH + x + 1 >= buffer.Length) { return(false); } buffer[(y * this.CONSOLE_WIDTH) + x].Char.UnicodeChar = c; buffer[(y * this.CONSOLE_WIDTH) + x].Attributes = (short)attribute; currentIndex = (y * this.CONSOLE_WIDTH) + x + 1; return(true); }
public bool WriteToBuffer(char c, ConsoleAttribute attribute = ConsoleAttribute.FG_WHITE) { // if out of bounds if (currentIndex + 1 >= buffer.Length) { return(false); } buffer[currentIndex].Char.UnicodeChar = c; buffer[currentIndex].Attributes = (short)attribute; currentIndex++; return(true); }
public bool WriteToBuffer(string str, ConsoleAttribute attribute = ConsoleAttribute.FG_WHITE) { // if out of bounds if (currentIndex + str.Length >= buffer.Length) { return(false); } for (int i = 0; i < str.Length; i++) { buffer[currentIndex + i].Char.UnicodeChar = str[i]; buffer[currentIndex + i].Attributes = (short)attribute; } currentIndex += str.Length; return(true); }
public bool WriteToBuffer(int x, int y, char[] arr, ConsoleAttribute attribute = ConsoleAttribute.FG_WHITE) { // if out of bounds if (y * this.CONSOLE_WIDTH + x + arr.Length >= buffer.Length) { return(false); } for (int i = 0; i < arr.Length; i++) { buffer[y * this.CONSOLE_WIDTH + x + i].Char.UnicodeChar = arr[i]; buffer[y * this.CONSOLE_WIDTH + x + i].Attributes = (short)attribute; } currentIndex = (y * this.CONSOLE_WIDTH) + x + arr.Length; return(true); }
public void Draw() { foreach (var powerup in listPowerup) { char powerUpChar = ' '; ConsoleAttribute powerupColor = ConsoleAttribute.FG_WHITE; switch (powerup.Item1) { case Powerup.Health: powerUpChar = PowerupChars.Health; powerupColor = PowerupColors.Health; break; case Powerup.Points: powerUpChar = PowerupChars.Points; powerupColor = PowerupColors.Points; break; case Powerup.Defense: powerUpChar = PowerupChars.Defense; powerupColor = PowerupColors.Defense; break; } gr.WriteToBuffer(powerup.Item2.X, powerup.Item2.Y, powerUpChar, powerupColor); } }
public void WriteLine() { _cursorColumn = 0; _cursorRow++; if (_cursorRow >= Rows) { _cursorRow--; if (ScrollAtBottom) { // Move all of the text up 1 line. for (var row = 1; row < Rows; row++) { for (var column = 0; column < Columns; column++) { this[row - 1, column] = this[row, column]; } } var emptyAttr = new ConsoleAttribute('\0', ForegroundColor, BackgroundColor); // Clear out the bottom row. for (var column = 0; column < Columns; column++) { this[Rows - 1, column] = emptyAttr; } } else { _cursorRow = 0; } } }
public void Write(char ch) { this[_cursorRow, _cursorColumn] = new ConsoleAttribute(ch, ForegroundColor, BackgroundColor); _cursorColumn++; if (_cursorColumn >= Columns) { _cursorColumn = 0; // TODO: Implement auto-scrolling. _cursorRow++; if (_cursorRow >= Rows) { _cursorRow = 0; } } }
/// <summary> /// Zeichnet die Highscore Liste in die Konsole /// </summary> /// <param name="spielmodus">Der Spielmodus aus dem der Highscore angezeigt werden soll</param> public void Draw() { gr.ClearBuffer(); // Positioniert das Logo mittig in der Konsole for (int i = 0; i < HIGHSCORE_LOGO.Length; i++) { // Offset 5 damit es nicht ganz oben am Rand ist sondern etwas drunter gr.WriteToBuffer((gr.CONSOLE_WIDTH - HIGHSCORE_LOGO[i].Length) / 2, i + 5, HIGHSCORE_LOGO[i], ConsoleAttribute.FG_RED); } ScoreRow[] scores = LoadScores(); // Sortiert die Highscores scores = scores.OrderByDescending(row => row.Score).ToArray(); for (int i = 0; i < scores.Length; i++) { if (i >= 10) { break; // nur die top 10 anzeigen } // Ziel Format: 1. Name Punkte string formatted = string.Format("{0,2}. {1,-20} {2,7}", i + 1, scores[i].Name, scores[i].Score); // Mittig in der Konsole platzieren und dabei beachten, dass es auch je nach Anzahl der Scores weiter oben oder unten ist gr.SetCursorPosition((gr.CONSOLE_WIDTH - formatted.Length) / 2, (gr.CONSOLE_HEIGHT / 2) + i - ((scores.Length > 10 ? 10 : scores.Length) / 2)); if (i % 2 == 0) { gr.WriteToBuffer(formatted, ConsoleAttribute.FG_CYAN); } else { gr.WriteToBuffer(formatted, ConsoleAttribute.FG_WHITE); } } // Draw Border if (scores.Length > 0) { ConsoleAttribute borderColor = ConsoleAttribute.FG_BLUE_BRIGHT; int borderOffset = 3; int borderWidth = 35; int amount = scores.Length > 10 ? 10 : scores.Length; int x = ((gr.CONSOLE_WIDTH - borderWidth) / 2) - borderOffset; int y = ((gr.CONSOLE_HEIGHT - amount) / 2) - borderOffset; // left/right border for (int rowY = 0; rowY < amount + (borderOffset * 2); rowY++) { if (rowY == 0) { // top left gr.WriteToBuffer(x, y + rowY, ConsoleGraphics.EDGE_TOP_LEFT, borderColor); // top right gr.WriteToBuffer(x + borderWidth + (borderOffset + 1), y + rowY, ConsoleGraphics.EDGE_TOP_RIGHT, borderColor); } else if (rowY == (amount + (borderOffset * 2) - 1)) { // bottom left gr.WriteToBuffer(x, y + rowY, ConsoleGraphics.EDGE_BOTTOM_LEFT, borderColor); // bottom right gr.WriteToBuffer(x + borderWidth + (borderOffset + 1), y + rowY, ConsoleGraphics.EDGE_BOTTOM_RIGHT, borderColor); } else { // vertical left gr.WriteToBuffer(x, y + rowY, ConsoleGraphics.VERTICAL_BORDER, borderColor); // vertical right gr.WriteToBuffer(x + borderWidth + (borderOffset + 1), y + rowY, ConsoleGraphics.VERTICAL_BORDER, borderColor); } } // top border gr.WriteToBuffer(x + 1, y, new string(ConsoleGraphics.HORIZONTAL_BORDER, borderWidth + (borderOffset * 2) - 3), borderColor); // bottom border gr.WriteToBuffer(x + 1, y + amount + (borderOffset * 2) - 1, new string(ConsoleGraphics.HORIZONTAL_BORDER, borderWidth + (borderOffset * 2) - 3), borderColor); } gr.DrawBufferToConsole(); ConsoleKeyInfo kInfo; while (((kInfo = Console.ReadKey(true)).Key != ConsoleKey.Escape) && kInfo.Key != ConsoleKey.Backspace && kInfo.Key != ConsoleKey.Enter) { ; } }
public bool WriteToBuffer(int x, int y, int num, ConsoleAttribute attribute = ConsoleAttribute.FG_WHITE) { return(WriteToBuffer(x, y, num.ToString(), attribute)); }
/// <summary> /// One-time initialization for method info dictionary /// </summary> private void InitializeMethodInfoDictionary() { methodInfoDictionary = new Dictionary <string, List <MethodInfo> >(); typeList.ForEach(type => { type.GetMethods(BindingFlagsConstantInternal.allBindingFlags).Where(method => !method.IsAbstract && !method.IsGenericMethod && !method.IsDefined <ExtensionAttribute>()).ToList().ForEach(method => { ConsoleAttribute attribute = method.GetCustomAttribute <ConsoleAttribute>(); if (attribute == null) { return; } string name = attribute.name; if (name == null || !name.IsMatch(RegexConstant.alphanumericOrUnderscore)) { StringConstantInternal.methodUnsupportedNameError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } ParameterInfo[] parameterInfos = method.GetParameters(); if (parameterInfos.Length >= 1 && parameterInfos[parameterInfos.Length - 1].IsDefined <ParamArrayAttribute>() || parameterInfos.ToList().Any(parameter => { return(parameter.IsOut || parameter.ParameterType.IsByRef || !parameter.ParameterType.IsPrimitive && parameter.ParameterType != typeof(string) && !parameter.ParameterType.IsEnum); })) { StringConstantInternal.methodUnsupportedArgumentError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } if (fieldInfoDictionary != null && fieldInfoDictionary.ContainsKey(name) || propertyInfoDictionary != null && propertyInfoDictionary.ContainsKey(name)) { StringConstantInternal.methodDuplicatedError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } if (!methodInfoDictionary.ContainsKey(name)) { methodInfoDictionary[name] = new List <MethodInfo>(); } List <MethodInfo> methodInfoList = methodInfoDictionary[name]; if (methodInfoList.Any(otherMethod => { ParameterInfo[] otherParameterInfos = otherMethod.GetParameters(); if (parameterInfos.Length != otherParameterInfos.Length) { return(false); } for (int i = 0; i < parameterInfos.Length; i++) { if (parameterInfos[i].ParameterType != otherParameterInfos[i].ParameterType) { return(false); } } return(true); })) { StringConstantInternal.methodDuplicatedError.ReplacedBy(name).Color(Color.red).LogConsole(); return; } methodInfoList.Add(method); }); }); }