public static AbstractFallingObject CreateInstance(AbstractGame gameState, FallingObjectType fallingObjectType) { var startFallingObjectRotationCenter = new Point (gameState.Width / 2 - (gameState.Width / 2) % Tetris.CellSize, gameState.Height + Tetris.CellSize); switch (fallingObjectType) { case FallingObjectType.CrookedStick: return(new CrookedStick(startFallingObjectRotationCenter, gameState)); case FallingObjectType.Cube: return(new Cube(startFallingObjectRotationCenter, gameState)); case FallingObjectType.Hanger: return(new Hanger(startFallingObjectRotationCenter, gameState)); case FallingObjectType.StraightStick: return(new StraightStick(startFallingObjectRotationCenter, gameState)); case FallingObjectType.Thunder: return(new Thunder(startFallingObjectRotationCenter, gameState)); default: throw new ArgumentOutOfRangeException(nameof(fallingObjectType), $"Unknown type {nameof(fallingObjectType)}."); } }
public void DestroyIfMatchType(FallingObjectType typeToMatch) { if (typeToMatch == type && !pointsEarned) { SuccessfullyClick(); } }
public FallingObject(FallingObjectType objectType, int lane) { // Adds every object spawned to the list Game.Current.FallingObjects.Add(this); // Define properties of falling object Type = objectType; SmallLane = lane; Size = new Size(30, 30); SizeMode = PictureBoxSizeMode.Zoom; Velocity = 3; // Define type of object if (Type == FallingObjectType.Good) { Image = Properties.Resources.Star; } else if (Type == FallingObjectType.Bad) { Image = Properties.Resources.Bomb; } else if (Type == FallingObjectType.Shield) { Image = Properties.Resources.Shield; } // Define big and small lanes of object switch (SmallLane) { case 1: Location = new Point(Game.FirstLaneX - (Width / 2), 10); BigLane = FallingObjectBigLane.Left; break; case 2: Location = new Point(Game.SecondLaneX - (Width / 2), 10); BigLane = FallingObjectBigLane.Left; break; case 3: Location = new Point(Game.ThirdLaneX - (Width / 2), 10); BigLane = FallingObjectBigLane.Right; break; case 4: Location = new Point(Game.FourthLaneX - (Width / 2), 10); BigLane = FallingObjectBigLane.Right; break; } }