public bool MoveDown() { if (!CheckCollision(Position.DOWN)) { this.ClearObject(); row++; this.DrawObject(); return(true); } else { tField.PlaceObject(row, column, tObject); Tuple <int, int> temp = new Tuple <int, int>(0, 0); temp = tField.ClearFullRows(); game.Score = temp.Item1; game.Bonus = temp.Item2; while (game.Score / game.Level >= 1000) { game.Level = game.Level + 1; } row = 0; column = 4; tObject = nextObject; if (!InitialDraw()) { game.EndGame(); } return(false); } }
public void PlaceObject(int row, int column, TetrisObject tObject) { foreach (Point p in tObject) { this[p.X + row, p.Y + column] = Color.Gray; } }
public TetrisObject(TetrisObject tetrisObject) { matrix = tetrisObject.matrix; rotationPoints = tetrisObject.rotationPoints; x = tetrisObject.x; y = tetrisObject.y; rotation = tetrisObject.rotation; }
private void btnParallelGame_Click(object sender, EventArgs e) { List <TetrisObject> listOfShapes = new List <TetrisObject>(); int[,] objekt1 = new int[, ] { { 1, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }; TetrisObject tObject1 = new TetrisObject(objekt1); listOfShapes.Add(tObject1); int[,] objekt2 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 1, 1, 0 } }; TetrisObject tObject2 = new TetrisObject(objekt2); listOfShapes.Add(tObject2); int[,] objekt3 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 } }; TetrisObject tObject3 = new TetrisObject(objekt3); listOfShapes.Add(tObject3); int[,] objekt4 = new int[, ] { { 1, 1, 0 }, { 1, 1, 0 }, { 0, 0, 0 } }; TetrisObject tObject4 = new TetrisObject(objekt4); listOfShapes.Add(tObject4); int[,] objekt5 = new int[, ] { { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject5 = new TetrisObject(objekt5); listOfShapes.Add(tObject5); int[,] objekt6 = new int[, ] { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject6 = new TetrisObject(objekt6); listOfShapes.Add(tObject6); int[,] objekt7 = new int[, ] { { 0, 0, 0 }, { 0, 1, 1 }, { 1, 1, 0 } }; TetrisObject tObject7 = new TetrisObject(objekt7); listOfShapes.Add(tObject7); ParallelGame parallelGame = new ParallelGame(listOfShapes); parallelGame.ShowDialog(); }
public MovingObject(TetrisField _tField, TetrisObject _tObject, TetrisObject _nextObject, GameScore _game) { tField = _tField; tObject = _tObject; nextObject = _nextObject; game = _game; row = 0; column = 4; goldenPoints = 0; InitialDraw(); }
private void MoveObject(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: mObject.MoveToSide(Position.LEFT); break; case Keys.Right: mObject.MoveToSide(Position.RIGHT); break; case Keys.Q: mObject.Rotate(Position.ROTATEL); break; case Keys.E: mObject.Rotate(Position.ROTATER); break; case Keys.Down: this.Down(); break; case Keys.Up: if (mObject.goldenPoints > 0 && mObject.MoveUp()) { mObject.goldenPoints--; goldenPts.Text = "Golden: " + mObject.goldenPoints.ToString(); } break; case Keys.R: if (mObject.goldenPoints > 0) { TetrisObject tetrisObject = new TetrisObject(listOfObjects[GetRandomNumber()]); while (tetrisObject == mObject.Object) { tetrisObject = new TetrisObject(listOfObjects[GetRandomNumber()]); } mObject.Object = tetrisObject; ShowNextObject(); mObject.goldenPoints--; goldenPts.Text = "Golden: " + mObject.goldenPoints.ToString(); } break; case Keys.P: game.Pause(); break; } }
private bool addToShapes(int[,] newShape, bool checkEquals = false) { int equals = 0; TetrisObject tetrisObject = new TetrisObject(newShape); if (checkEquals) { foreach (TetrisObject shape in listOfShapes) { if (tetrisObject == shape) { MessageBox.Show("The chosen shape has already been chosen before. Please, select a new one."); equals = 1; return(false); } } } if (equals == 0) { listOfShapes.Add(tetrisObject); shapesChosen += 1; setExplanation(); if (shapesChosen == 7) { play.Enabled = true; } if (shapesChosen == 10) { addingButton.Enabled = false; } } return(true); }
private bool CheckCollision(Position pos) { int newRow = row; int newColumn = column; TetrisObject tetrisObject = new TetrisObject(tObject); switch (pos) { case Position.UP: newRow--; if (newRow < 0) { return(true); } break; case Position.DOWN: newRow++; break; case Position.LEFT: newColumn--; break; case Position.RIGHT: newColumn++; break; case Position.ROTATEL: tetrisObject.Rotate(-1); if (tetrisObject.Size(1) + newColumn >= tField.Size(1)) { newColumn = tField.Size(1) - tetrisObject.Size(1); } break; case Position.ROTATER: tetrisObject.Rotate(1); if (tetrisObject.Size(1) + newColumn >= tField.Size(1)) { newColumn = tField.Size(1) - tetrisObject.Size(1); } break; default: break; } foreach (Point p in tetrisObject) { if (p.X + newRow >= tField.Size(0) || newColumn < 0 || newColumn + p.Y >= tField.Size(1)) { return(true); } if (tField[p.X + newRow, p.Y + newColumn] == Color.Gold) { goldenPoints += 3; //tField[p.X + newRow, p.Y + newColumn] = Color.Yellow; } if (tField[p.X + newRow, p.Y + newColumn] == Color.Gray || tField[p.X + newRow, p.Y + newColumn] == Color.Black) { return(true); } } return(false); }
public HighScore() { InitializeComponent(); this.BackColor = Color.CornflowerBlue; label1.ForeColor = Color.Yellow; label2.ForeColor = Color.Yellow; label3.ForeColor = Color.Yellow; if (Directory.Exists("..\\..\\data") && File.Exists(filePath)) { gamesAlreadyPlayed = ReadFromBinaryFile <List <Game> >(filePath); //Creating list of shapes in game List <TetrisObject> listOfShapes = new List <TetrisObject>(); int[,] objekt1 = new int[, ] { { 1, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }; TetrisObject tObject1 = new TetrisObject(objekt1); listOfShapes.Add(tObject1); int[,] objekt2 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 1, 1, 0 } }; TetrisObject tObject2 = new TetrisObject(objekt2); listOfShapes.Add(tObject2); int[,] objekt3 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 } }; TetrisObject tObject3 = new TetrisObject(objekt3); listOfShapes.Add(tObject3); int[,] objekt4 = new int[, ] { { 1, 1, 0 }, { 1, 1, 0 }, { 0, 0, 0 } }; TetrisObject tObject4 = new TetrisObject(objekt4); listOfShapes.Add(tObject4); int[,] objekt5 = new int[, ] { { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject5 = new TetrisObject(objekt5); listOfShapes.Add(tObject5); int[,] objekt6 = new int[, ] { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject6 = new TetrisObject(objekt6); listOfShapes.Add(tObject6); int[,] objekt7 = new int[, ] { { 0, 0, 0 }, { 0, 1, 1 }, { 1, 1, 0 } }; TetrisObject tObject7 = new TetrisObject(objekt7); listOfShapes.Add(tObject7); standardGame = new Game(listOfShapes); parallelGame = new Game(listOfShapes, false, false, true); if (gamesAlreadyPlayed.Contains(standardGame)) { idOfGame = gamesAlreadyPlayed.IndexOf(standardGame) + 1; scoreFilePath = Path.GetFullPath("..\\..\\data") + "\\scores\\" + idOfGame.ToString() + ".bin"; if (File.Exists(scoreFilePath)) { listOfScores = ReadFromBinaryFile <List <KeyValuePair <string, int> > >(scoreFilePath); int length = listOfScores.Count(); if (length > 7) { length = 7; } Label[] labelArray = new Label[7] { sgLabel1, sgLabel2, sgLabel3, sgLabel4, sgLabel5, sgLabel6, sgLabel7 }; for (int i = 0; i < length; i++) { labelArray[i].Text = (i + 1).ToString() + ". " + listOfScores[i].Key + " " + listOfScores[i].Value.ToString(); } } } if (gamesAlreadyPlayed.Contains(parallelGame)) { idOfGame = gamesAlreadyPlayed.IndexOf(parallelGame) + 1; scoreFilePath = Path.GetFullPath("..\\..\\data") + "\\scores\\" + idOfGame.ToString() + ".bin"; if (File.Exists(scoreFilePath)) { listOfScores = ReadFromBinaryFile <List <KeyValuePair <string, int> > >(scoreFilePath); int length = listOfScores.Count(); if (length > 7) { length = 7; } Label[] labelArray = new Label[7] { pgLabel1, pgLabel2, pgLabel3, pgLabel4, pgLabel5, pgLabel6, pgLabel7 }; for (int i = 0; i < length; i++) { labelArray[i].Text = (i + 1).ToString() + ". " + listOfScores[i].Key + " " + listOfScores[i].Value.ToString(); } } } } }
public Form1(bool _addObstacles = false, bool _addGoldenPoints = false) { SuspendLayout(); addObstacles = _addObstacles; addGoldenPoints = _addGoldenPoints; blackFieldAdded = false; goldenPointsInterval = rnd.Next(15, 50); labelArray = new Label[20, 10]; labelScore = new Label(); labelLevel = new Label(); labelArrayNext = new Label[3, 3]; this.CreateGrid(); this.CreateHelp(); tField = new TetrisField(ref labelArray); this.BackColor = Color.CornflowerBlue; InitializeComponent(); game = new GameScore(ref timer1); labelScore.Text = "SCORE:\n" + game.Score.ToString(); labelLevel.Text = "LEVEL: " + game.Level.ToString(); int[,] objekt1 = new int[, ] { { 1, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }; TetrisObject tObject1 = new TetrisObject(objekt1); int[,] objekt2 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 1, 1, 0 } }; TetrisObject tObject2 = new TetrisObject(objekt2); int[,] objekt3 = new int[, ] { { 0, 1, 0 }, { 0, 1, 0 }, { 0, 1, 1 } }; TetrisObject tObject3 = new TetrisObject(objekt3); int[,] objekt4 = new int[, ] { { 1, 1, 0 }, { 1, 1, 0 }, { 0, 0, 0 } }; TetrisObject tObject4 = new TetrisObject(objekt4); int[,] objekt5 = new int[, ] { { 1, 1, 0 }, { 0, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject5 = new TetrisObject(objekt5); int[,] objekt6 = new int[, ] { { 0, 1, 0 }, { 1, 1, 1 }, { 0, 0, 0 } }; TetrisObject tObject6 = new TetrisObject(objekt6); int[,] objekt7 = new int[, ] { { 0, 0, 0 }, { 0, 1, 1 }, { 1, 1, 0 } }; TetrisObject tObject7 = new TetrisObject(objekt7); listOfObjects = new TetrisObject[7] { tObject1, tObject2, tObject3, tObject4, tObject5, tObject6, tObject7 }; List <TetrisObject> list = new List <TetrisObject>() { tObject1, tObject2, tObject3, tObject4, tObject5, tObject6, tObject7 }; newGame = new Game(list); mObject = new MovingObject(tField, new TetrisObject(listOfObjects[GetRandomNumber()]), new TetrisObject(listOfObjects[GetRandomNumber()]), game); this.ClientSize = new Size(10 * 32 + 3 * 32 + 50, 32 * 20 + 1); goldenPosition = new Tuple <int, int>(0, 0); ShowNextObject(); ResumeLayout(); this.KeyDown += MoveObject; game.Start(); }