static void CaptureKey() { if (!Console.KeyAvailable) { return; } ConsoleKeyInfo pressedKey = Console.ReadKey(true); // = Console.ReadKey(); while (Console.KeyAvailable) // read all buffer { pressedKey = Console.ReadKey(true); } bool keyPress = false; if (pressedKey.Key == ConsoleKey.LeftArrow && playerField[bomberman.position.row, bomberman.position.col - 1] == ' ') { bomberman.position.col--; keyPress = true; } else if (pressedKey.Key == ConsoleKey.RightArrow && playerField[bomberman.position.row, bomberman.position.col + 1] == ' ') { bomberman.position.col++; keyPress = true; } else if (pressedKey.Key == ConsoleKey.UpArrow && playerField[bomberman.position.row - 1, bomberman.position.col] == ' ') { bomberman.position.row--; keyPress = true; } else if (pressedKey.Key == ConsoleKey.DownArrow && playerField[bomberman.position.row + 1, bomberman.position.col] == ' ') { bomberman.position.row++; keyPress = true; } else if (pressedKey.Key == ConsoleKey.Spacebar) { if (bombermanBombsCounter < bombermanBombsMax) { Position pos; pos.col = bomberman.position.col; pos.row = bomberman.position.row; Bomb myBomb = new Bomb(pos); bombList.Add(myBomb); DropTheBomb(myBomb); bombermanBombsCounter++; } } else if (pressedKey.Key == ConsoleKey.N) { DialogResult res = MessageBox.Show("Do you want to start new game?", "BOMBERMAN GAME", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { InitGame(); } } else if (pressedKey.Key == ConsoleKey.S) { DialogResult res = MessageBox.Show("Do you want to save game and exit?", "BOMBERMAN GAME", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) {// save game code here SaveGame(); Environment.Exit(0); } } else if (pressedKey.Key == ConsoleKey.L) { DialogResult res = MessageBox.Show("Do you want to load last saved game?", "BOMBERMAN GAME", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) {// load game from file LoadGame(); } } if (keyPress) { DrawBomberman(); Console.Beep(1000, 50); } }
static void DetonationBombs(Bomb myBomb) { Console.CursorVisible = false; Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Red; //blow up bombs code here const char detonationSymbol = '*'; int x = myBomb.position.col + playerFieldPosition.col; int y = myBomb.position.row + playerFieldPosition.row; for (int i = 1; i <= myBomb.power; i++)// down { if (playerField[myBomb.position.row + i, myBomb.position.col] == brick) { break; } // print detonationSymbol; Console.SetCursorPosition(x, y + i); Console.Write(detonationSymbol); CheckForGad(myBomb.position.row + i, myBomb.position.col); } for (int i = 1; i <= myBomb.power; i++)// up { if (playerField[myBomb.position.row - i, myBomb.position.col] == brick) { break; } // print detonationSymbol; Console.SetCursorPosition(x, y - i); Console.Write(detonationSymbol); CheckForGad(myBomb.position.row - i, myBomb.position.col); } for (int i = 1; i <= myBomb.power; i++)// left { if (playerField[myBomb.position.row, myBomb.position.col - i] == brick) { break; } // print detonationSymbol; Console.SetCursorPosition(x - i, y); Console.Write(detonationSymbol); CheckForGad(myBomb.position.row, myBomb.position.col - i); } for (int i = 1; i <= myBomb.power; i++)// right { if (playerField[myBomb.position.row, myBomb.position.col + i] == brick) { break; } // print detonationSymbol; Console.SetCursorPosition(x + i, y); Console.Write(detonationSymbol); CheckForGad(myBomb.position.row, myBomb.position.col + i); } //for (int k = 1; k < 6; k++) { Console.Beep(2000, 400); // Thread.Sleep(20); } Console.BackgroundColor = playerFieldBackgroundColor; Console.ForegroundColor = playerFieldForegroundColor; for (int i = 1; i <= myBomb.power; i++)// down { if (playerField[myBomb.position.row + i, myBomb.position.col] == brick) { break; } Console.SetCursorPosition(x, y + i); Console.Write(' '); } for (int i = 1; i <= myBomb.power; i++)// up { if (playerField[myBomb.position.row - i, myBomb.position.col] == brick) { break; } Console.SetCursorPosition(x, y - i); Console.Write(' '); } for (int i = 1; i <= myBomb.power; i++)// left { if (playerField[myBomb.position.row, myBomb.position.col - i] == brick) { break; } Console.SetCursorPosition(x - i, y); Console.Write(' '); } for (int i = 1; i <= myBomb.power; i++)// right { if (playerField[myBomb.position.row, myBomb.position.col + i] == brick) { break; } Console.SetCursorPosition(x + i, y); Console.Write(' '); } // erase bomb playerField[myBomb.position.row, myBomb.position.col] = ' '; Console.SetCursorPosition(myBomb.position.col + playerFieldPosition.col, myBomb.position.row + playerFieldPosition.row); Console.BackgroundColor = playerFieldBackgroundColor; Console.ForegroundColor = playerFieldForegroundColor; Console.Write(' ');// erase old position DrawBomberman(); CheckForGad(myBomb.position.row, myBomb.position.col); DrawBomberman(); }