Exemple #1
0
        static void InitGame()
        {
            Console.Clear();
            Console.ResetColor();
            Console.Title = "BOMBERMAN GAME";

            LogoPrint();
            InitPlayerField(playerField);
            DrawPlayerField(playerField);
            PrintLegend();

            bomberman = new Man(new Position(1, 1));
            // gad init
            gadsList.Clear();
            Gad gad = new Gad(new Position(7, 7), 1);

            gad.dir = direction.up;
            gadsList.Add(gad);

            gad.position.row = 11;
            gad.position.col = 11;
            gad.dir          = direction.down;
            gadsList.Add(gad);

            gad.position.row = 27;
            gad.position.col = 27;
            gad.dir          = direction.up;
            gadsList.Add(gad);

            gad.position.row = 27;
            gad.position.col = 31;
            gad.dir          = direction.down;
            gadsList.Add(gad);

            gad.position.row = 9;
            gad.position.col = 17;
            gad.dir          = direction.left;
            gadsList.Add(gad);

            gad.position.row = 9;
            gad.position.col = 29;
            gad.dir          = direction.right;
            gadsList.Add(gad);

            gad.position.row = 29;
            gad.position.col = 25;
            gad.dir          = direction.left;
            gadsList.Add(gad);

            gad.position.row = 25;
            gad.position.col = 3;
            gad.dir          = direction.right;
            gadsList.Add(gad);

            DrawBomberman();
            bombList.Clear();
            bombermanBombsCounter = 0;
            seconds     = 0;
            restartGame = false;
        }
Exemple #2
0
 static void PrintGad(Gad gad)
 {
     playerField[gad.position.row, gad.position.col] = gad.body;
     Console.SetCursorPosition(gad.position.col + playerFieldPosition.col, gad.position.row + playerFieldPosition.row);
     Console.BackgroundColor = gad.background;
     Console.ForegroundColor = gad.foreground;
     Console.Write(gad.body);// print bomberman
 }
Exemple #3
0
        static void CheckForGad(int y, int x)
        {
            if (restartGame)
            {
                return;
            }

            if (playerField[y, x] == bomberman.body)
            {
                bomberman.lifes--;
                Console.Beep(4000, 750);
                if (bomberman.lifes <= 0)
                {// GAME OVER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    PrintInfo();
                    bomberman.foreground = ConsoleColor.Black;
                    DrawBomberman();
                    DialogResult res = MessageBox.Show("GAME OVER!\nDo you want to start a new game?", "BOMBERMAN GAME", MessageBoxButtons.YesNo);
                    if (res == DialogResult.Yes)
                    {// start new game
                        restartGame = true;
                        //InitGame();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
            else
            {
                //Search Gad in colection
                for (int i = 0; i < gadsList.Count; i++)
                {
                    Gad current = gadsList[i];
                    if (current.position.row == y && current.position.col == x)
                    {
                        gadsList.RemoveAt(i);
                        playerField[y, x] = ' ';
                    }
                }
                if (gadsList.Count <= 0)
                {
                    DialogResult res = MessageBox.Show("YOU ARE WINNER!\nDo you want a new game?", "BOMBERMAN GAME", MessageBoxButtons.YesNo);
                    if (res == DialogResult.Yes)
                    {// start new game
                        restartGame = true;
                        //InitGame();
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
        }
Exemple #4
0
        static void MoveGads()
        {
            for (int i = 0; i < gadsList.Count; i++)
            {
                Gad current = gadsList[i];

                if (current.moveCount >= current.speed)
                {   // move UP
                    if (current.dir == direction.up)
                    {
                        if (playerField[current.position.row - 1, current.position.col] == ' ' || playerField[current.position.row - 1, current.position.col] == bomberman.body)
                        {   // erase old position
                            ErasePosition(current.position.row, current.position.col);
                            //move to new positon
                            current.position.row--;
                            CheckForGad(current.position.row, current.position.col);
                            PrintGad(current);
                        }
                        else
                        {
                            current.dir = direction.down;
                        }
                    }
                    else if (current.dir == direction.down)
                    {
                        if (playerField[current.position.row + 1, current.position.col] == ' ' || playerField[current.position.row + 1, current.position.col] == bomberman.body)
                        {   // erase old position
                            ErasePosition(current.position.row, current.position.col);
                            //move to new positon
                            current.position.row++;
                            CheckForGad(current.position.row, current.position.col);
                            PrintGad(current);
                        }
                        else
                        {
                            current.dir = direction.up;
                        }
                    }
                    else if (current.dir == direction.left)
                    {
                        if (playerField[current.position.row, current.position.col - 1] == ' ' || playerField[current.position.row, current.position.col - 1] == bomberman.body)
                        {   // erase old position
                            ErasePosition(current.position.row, current.position.col);
                            //move to new positon
                            current.position.col--;
                            CheckForGad(current.position.row, current.position.col);
                            PrintGad(current);
                        }
                        else
                        {
                            current.dir = direction.right;
                        }
                    }
                    else if (current.dir == direction.right)
                    {
                        if (playerField[current.position.row, current.position.col + 1] == ' ' || playerField[current.position.row, current.position.col + 1] == bomberman.body)
                        {   // erase old position
                            ErasePosition(current.position.row, current.position.col);
                            //move to new positon
                            current.position.col++;
                            CheckForGad(current.position.row, current.position.col);
                            PrintGad(current);
                        }
                        else
                        {
                            current.dir = direction.left;
                        }
                    }
                    current.moveCount = 0;
                }
                else
                {
                    current.moveCount++;
                }
                gadsList[i] = current;
                DrawBomberman();
            }
        }