public IDrawing CreateObject(string c) { IDrawing drawing = null; if (!Enum.TryParse(c, out CommandEnum command)) { return(drawing); } else { if (command == CommandEnum.C) { drawing = new CreateCanvas(); } else if (command == CommandEnum.L) { drawing = new CreateNewLine(); } else if (command == CommandEnum.R) { drawing = new CreateRectangle(); } else if (command == CommandEnum.B) { drawing = new FillArea(); } } return(drawing); }
private void DrawPath(DirectionalCell c, CreateRectangle path, SpriteBatch spritebatch) { if (c.Direction == Direction.Stay) { return; } Cell cell = c.Cell; #if DEBUG if (_selectedCell == cell) { Console.WriteLine("X: {0}, Y: {1}, Dir: {2}", cell.X, cell.Y, c.Direction); } #endif float rotation = c.ToRad(); Texture2D texture = _towerTextures[c.Direction == Direction.Stay ? Tower.Ground : Tower.Direction]; spritebatch.Draw(texture, path(cell.X, cell.Y), null, (_selectedCell == cell) ? Color.YellowGreen : Color.White, rotation, new Vector2(texture.Width / 2, texture.Height / 2) , SpriteEffects.None, 0f); }
static void Main(string[] args) { ICanvas canvas = null; ICommand command; while (true) { Console.Write("enter command : "); var userInput = Console.ReadLine(); var input = InputParser.ParseInput(userInput); switch (input.Command.ToUpper()) { case "C": command = new CreateCanvas(); ExecuteCommandAndDrawCanvas(); break; case "L": command = new CreateLine(canvas); ExecuteCommandAndDrawCanvas(); break; case "R": command = new CreateRectangle(canvas); ExecuteCommandAndDrawCanvas(); break; case "B": command = new FillBucket(canvas); ExecuteCommandAndDrawCanvas(); break; case "Q": command = new ExitCommand(); command.ExecuteCommand(input.Args); break; default: break; void ExecuteCommandAndDrawCanvas() { try { canvas = command.ExecuteCommand(input.Args); Console.WriteLine(canvas.ToString()); //canvas.DrawCanvas(); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } } } } }
public void ExecuteCommand_Canvas_Not_Exists() { string[] args = new string[] { "1", "2", "6", "2" }; CreateRectangle createRectangle = new CreateRectangle(null); var exception = Record.Exception(() => createRectangle.ExecuteCommand(args)); Assert.NotNull(exception); Assert.IsType <ArgumentException>(exception); Assert.Equal($"{Constants.Command_Canvas_Not_Exists}", exception.Message); }
public void ExecuteCommand_Invalid_Argument(string CommandName, string[] args) { CreateRectangle createRectangle = new CreateRectangle(_canvas.Object); var exception = Record.Exception(() => createRectangle.ExecuteCommand(args)); Assert.NotNull(exception); Assert.IsType <ArgumentException>(exception); Assert.Equal($"{Constants.Command_Expect_Four_Positive_Arguments}", exception.Message); Assert.Equal("R", CommandName); }
/// <summary> /// Constructeur de la grille /// </summary> /// <param name="width">Nombre de cellules horizontalement</param> /// <param name="height">Nombre de cellules verticalement</param> /// <param name="sizeX"></param> /// <param name="sizeY"></param> /// <param name="screenWidth"></param> /// <param name="screenHeight"></param> public Grid(int width, int height, int sizeX, int sizeY, int screenWidth, int screenHeight) : base(width, height, (x, y, list) => new Cell(x, y, list)) { _sizeX = sizeX; _sizeY = sizeY; Zoom = 10; _towerTextures = new Dictionary <Tower, Texture2D>(); _offsetX = (screenWidth - Width * _sizeX) / 2; _offsetY = (screenHeight - Height * _sizeY) / 2; _running = true; _changePath = _delegateChangePath = (path, cell) => { _changePath = (p, c) => p; if (Cell.Goal == null || Cell.Start == null) { return(path); } try { return(AStar(cell, Cell.Goal, (Cell p, Cell c, out int cost) => { Point dir = new Point(c.X - p.X, c.Y - p.Y); if (dir.X != 0 && dir.Y != 0) { var c1 = this[c.X - dir.X, c.Y]; var c2 = this[c.X, c.Y - dir.Y]; bool canWalk = c.InnerCell.CanWalk && (c1.InnerCell.CanWalk && c2.InnerCell.CanWalk); cost = c.InnerCell.CellCost + (Math.Max(c1.InnerCell.CellCost, c2.InnerCell.CellCost)); return canWalk; } cost = c.InnerCell.CellCost; return c.InnerCell.CanWalk; }, ArroundSelectMode.Round)); } catch (Exception e) { new Thread(() => System.Windows.Forms.MessageBox.Show(e.Message)).Start(); return(new DirectionalCell[0]); } }; _rect = RectangleFactory(_offsetX, _offsetY, _sizeX, _sizeY); }
public void CreateASquare() { var mock = new Mock <ICanvas>(); mock.Setup(canvas => canvas.Draw(0, 0, 1)); mock.Setup(canvas => canvas.Draw(0, 1, 1)); mock.Setup(canvas => canvas.Draw(1, 0, 1)); mock.Setup(canvas => canvas.Draw(1, 1, 1)); CreateRectangle rect = new CreateRectangle(mock.Object, 0, 0, 1, 1, 1); rect.Execute(); mock.Verify(canvas => canvas.Draw(0, 0, 1), Times.Once()); mock.Verify(canvas => canvas.Draw(0, 1, 1), Times.Once()); mock.Verify(canvas => canvas.Draw(1, 0, 1), Times.Once()); mock.Verify(canvas => canvas.Draw(1, 1, 1), Times.Once()); }
private void OnMouseDown(object sender, MouseEventArgs e) { CreateRectangle newRectangle = new CreateRectangle(modelSpace.Project.CreateNewOperationId()); //The width,height,depth of cuboid is setted with default value now //We'll improve it next version by using mouse draging Length.LengthUnit unit = modelSpace.Project.Environment.DefaultLengthUnit; float value1 = modelSpace.Project.Environment.GridSize.Value * 2; float value2 = modelSpace.Project.Environment.GridSize.Value; newRectangle.Width = new Length(value1, unit); newRectangle.Height = new Length(value2, unit); //Set the refpoint Vector3 refPoint = modelSpace.SceneRender.DisplayedGridPoint; newRectangle.RefPoint = new Vector3WithUnit(refPoint, modelSpace.Project.Environment.DefaultLengthUnit); //Set the aline axis switch (modelSpace.Project.Environment.GridPlane) { case GridPlane.XY: newRectangle.AlineAxis = Axis.Z; break; case GridPlane.XZ: newRectangle.AlineAxis = Axis.Y; break; case GridPlane.YZ: newRectangle.AlineAxis = Axis.X; break; default: newRectangle.AlineAxis = Axis.Z; break; } //Create the new single modelSpace.Project.CreateNewSingle(newRectangle); workspace.SelectTool(); }
public void Update() { if (InputEvent.KeyboardClick(Keys.Space)) { LaunchWave(Textures.Ship.Ship2); } if (!CircularMenu.Opened) { if (InputEvent.MouseState.RightButton == ButtonState.Pressed || InputEvent.MouseState.MiddleButton == ButtonState.Pressed) { var move = InputEvent.MouseMove(); _offsetX -= (int)move.X; _offsetY -= (int)move.Y; _rect = RectangleFactory(_offsetX, _offsetY, SizeX, SizeY); } if (InputEvent.HasScrolled()) { var dir = (InputEvent.ScroolValue() > 0) ? 1 : -1; _zoom += dir; if (_zoom < 1) { _zoom = 1; } _rect = RectangleFactory(_offsetX, _offsetY, SizeX, SizeY); } if (InputEvent.MousePosition().X - _offsetX < 0 || InputEvent.MousePosition().Y - _offsetY < 0) { _selectedCell = null; } else { _selectedCell = this[(InputEvent.MousePosition().X - _offsetX) / SizeX, (InputEvent.MousePosition().Y - _offsetY) / SizeY]; } } if (_ships != null) { _ships.Update(); } }
public void ExecuteCommand_Create_Rectangle_Success() { CreateCanvas createCanvas = new CreateCanvas(); string[] args1 = new string[] { "20", "4" }; var canvas = createCanvas.ExecuteCommand(args1); string[] args = new string[] { "14", "1", "18", "3" }; CreateRectangle createRectangle = new CreateRectangle(canvas); var result = createRectangle.ExecuteCommand(args); Assert.NotNull(result); for (int i = 14; i <= 18; i++) { Assert.Equal('x', canvas.Cells[i, 1]); Assert.Equal('x', canvas.Cells[i, 3]); } for (int i = 2; i < 3; i++) { Assert.Equal('x', canvas.Cells[14, i]); Assert.Equal('x', canvas.Cells[18, i]); } }
public void CanvasApp_Test() { List <string> commands = new List <string> { new string("C 20 4"), new string("L 1 2 6 2"), new string("L 6 3 6 4"), new string("R 14 1 18 3"), new string("B 10 3 o"), }; ICanvas canvas = null; ICommand command; foreach (string com in commands) { var input = InputParser.ParseInput(com); switch (input.Command.ToUpper()) { case "C": command = new CreateCanvas(); ExecuteCommandAndDrawCanvas(); break; case "L": command = new CreateLine(canvas); ExecuteCommandAndDrawCanvas(); break; case "R": command = new CreateRectangle(canvas); ExecuteCommandAndDrawCanvas(); break; case "B": command = new FillBucket(canvas); ExecuteCommandAndDrawCanvas(); break; case "Q": command = new ExitCommand(); command.ExecuteCommand(input.Args); break; default: break; void ExecuteCommandAndDrawCanvas() { try { canvas = command.ExecuteCommand(input.Args); } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } } } } string[] expected = new string[6] { "----------------------", "|oooooooooooooxxxxxoo|", "|xxxxxxooooooox xoo|", "| xoooooooxxxxxoo|", "| xoooooooooooooo|", "----------------------" }; for (int i = 0; i < 6; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < 22; j++) { sb.Append(canvas.Cells[j, i]); } sb.Replace('\0', ' '); Assert.Equal(expected[i], sb.ToString()); } }