private void ShapeToolClick(object sender, RoutedEventArgs e) { Button btn = (Button)sender; if (btn == btnLineTool) { shape = ShapeCreator.CreateNewShape("TLine"); } else if (btn == btnArrowTool) { shape = ShapeCreator.CreateNewShape("TArrow"); } else if (btn == btnRectangleTool) { shape = ShapeCreator.CreateNewShape("TRectangle"); } else if (btn == btnEllipseTool) { shape = ShapeCreator.CreateNewShape("TEllipse"); } else if (btn == btnStar) { shape = ShapeCreator.CreateNewShape("TStar"); } DrawType = (int)DrawElementType.Shape; CurrentTool = (int)DrawElementType.Shape; }
public TShape LoadShapePlugin(string fileName) { TShape result = null; try { Assembly asm = Assembly.LoadFile(fileName); result = CreatePluginFromAssembly(asm); if (result != null) { if (!pluginLogger.hasLineInFile(fileName)) { pluginLogger.writeLine(fileName); } if (!IsInShapes(result.getShapeName())) { shapes.Add(result.getShapeName(), result); } } } catch (Exception) { return(null); } return(result); }
// Paste private void btnPaste_Click(object sender, RoutedEventArgs e) { // Xóa bỏ ContentControl của các hình đang chọn (nếu có) UnSelectedTheLastChildrenOfCanvas(); // Lấy hình ảnh từ Clipboard BitmapSource bmi = Clipboard.GetImage(); if (bmi != null) { // Tạo ImageBrush để fill cho Rectangle ImageBrush imb = new ImageBrush(bmi); shape = ShapeCreator.CreateNewShape("TRectangle"); shape.FillColorBrush = imb; shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent; shape.StartPoint = new Point(0, 0); shape.EndPoint = new Point(imb.ImageSource.Width, imb.ImageSource.Height); Style controlStyle = (Style)FindResource("DesignerItemStyle"); if (controlStyle != null) { shape.controlStyle = controlStyle; } shape.draw(isShiftKeyDown, PaintCanvas.Children); // Show control cho ContentControl SelectedTheLastChildrenOfCanvas(); isSelectShape = true; ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]); } // Thoát chế độ Select isSelectionTool = false; }
private void cbShapePlugin_SelectionChanged(object sender, SelectionChangedEventArgs e) { string shapeName = cbShapePlugin.SelectedItem.ToString(); shape = ShapeCreator.CreateNewShape(shapeName); DrawType = (int)DrawElementType.Shape; CurrentTool = (int)DrawElementType.Shape; }
/// <summary> /// Creates a new shape from this template. /// </summary> public TShape CreateShape <TShape>() where TShape : Shape { TShape result = (TShape)_shape.Type.CreateInstance(this); if (_shape.ModelObject != null) { ShapeDuplicator.CloneModelObjectOnly(result); } return(result); }
public TShape CreateFromType(Type type) { try { TShape result = (TShape)Activator.CreateInstance(type); return(result); } catch (Exception) { return(null); } }
public TShape CreatePluginFromAssembly(Assembly asm) { foreach (Type type in asm.GetTypes()) { TShape result = CreateFromType(type); if (result != null) { return(result); } } return(null); }
private TShape BasicShapeInitialize(out List <Vector2> coordinates, ShapeRenderer.Orientation ori) { Block anchor = new Block(100, 100); TShape T = new TShape(anchor, ori); coordinates = new List <Vector2>(); foreach (Block b in T.blocks) { coordinates.Add(new Vector2(b.GetX(), b.GetY())); } return(T); }
private IShape GetDesiredShape(string shapeParam) { IShape newShape = null; Random randomClass = new Random(); //int randomCode = randomClass.Next((int)ShapeCodes.I, (int)ShapeCodes.Z + 1); switch (shapeParam) { case "I": newShape = new StickShape(); newShape.Color = Color.Cyan; break; case "J": newShape = new JShape(); newShape.Color = Color.Blue; break; case "L": newShape = new LShape(); newShape.Color = Color.Orange; break; case "O": newShape = new OShape(); newShape.Color = Color.Yellow; break; case "S": newShape = new SShape(); newShape.Color = Color.Green; break; case "T": newShape = new TShape(); newShape.Color = Color.Purple; break; case "Z": newShape = new ZShape(); newShape.Color = Color.Red; break; } ((BaseShape)newShape).Presenter = presenter; presenter.UpdateScoreView(score, hiScore, lines, level, newShape); return(newShape); }
private IShape GetRandomShape() { IShape newShape = null; Random randomClass = new Random(); int randomCode = randomClass.Next((int)ShapeCodes.I, (int)ShapeCodes.Z + 1); switch (randomCode) { case (int)ShapeCodes.I: newShape = new StickShape(); newShape.Color = Color.Cyan; break; case (int)ShapeCodes.J: newShape = new JShape(); newShape.Color = Color.Blue; break; case (int)ShapeCodes.L: newShape = new LShape(); newShape.Color = Color.Orange; break; case (int)ShapeCodes.O: newShape = new OShape(); newShape.Color = Color.Yellow; break; case (int)ShapeCodes.S: newShape = new SShape(); newShape.Color = Color.Green; break; case (int)ShapeCodes.T: newShape = new TShape(); newShape.Color = Color.Purple; break; case (int)ShapeCodes.Z: newShape = new ZShape(); newShape.Color = Color.Red; break; } ((BaseShape)newShape).Presenter = presenter; presenter.UpdateScoreView(score, hiScore, lines, level, newShape); return(newShape); }
private void btnLoadShapePlugin_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Filter = "Dll Plugin File|*.dll"; if ((bool)openFileDialog.ShowDialog()) { TShape plugin = ShapeCreator.LoadShapePlugin(openFileDialog.FileName); if (plugin != null) { cbShapePlugin.Items.Add(plugin.getShapeName()); cbShapePlugin.SelectedIndex = 0; } } }
public string[] LoadPluginFromPluginLogFile() { List <string> result = new List <string>(); string[] files = pluginLogger.readAllLine(); foreach (string fileName in files) { TShape shape = LoadShapePlugin(fileName); if (shape != null) { result.Add(shape.getShapeName()); } } return(result.ToArray()); }
private IShape GetRandomShape() { IShape newShape = null; Random randomClass = new Random(); int randomCode = randomClass.Next((int)ShapeKind.I, (int)ShapeKind.Z + 1); switch (randomCode) { case (int)ShapeKind.I: newShape = new StickShape(); break; case (int)ShapeKind.J: newShape = new JShape(); break; case (int)ShapeKind.L: newShape = new LShape(); break; case (int)ShapeKind.O: newShape = new OShape(); break; case (int)ShapeKind.S: newShape = new SShape(); break; case (int)ShapeKind.T: newShape = new TShape(); break; case (int)ShapeKind.Z: newShape = new ZShape(); break; } ((BaseShape)newShape).Presenter = _presenter; _presenter.UpdateScoreView(_score, _hiScore, _lines, _level, newShape); return(newShape); }
private static Shape GetShapeByTypeName(string shapeTypeName, Canvas canvas) { Shape shape = default(Shape); switch (shapeTypeName) { case nameof(ShapeType.Stick): shape = new Stick(canvas); break; case nameof(ShapeType.Square): shape = new Square(canvas); break; case nameof(ShapeType.ZShape): shape = new ZShape(canvas); break; case nameof(ShapeType.ZShapeMirror): shape = new ZShapeMirror(canvas); break; case nameof(ShapeType.LShape): shape = new LShape(canvas); break; case nameof(ShapeType.LShapeMirror): shape = new LShapeMirror(canvas); break; case nameof(ShapeType.TShape): shape = new TShape(canvas); break; case nameof(ShapeType.TShapeMirror): shape = new TShapeMirror(canvas); break; } return(shape); }
protected virtual Shape GenerateRandomShape() { int Random_Color_Element; Random_Color_Element = Game1.rnd.Next(0, 8); Shape generatedShape = null; switch (Game1.rnd.Next(7)) { case 0: generatedShape = new OShape(); break; case 1: generatedShape = new IShape(); break; case 2: generatedShape = new SShape(); break; case 3: generatedShape = new ZShape(); break; case 4: generatedShape = new LShape(); break; case 5: generatedShape = new JShape(); break; case 6: generatedShape = new TShape(); break; } return(generatedShape); }
// Open file private void btnOpenImage_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Filter = "Png Image|*.png|Jpg Image|*.jpg|Bitmap Image|*.bmp"; openFileDialog.FileName = "MyPaint"; openFileDialog.DefaultExt = ".png"; if ((bool)openFileDialog.ShowDialog()) { ImageBrush image = new ImageBrush(); image.ImageSource = new BitmapImage(new Uri(@openFileDialog.FileName, UriKind.Relative)); shape = ShapeCreator.CreateNewShape("TRectangle"); shape.FillColorBrush = image; shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent; shape.StartPoint = new Point(0, 0); shape.EndPoint = new Point(image.ImageSource.Width, image.ImageSource.Height); shape.draw(isShiftKeyDown, PaintCanvas.Children); ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]); } }
//Spawns a random tetromino which is placed to the right of the gamefield. public void AddNewRandomTetrominoUpcoming() { Random rng = new(); int num = rng.Next(1, 8); switch (num) { case 1: UpcomingTetromino = new ZShape(GridWidth / 2, 0); break; case 2: UpcomingTetromino = new SShape(GridWidth / 2, 0); break; case 3: UpcomingTetromino = new LShape(GridWidth / 2, 0); break; case 4: UpcomingTetromino = new JShape(GridWidth / 2, 0); break; case 5: UpcomingTetromino = new IShape(GridWidth / 2, 0); break; case 6: UpcomingTetromino = new TShape(GridWidth / 2, 0); break; case 7: UpcomingTetromino = new OShape(GridWidth / 2, 0); break; default: break; } }
// Cut private void btnCut_Click(object sender, RoutedEventArgs e) { if (isSelectionTool) { // Xóa ContentControl của Select removeLastChildren(); shape = ShapeCreator.CreateNewShape("TRectangle"); shape.StartPoint = StartPoint; shape.EndPoint = EndPoint; shape.FillColorBrush = System.Windows.Media.Brushes.White; shape.StrokeColorBrush = System.Windows.Media.Brushes.Transparent; shape.draw(isShiftKeyDown, PaintCanvas.Children); // Lưu CroppedBitmapImage vào Clipboard saveCroppedBitmapToClipboard(); ShapeCommand cmd = new ShapeCommand(PaintCanvas.Children, PaintCanvas.Children[PaintCanvas.Children.Count - 1]); } // Thoát chế độ Select isSelectionTool = false; }
public Boolean NewShapeSpawn() { Shape currentShape; Int32 currentShapeIndex; ShapeTypes value = RandomEnumValue(); switch (value) { case ShapeTypes.TShape: currentShape = new TShape(); currentShapeIndex = 1; break; case ShapeTypes.JShape: currentShape = new JShape(); currentShapeIndex = 2; break; case ShapeTypes.ZShape: currentShape = new ZShape(); currentShapeIndex = 3; break; case ShapeTypes.OShape: currentShape = new OShape(); currentShapeIndex = 4; break; case ShapeTypes.SShape: currentShape = new SShape(); currentShapeIndex = 5; break; case ShapeTypes.LShape: currentShape = new LShape(); currentShapeIndex = 6; break; case ShapeTypes.IShape: currentShape = new IShape(); currentShapeIndex = 7; break; default: currentShape = new IShape(); currentShapeIndex = 7; break; } var x = currentShape.getPosX(); var y = currentShape.getPosY(); var ImaginaryPos = currentShape.getCurrentState(); Boolean l = true; for (int i = 0; i < 4 && l; i++) { var a = x + ImaginaryPos[i, 0]; var b = y + ImaginaryPos[i, 1]; if (a < 0 || a > _table.Size || b < 0 || b > 15) { l = false; } l = l && _table.Table[a, b] == 0; } if (l) { for (int i = 0; i < 4 && l; i++) { var a = x + ImaginaryPos[i, 0]; var b = y + ImaginaryPos[i, 1]; _table.Table[a, b] = 2; _table.TypeTable[a, b] = currentShapeIndex; } _table.NewShape(currentShapeIndex); } else { currentShape = null; //gameover(); } return(l); }
public static Shape ConvertToShape(string s) { Shape shape = null; string name = ""; string[] ss = new string[0]; //array of all the data parts int numBlocks; //counting variables bool extraData = false; //Grab extra data from the string for shape shifting shape try { //Get name ss = s.Split('['); for (int i = 0; i < ss.Length; i++) { ss[i] = ss[i].Trim('[', ']'); } //Set up initial shape design name = ss[0]; switch (name) { case "IShape": shape = new IShape(); break; case "JShape": shape = new JShape(); break; case "LShape": shape = new LShape(); break; case "OShape": shape = new OShape(); break; case "SShape": shape = new SShape(); break; case "TShape": shape = new TShape(); break; case "ZShape": shape = new ZShape(); break; case "Corner Shape": shape = new CornerShape(); break; case "Easy Diagonal Shape": shape = new EasyDiagonalShape(); break; case "Hockey Stick Shape": shape = new HockeyStickShape(); break; case "Oklahoma Shape": shape = new OklahomaShape(); break; case "Reverse Hockey Stick Shape": shape = new ReverseHockeyStickShape(); break; case "Bucket Shape": shape = new BucketShape(); break; case "Lobster Claw Shape": shape = new LobsterClawShape(); break; case "Plus Shape": shape = new PlusShape(); break; case "Stair Shape": shape = new StairShape(); break; case "VShape": shape = new VShape(); break; case "Hard Diagonal Shape": shape = new HardDiagonalShape(); break; case "Hook Shape": shape = new HookShape(); break; case "Kite Shape": shape = new KiteShape(); break; case "Tonfu Shape": shape = new TonfuShape(); break; case "Shape Shifting Shape": shape = new ShapeShiftingShape(); extraData = true; break; default: shape = new OShape(); break; } //Set up blocks numBlocks = int.Parse(ss[1]); for (int i = 0; i < numBlocks; i++) { int blockIndex = int.Parse(ss[2 + i]); shape.blocks[i].blockColor = BlockColors.AllBlocks[blockIndex]; } //If shapeshifting shape, get state relative positions of the different forms if (extraData) { shape.stateRelativePositions.Clear(); int index = 2 + numBlocks; for (int i = 0; i < 4; i++) { shape.stateRelativePositions.Add(new List <Vector2>()); int numFormBlocks = int.Parse(ss[index]); index++; for (int j = 0; j < numFormBlocks; j++) { int x = int.Parse(ss[index]); int y = int.Parse(ss[index + 1]); index += 2; shape.stateRelativePositions[i].Add(new Vector2(x, y)); } } } } catch { Console.WriteLine("String could not be converted to shape: {0}", s); } return(shape); }
private void btnSelect_Click(object sender, RoutedEventArgs e) { DrawType = (int)DrawElementType.Shape; CurrentTool = (int)DrawElementType.SelectionTool; shape = ShapeCreator.CreateNewShape("TRectangle"); }