示例#1
0
        public void generateBoard(int board, int xDimension, int yDimension, int limitX, int limitY, int limObstacles, int limEnemys)
        {
            Console.WriteLine("Generando tablero...");
            this.board  = board; this.limitX = limitX; this.limitY = limitY; this.obstacles = limObstacles;
            this.enemys = limEnemys; this.xD = xDimension; this.yD = yDimension;
            int star = 1, currObstacles = 1, currEnemys = 1;

            board1 = new MatrixObject[xDimension, yDimension];
            for (int y = 0; y <= limitY; y++)
            {
                for (int x = 0; x <= limitX; x++)
                {
                    MatrixObject objecto = new MatrixObject(0, y, x, " ");
                    board1[y, x] = objecto;
                }
            }
            currentCharacter  = new Character(name, 5, 3, limitX, 0, "%");
            board1[0, limitX] = currentCharacter;
            while (star <= 1)
            {
                int randX = random.generateRandomX(board);
                int randY = random.generateRandomY(board);
                if (board1[randX, randY].getSimbol().Equals(" "))
                {
                    Star nuevaEstrella = new Star(2, randY, randX, "*");
                    board1[randX, randY] = nuevaEstrella;
                    star++;
                }
            }

            while (currObstacles <= limObstacles)
            {
                int randX = random.generateRandomX(board);
                int randY = random.generateRandomY(board);
                if (board1[randX, randY].getSimbol().Equals(" ") &&
                    isStarAlone(randX, randY, limitX, limitY))
                {
                    Obstacle nuevoObstaculo = new Obstacle(1, randY, randX, "O");
                    board1[randX, randY] = nuevoObstaculo;
                    currObstacles++;
                }
            }
            while (currEnemys <= limEnemys)
            {
                int randX = random.generateRandomX(board);
                int randY = random.generateRandomY(board);
                if (board1[randX, randY].getSimbol().Equals(" "))
                {
                    Enemy nuevoEnemigo = new Enemy(-1, randY, randX, "X");
                    board1[randX, randY] = nuevoEnemigo;
                    currEnemys++;
                }
            }
            Console.WriteLine("Tablero generado correctamente");
        }
示例#2
0
        public void commandMenu()
        {
            Console.WriteLine("Ingrese un comando");
            Console.WriteLine("1. Mover a la derecha");
            Console.WriteLine("2. Mover a la izquierda");
            Console.WriteLine("3. Mover arriba");
            Console.WriteLine("4. Mover abajo");
            Console.WriteLine("5. Atacar a la izquierda");
            Console.WriteLine("6. Atacar a la derecha");
            Console.WriteLine("7. Atacar arriba");
            Console.WriteLine("8. Atacar abajo");
            Console.WriteLine("9. Regresar");
            option = Console.ReadLine();
            switch (option)
            {
            case "1":
                if (currentCharacter.getX() + 1 > limitX)
                {
                    Console.WriteLine("No se puede salir de los margenes del tablero");
                    Console.WriteLine("Se le restará 1 punto al personaje");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }

                    GameMenu();
                }
                else if (board1[currentCharacter.getX() + 1, currentCharacter.getY()].getSimbol().Equals(" "))
                {
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX(), " ");

                    board1[currentCharacter.getX(), currentCharacter.getY()] = objecto;
                    currentCharacter.setX(currentCharacter.getX() + 1);
                    board1[currentCharacter.getX(), currentCharacter.getY()] = currentCharacter;
                    Console.WriteLine("Se movio el personaje a la posicion; X: " + currentCharacter.getX() +
                                      ", Y: " + currentCharacter.getY());
                    GameMenu();
                }
                else if (board1[currentCharacter.getX() + 1, currentCharacter.getY()].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Se ha encontrado con un enemigo, se le restará 1 punto de vida");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }
                }
                else if (board1[currentCharacter.getX() + 1, currentCharacter.getY()].getSimbol().Equals("O"))
                {
                    Console.WriteLine("Se ha encontrado con un obstaculo, permancerá donde está");
                    GameMenu();
                }
                else if (board1[currentCharacter.getX() + 1, currentCharacter.getY()].getSimbol().Equals("*"))
                {
                    Console.WriteLine("***************Encontró la estrella********************");
                    nextLevel(xD, yD, obstacles, enemys);
                }

                break;

            case "2":
                if (currentCharacter.getX() - 1 < 0)
                {
                    Console.WriteLine("No se puede salir de los margenes del tablero");
                    Console.WriteLine("Se le restará 1 punto al personaje");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }
                    GameMenu();
                }
                else if (board1[currentCharacter.getX() - 1, currentCharacter.getY()].getSimbol().Equals(" "))
                {
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX(), " ");

                    board1[currentCharacter.getX(), currentCharacter.getY()] = objecto;
                    currentCharacter.setX(currentCharacter.getX() - 1);
                    board1[currentCharacter.getX(), currentCharacter.getY()] = currentCharacter;
                    Console.WriteLine("Se movio el personaje a la posicion; X: " + currentCharacter.getX() +
                                      ", Y: " + currentCharacter.getY());
                    GameMenu();
                }
                else if (board1[currentCharacter.getX() - 1, currentCharacter.getY()].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Se ha encontrado con un enemigo, se le restará 1 punto de vida");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }
                }
                else if (board1[currentCharacter.getX() - 1, currentCharacter.getY()].getSimbol().Equals("O"))
                {
                    Console.WriteLine("Se ha encontrado con un obstaculo, permancerá donde está");
                    GameMenu();
                }
                else if (board1[currentCharacter.getX() - 1, currentCharacter.getY()].getSimbol().Equals("*"))
                {
                    Console.WriteLine("***************Encontró la estrella********************");
                    nextLevel(xD, yD, obstacles, enemys);
                }
                break;

            case "3":
                if (currentCharacter.getY() - 1 > limitY)
                {
                    Console.WriteLine("No se puede salir de los margenes del tablero");
                    Console.WriteLine("Se le restará 1 punto al personaje");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }

                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() - 1].getSimbol().Equals(" "))
                {
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX(), " ");

                    board1[currentCharacter.getX(), currentCharacter.getY()] = objecto;
                    currentCharacter.setY(currentCharacter.getY() - 1);
                    board1[currentCharacter.getX(), currentCharacter.getY()] = currentCharacter;
                    Console.WriteLine("Se movio el personaje a la posicion; X: " + currentCharacter.getX() +
                                      ", Y: " + currentCharacter.getY());
                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() - 1].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Se ha encontrado con un enemigo, se le restará 1 punto de vida");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }
                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() - 1].getSimbol().Equals("O"))
                {
                    Console.WriteLine("Se ha encontrado con un obstaculo, permancerá donde está");
                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() - 1].getSimbol().Equals("*"))
                {
                    Console.WriteLine("***************Encontró la estrella********************");
                    nextLevel(xD, yD, obstacles, enemys);
                }
                break;

            case "4":
                if (currentCharacter.getY() + 1 > limitX)
                {
                    Console.WriteLine("No se puede salir de los margenes del tablero");
                    Console.WriteLine("Se le restará 1 punto al personaje");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }

                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() + 1].getSimbol().Equals(" "))
                {
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX(), " ");

                    board1[currentCharacter.getX(), currentCharacter.getY()] = objecto;
                    currentCharacter.setY(currentCharacter.getY() + 1);
                    board1[currentCharacter.getX(), currentCharacter.getY()] = currentCharacter;
                    Console.WriteLine("Se movio el personaje a la posicion; X: " + currentCharacter.getX() +
                                      ", Y: " + currentCharacter.getY());
                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() + 1].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Se ha encontrado con un enemigo, se le restará 1 punto de vida");
                    if (gameOver(currentCharacter.getLife() - 1))
                    {
                        restartGame();
                    }
                    else
                    {
                        currentCharacter.setLife(currentCharacter.getLife() - 1);
                    }
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() + 1].getSimbol().Equals("O"))
                {
                    Console.WriteLine("Se ha encontrado con un obstaculo, permancerá donde está");
                    GameMenu();
                }
                else if (board1[currentCharacter.getX(), currentCharacter.getY() + 1].getSimbol().Equals("*"))
                {
                    Console.WriteLine("***************Encontró la estrella********************");
                    nextLevel(xD, yD, obstacles, enemys);
                }
                break;

            case "5":
                if (currentCharacter.getX() - 1 < 0)
                {
                    Console.WriteLine("No hay ningun enemigo en esta posición");
                    GameMenu();
                }

                else if (board1[currentCharacter.getX() - 1, currentCharacter.getY()].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Ha eliminado a un enemigo");
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX() - 1, " ");
                    board1[currentCharacter.getX() - 1, currentCharacter.getY()] = objecto;

                    GameMenu();
                }
                else
                {
                    Console.WriteLine("El ataque no tuvo efecto");
                    GameMenu();
                }

                break;

            case "6":
                if (currentCharacter.getX() + 1 > limitX)
                {
                    Console.WriteLine("No hay ningun enemigo en esta posicion");
                    GameMenu();
                }

                else if (board1[currentCharacter.getX() + 1, currentCharacter.getY()].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Ha eliminado a un enemigo");
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY(), currentCharacter.getX() + 1, " ");
                    board1[currentCharacter.getX() + 1, currentCharacter.getY()] = objecto;

                    GameMenu();
                }
                else
                {
                    Console.WriteLine("El ataque no tuvo efecto");
                    GameMenu();
                }
                break;

            case "7":
                if (currentCharacter.getY() - 1 < 0)
                {
                    Console.WriteLine("No hay ningun enemigo en esta posicion");
                    GameMenu();
                }

                else if (board1[currentCharacter.getX(), currentCharacter.getY() - 1].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Ha eliminado a un enemigo");
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY() - 1, currentCharacter.getX(), " ");
                    board1[currentCharacter.getX(), currentCharacter.getY() - 1] = objecto;

                    GameMenu();
                }
                else
                {
                    Console.WriteLine("El ataque no tuvo efecto");
                    GameMenu();
                }
                break;

            case "8":
                if (currentCharacter.getY() + 1 > limitY)
                {
                    Console.WriteLine("No hay ningun enemigo en esta posicion");
                    GameMenu();
                }

                else if (board1[currentCharacter.getX(), currentCharacter.getY() + 1].getSimbol().Equals("X"))
                {
                    Console.WriteLine("Ha eliminado a un enemigo");
                    MatrixObject objecto = new MatrixObject(0, currentCharacter.getY() + 1, currentCharacter.getX(), " ");
                    board1[currentCharacter.getX(), currentCharacter.getY() + 1] = objecto;

                    GameMenu();
                }
                else
                {
                    Console.WriteLine("El ataque no tuvo efecto");
                    GameMenu();
                }
                break;

            case "9":
                GameMenu();
                break;

            default:
                invalidOption(4);
                break;
            }
        }