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 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); }
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); }
//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; } }
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); }