/// <summary> /// Create a 3D tetris shape, each shape is contructed with several faces /// </summary> /// <param name="shape"></param> /// <returns></returns> static public ModelVisual3D CreateShape(GeniusTetris.Core.Shape shape) { ModelVisual3D model = new ModelVisual3D(); Model3DGroup group = new Model3DGroup(); model.Content = group; byte currentColor = 0; for (int i = 0; i < shape.Width; i++) { for (int j = 0; j < shape.Height; j++) { byte b = shape[i, j]; if (b > 0) { currentColor = b; DrawingBrush dbrush = (DrawingBrush)Application.Current.Resources[string.Format("Block{0}", b)]; //Brush dbrush = new SolidColorBrush(Colors.Red); Model3D face = CreateFaceModel1x1(dbrush); face.Transform = GetTransformation(i, j, false); group.Children.Add(face); face = CreateFaceModel1x1(dbrush); face.Transform = GetTransformation(i, j, true); group.Children.Add(face); //ajout des cotés AddCotes(shape, group, i, j, dbrush); } } } return(model); }
static private void AddCotes(GeniusTetris.Core.Shape shape, Model3DGroup group, int i, int j, Brush dbrush) { //Gauche if (i - 1 < 0 || shape[i - 1, j] == 0) { group.Children.Add(CreateFaceDroiteGauche(i, j, dbrush, true)); } //Droit if (i + 1 >= shape.Width || shape[i + 1, j] == 0) { group.Children.Add(CreateFaceDroiteGauche(i, j, dbrush, false)); } //Haut if (j - 1 < 0 || shape[i, j - 1] == 0) { group.Children.Add(CreateFaceHautBas(i, j, dbrush, true)); } //Bas if (j + 1 >= shape.Height || shape[i, j + 1] == 0) { group.Children.Add(CreateFaceHautBas(i, j, dbrush, false)); } }