private void CreateNewBlockOnStartPosition() { neuerBlock = GameHelper.GetBlockItem(); block = GameHelper.GetBlockItem(); UpdateGui(); }
private void timer1_Tick(object sender, EventArgs e) { timer1.Interval = 200; ResetGui(); #region ausprogrammierter Weg //var maxValue = 0; //foreach (var item in block.BlockList) //{ // if (maxValue < item.Y) // { // maxValue = item.Y; // } //} #endregion var maxValueLinq = block.BlockList.Max(x => x.Y); var maxValueOnField = maxValueLinq + block.Y; var bottomBlocks = block.BlockList.Where(x => x.Y == maxValueLinq).ToList(); var canMoveDown = true; foreach (var bottomsBlockItem in bottomBlocks) { var yValue = bottomsBlockItem.Y + block.Y; var xValue = bottomsBlockItem.X + block.X; if (yValue + 1 < 25) { if (panelArray[bottomsBlockItem.Y + block.Y + 1, bottomsBlockItem.X + block.X].IsFix) { canMoveDown = false; } else if (panelArray[bottomsBlockItem.Y + block.Y, bottomsBlockItem.X + block.X].IsFix) { canMoveDown = false; } } } if (maxValueOnField < 24 && canMoveDown) { block.Y += 1; // <---------------------------------------------------------------------------------------- hier wird y + 1 gemacht(nach unten bewegt) } else { block = neuerBlock; //<---------------------------------------------- hier wird dem block, der block der Vorschau (unten rechts)zugewiesen neuerBlock = GameHelper.GetBlockItem(); } UpdateGui(); this.Invalidate(); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { var mainItem = block.BlockList.First(x => x.MainItem); var leftexists = block.BlockList.Any(x => x.X == mainItem.X - 1); var zweiLeftexists = block.BlockList.Any(x => x.X == mainItem.X - 2); var rightexists = block.BlockList.Any(x => x.X == mainItem.X + 1); var zweirightexists = block.BlockList.Any(x => x.X == mainItem.X + 2); if (!block.BlockList.Any(x => x.Y + block.Y < 0)) { #region keinerLinks if (e.KeyCode == Keys.Left && leftexists == false) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) // hier sagt es der y wert ist zu niedrig (bei -1) ist iwas mit dem item.Y flasch glaube ich { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 0) { block.X = block.X - 1; } } } #endregion #region einerLinks if (e.KeyCode == Keys.Left && leftexists == true && zweiLeftexists == false) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y + 1 }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 1) { block.X = block.X - 1; } } } #endregion #region zweiLinks if (e.KeyCode == Keys.Left && zweiLeftexists == true) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 3) { block.X = block.X - 1; } } } #endregion #region keinerRechts if (e.KeyCode == Keys.Right && rightexists == false) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 14) { block.X = block.X + 1; } } } #endregion #region einerRechts if (e.KeyCode == Keys.Right && rightexists == true && zweirightexists == false) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 13) { block.X = block.X + 1; } } } #endregion #region zweiRechts if (e.KeyCode == Keys.Right && zweirightexists == true) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List <Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 12) { block.X = block.X + 1; } } } #endregion } if (e.KeyCode == Keys.Down) { timer1.Enabled = true; timer1.Interval = 15; } if (e.KeyCode == Keys.A) { //Rotation if (block.BlockType == BlockType.DiceBlock || block.X > 13 || block.X < 2 || block.BlockType == BlockType.IBlock && block.X > 12 || block.BlockType == BlockType.LBlockLeft && block.X > 12 || block.BlockType == BlockType.LBlockRight && block.X > 12) // -> damit es nicht gedreht werden kann wenn der x wert zu hoch bzw zu niedrig ist { //mach nichts, da dieser Block sich nicht dreht } else { var nextDirection = GameHelper.GetNextDirection(block.Direction); var newBlock = GameHelper.GetBlockByTypeAndDirection(block.BlockType, nextDirection); newBlock.X = block.X; newBlock.Y = block.Y; block = newBlock; } } #region CheatjfF if (e.KeyCode == Keys.VolumeMute && block.BlockType == BlockType.DiceBlock) { if (s == 0) { MessageBox.Show("Cheat Aktiviert! (PunkteBonus)"); int a = Convert.ToInt32(labelAusgabePunkte.Text); int b = a + 600; labelAusgabePunkte.Text = Convert.ToString(b); s++; } else { int a = Convert.ToInt32(labelAusgabePunkte.Text); int b = a + 600; labelAusgabePunkte.Text = Convert.ToString(b); s++; } } if (e.KeyCode == Keys.C) { i++; if (i == 1) { tableLayoutPanel1.BackColor = Color.GreenYellow; } else if (i == 2) { tableLayoutPanel1.BackColor = Color.Blue; } else if (i == 3) { tableLayoutPanel1.BackColor = Color.HotPink; } else if (i == 4) { tableLayoutPanel1.BackColor = Color.OrangeRed; } else if (i == 5) { tableLayoutPanel1.BackColor = Color.Gold; } else if (i == 6) { tableLayoutPanel1.BackColor = Color.DarkOrchid; } else { tableLayoutPanel1.BackColor = tableLayoutPanel1.ForeColor; i = i - 7; } } #endregion }
//Methode GetBlock By BlockType & Direction public static BlockItem GetBlockByTypeAndDirection(BlockType blocktype, Direction direction) { #region GetNewDirectionLBlockRight if (blocktype == BlockType.LBlockRight && direction == Direction.Right) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockRight && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockRight && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -2, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockRight && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 2, Y = 0, MainItem = false }); return myblockItem; } #endregion #region GetNewDirectionIBlock if (blocktype == BlockType.IBlock && direction == Direction.Right) { //hier jetzt die werte des hellblauen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.IBlock && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = -1, Y = 0, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.IBlock && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -2, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.IBlock && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); return myblockItem; } #endregion #region GetNewDirectionLBlockLeft if (blocktype == BlockType.LBlockLeft && direction == Direction.Right) { //hier jetzt die werte des orangenen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 1, Y = 0, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -2, Y = 0, MainItem = false }); return myblockItem; } #endregion #region GetNewDirectionSBlockRight if (blocktype == BlockType.SBlockRight && direction == Direction.Right) { //hier jetzt die werte des grünen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockRight && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = -1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockRight && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = -1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockRight && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = -1, MainItem = false }); return myblockItem; } #endregion #region GetNewDirectionPyramidBlock if (blocktype == BlockType.PyramidBlock && direction == Direction.Right) { //hier jetzt die werte des lilanen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); return myblockItem; } #endregion #region GetNewDirectionSBlockLeft if (blocktype == BlockType.SBlockLeft && direction == Direction.Right) { //hier jetzt die werte des lilanen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = -1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 1, MainItem = false }); return myblockItem; } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List<Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = -1, MainItem = false }); return myblockItem; } return null; #endregion }
public static BlockItem GetBlockItem() { var myblockItem = new BlockItem() { X = 7, Y = 0, //start position Direction = Direction.Up }; myblockItem.BlockList = new List<Block>(); //todo: ds direkteingabe var zufallsZahl = randomZahl.Next(1, 8); //auswählen des Blockes von dem Computer und erstellen der Blöcke //var zufallsZahl = 2; switch (zufallsZahl) { case 1: #region Block Blue myblockItem.BlockType = BlockType.LBlockRight; myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 2, Y = 0, MainItem = false }); #endregion break; case 2: #region Block SkyBlue myblockItem.BlockType = BlockType.IBlock; myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 2, Y = 0, MainItem = false }); #endregion break; case 3: #region Block Orange myblockItem.BlockType = BlockType.LBlockLeft; myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); #endregion break; case 4: #region Block Yellow myblockItem.BlockType = BlockType.DiceBlock; myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 1, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 1, Y = 0, MainItem = false }); #endregion break; case 5: #region Block Green myblockItem.BlockType = BlockType.SBlockRight; myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = -1, MainItem = false }); #endregion break; case 6: #region Block Purple myblockItem.BlockType = BlockType.PyramidBlock; myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); #endregion break; case 7: #region Block Red myblockItem.BlockType = BlockType.SBlockLeft; myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = -1, MainItem = false }); #endregion break; default: Console.WriteLine("Ungültiger Block entdeckt"); break; } return myblockItem; }
//Methode GetBlock By BlockType & Direction public static BlockItem GetBlockByTypeAndDirection(BlockType blocktype, Direction direction) { #region GetNewDirectionLBlockRight if (blocktype == BlockType.LBlockRight && direction == Direction.Right) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockRight && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockRight && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -2, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockRight && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 2, Y = 0, MainItem = false }); return(myblockItem); } #endregion #region GetNewDirectionIBlock if (blocktype == BlockType.IBlock && direction == Direction.Right) { //hier jetzt die werte des hellblauen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.IBlock && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = -1, Y = 0, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.IBlock && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -2, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.IBlock && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = -2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 1, MainItem = false }); return(myblockItem); } #endregion #region GetNewDirectionLBlockLeft if (blocktype == BlockType.LBlockLeft && direction == Direction.Right) { //hier jetzt die werte des orangenen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 1, Y = 0, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 2, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.LBlockLeft && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -2, Y = 0, MainItem = false }); return(myblockItem); } #endregion #region GetNewDirectionSBlockRight if (blocktype == BlockType.SBlockRight && direction == Direction.Right) { //hier jetzt die werte des grünen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockRight && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = -1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockRight && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = -1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockRight && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = -1, MainItem = false }); return(myblockItem); } #endregion #region GetNewDirectionPyramidBlock if (blocktype == BlockType.PyramidBlock && direction == Direction.Right) { //hier jetzt die werte des lilanen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.PyramidBlock && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); return(myblockItem); } #endregion #region GetNewDirectionSBlockLeft if (blocktype == BlockType.SBlockLeft && direction == Direction.Right) { //hier jetzt die werte des lilanen blockes neu festlegen wenn er dann einmal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = -1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Down) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann zweimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Left) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann dreimal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = 1, MainItem = false }); return(myblockItem); } else if (blocktype == BlockType.SBlockLeft && direction == Direction.Up) { //hier jetzt die werte des blauen blockes neu festlegen wenn er dann viermal um 90° gedreht wurde also nach rechts zeigt var myblockItem = new BlockItem() { BlockType = blocktype, Direction = direction }; myblockItem.BlockList = new List <Block>(); //werte: myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = -1, MainItem = false }); return(myblockItem); } return(null); #endregion }
public static BlockItem GetBlockItem() { var myblockItem = new BlockItem() { X = 7, Y = 0, //start position Direction = Direction.Up }; myblockItem.BlockList = new List <Block>(); //todo: ds direkteingabe var zufallsZahl = randomZahl.Next(1, 8); //auswählen des Blockes von dem Computer und erstellen der Blöcke //var zufallsZahl = 2; switch (zufallsZahl) { case 1: #region Block Blue myblockItem.BlockType = BlockType.LBlockRight; myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = 0, MainItem = true, }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Blue, X = 2, Y = 0, MainItem = false }); #endregion break; case 2: #region Block SkyBlue myblockItem.BlockType = BlockType.IBlock; myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.SkyBlue, X = 2, Y = 0, MainItem = false }); #endregion break; case 3: #region Block Orange myblockItem.BlockType = BlockType.LBlockLeft; myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = -2, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Orange, X = 0, Y = -1, MainItem = false }); #endregion break; case 4: #region Block Yellow myblockItem.BlockType = BlockType.DiceBlock; myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 1, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Yellow, X = 1, Y = 0, MainItem = false }); #endregion break; case 5: #region Block Green myblockItem.BlockType = BlockType.SBlockRight; myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Green, X = 1, Y = -1, MainItem = false }); #endregion break; case 6: #region Block Purple myblockItem.BlockType = BlockType.PyramidBlock; myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = -1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Purple, X = 1, Y = 0, MainItem = false }); #endregion break; case 7: #region Block Red myblockItem.BlockType = BlockType.SBlockLeft; myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = 0, MainItem = true }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 1, Y = 0, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = 0, Y = -1, MainItem = false }); myblockItem.BlockList.Add(new Block() { Color = Color.Red, X = -1, Y = -1, MainItem = false }); #endregion break; default: Console.WriteLine("Ungültiger Block entdeckt"); break; } return(myblockItem); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { var mainItem = block.BlockList.First(x => x.MainItem); var leftexists = block.BlockList.Any(x => x.X == mainItem.X - 1); var zweiLeftexists = block.BlockList.Any(x => x.X == mainItem.X - 2); var rightexists = block.BlockList.Any(x => x.X == mainItem.X + 1); var zweirightexists = block.BlockList.Any(x => x.X == mainItem.X + 2); if (!block.BlockList.Any(x => x.Y + block.Y <0)) { #region keinerLinks if (e.KeyCode == Keys.Left && leftexists == false) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) // hier sagt es der y wert ist zu niedrig (bei -1) ist iwas mit dem item.Y flasch glaube ich { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 0) { block.X = block.X - 1; } } } #endregion #region einerLinks if (e.KeyCode == Keys.Left && leftexists == true && zweiLeftexists == false) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y + 1 }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 1) { block.X = block.X - 1; } } } #endregion #region zweiLinks if (e.KeyCode == Keys.Left && zweiLeftexists == true) { var minRightValue = block.BlockList.Min(x => x.X); var listMinItems = block.BlockList.Where(x => x.X == minRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMinItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob links was da ist var canMoveLeft = true; foreach (var item in myList) { int leftPostion; if (item.X < 0) { leftPostion = item.X - 1; } else { leftPostion = item.X; } if (panelArray[item.Y, leftPostion].IsFix) { canMoveLeft = false; } } if (canMoveLeft) { if ((block.X - mainItem.X) > 3) { block.X = block.X - 1; } } } #endregion #region keinerRechts if (e.KeyCode == Keys.Right && rightexists == false) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 14) { block.X = block.X + 1; } } } #endregion #region einerRechts if (e.KeyCode == Keys.Right && rightexists == true && zweirightexists == false) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 13) { block.X = block.X + 1; } } } #endregion #region zweiRechts if (e.KeyCode == Keys.Right && zweirightexists == true) { var maxRightValue = block.BlockList.Max(x => x.X); var listMaxItems = block.BlockList.Where(x => x.X == maxRightValue); var myList = new List<Block>(); //transofrmieren auf Spieleld foreach (var item in listMaxItems) { myList.Add(new Block { X = item.X + block.X, Y = item.Y + block.Y }); } //prüfen ob rechts was da ist var canMoveRight = true; foreach (var item in myList) { int rightPostion; if (item.X < 14) { rightPostion = item.X + 1; } else { rightPostion = item.X; } if (panelArray[item.Y, rightPostion].IsFix) { canMoveRight = false; } } if (canMoveRight) { if ((block.X + mainItem.X) < 12) { block.X = block.X + 1; } } } #endregion } if (e.KeyCode == Keys.Down) { timer1.Enabled = true; timer1.Interval = 15; } if (e.KeyCode == Keys.A) { //Rotation if (block.BlockType == BlockType.DiceBlock || block.X > 13 || block.X < 2 || block.BlockType == BlockType.IBlock && block.X > 12 || block.BlockType == BlockType.LBlockLeft && block.X > 12 || block.BlockType == BlockType.LBlockRight && block.X > 12) // -> damit es nicht gedreht werden kann wenn der x wert zu hoch bzw zu niedrig ist { //mach nichts, da dieser Block sich nicht dreht } else { var nextDirection = GameHelper.GetNextDirection(block.Direction); var newBlock = GameHelper.GetBlockByTypeAndDirection(block.BlockType, nextDirection); newBlock.X = block.X; newBlock.Y = block.Y; block = newBlock; } } #region CheatjfF if (e.KeyCode == Keys.VolumeMute && block.BlockType == BlockType.DiceBlock) { if (s == 0) { MessageBox.Show("Cheat Aktiviert! (PunkteBonus)"); int a = Convert.ToInt32(labelAusgabePunkte.Text); int b = a + 600; labelAusgabePunkte.Text = Convert.ToString(b); s++; } else { int a = Convert.ToInt32(labelAusgabePunkte.Text); int b = a + 600; labelAusgabePunkte.Text = Convert.ToString(b); s++; } } if (e.KeyCode == Keys.C) { i++; if (i == 1) { tableLayoutPanel1.BackColor = Color.GreenYellow; } else if (i == 2) { tableLayoutPanel1.BackColor = Color.Blue; } else if (i == 3) { tableLayoutPanel1.BackColor = Color.HotPink; } else if (i == 4) { tableLayoutPanel1.BackColor = Color.OrangeRed; } else if (i == 5) { tableLayoutPanel1.BackColor = Color.Gold; } else if (i == 6) { tableLayoutPanel1.BackColor = Color.DarkOrchid; } else { tableLayoutPanel1.BackColor = tableLayoutPanel1.ForeColor; i = i - 7; } } #endregion }