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); }
public void AssignEnemyNextBlock(int tier)//gives the player 3 unique blocks to choose for their enemy { //tier = 4; int[] cases = new int[3]; //a list of ID's that correspond to shapes, cases will never have two of the same number in it int index = 0; //the current element that controls cases switch (tier) //sets unique numbers based on the number of shape choices possible, size, and the bounds of random generation (max/min values) { case 1: cases = generateUniqueNumbers(3, 0, 5); //3 shapes to choose from, 5 shape types giving a rnd.next(0,7); break; case 2: cases = generateUniqueNumbers(3, 0, 5); //3 shapes to choose from, 5 shape types giving a rnd.next(0,5); break; case 3: cases = generateUniqueNumbers(3, 0, 4); //3 shapes to choose from, 4 shape types giving a rnd.next(0,4); break; } for (int Q = 0; Q < 3; Q++)//creates the actual shape and adds it to the player's choices which will add them to the enemy's shape queue { if (shapeChoices.Count > 2) { shapeChoices.RemoveAt(0); } Shape Temp = new OShape(); //temporary shape switch (tier) //looks at the tier, and assigns a certain difficulty of shape based on the tier { //the following functions take in cases and index. which will judge what shape gets assigned //cases controls the unique shape type //index controls the element within "cases" to assign a unique shape case 1: Temp = GenerateRandomTier1Shape(cases, index); //tier 1 shapes, or basic shapes break; case 2: Temp = GenerateRandomTier2Shape(cases, index); //tier 2 shapes, a little harder to place break; case 3: Temp = GenerateRandomTier3Shape(cases, index); //tier 3 shapes, pretty hard to place break; case 4: Temp = new ShapeShiftingShape(); //the ultimate shape, changes form every time player rotates it break; } shapeChoices.Add(Temp); //add the newly generated shape to the player's shape choices index++; //increase the index by one so next run of the for loop will assign the next unique shape type from "cases" } }
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); }