Ejemplo n.º 1
0
        public override Graphic enterCommand(String command)
        {
            Player player = hb.getPlayer();
            Graphic graphic = new Graphic(player.Coord, null, "");

            Move where = Move.STALL;
            switch (command) //see if movement command
            {
                case "FORWARD": where = Move.FORWARD; break;
                case "RIGHT": where = Move.RIGHT; break;
                case "BACKWARD": where = Move.BACKWARD; break;
                case "LEFT": where = Move.LEFT; break;
            }

            if (where != Move.STALL) //It is a move command
            {
                //TODO not just a wall but maybe an elevator.
                if (!player.move(where))
                    graphic.Text = "You can't move there." + System.Environment.NewLine;
                else
                {
                    graphic.setImage(player.Coord, null);
                }
            }
            else if (command == "ENTER DOWN")
            {
                enterElevator(false, graphic); //false for Down
            }
            else if (command == "ENTER UP")
            {
                enterElevator(true, graphic); //true for Up
            }
            else if (command == "ENTER DOOR")
            {
                DoorState result = player.enterDoor();

                switch (result)
                {
                    case DoorState.UNLOCKED:
                        graphic.Text = "";
                        graphic.ExtraFlag = 1;
                        break;
                    case DoorState.LOCKED:
                        graphic.Text = "The door is locked.";
                        break;
                    case DoorState.NOTNEAR:
                        graphic.Text = "You are not near a door.";
                        break;
                    default:
                        graphic.Text = "This should not happen.";
                        break;
                }
            }
            else if (command == "PICKUP")
            {
                Item i = player.pickup();
                graphic.Text = "You picked up " + (i != null ? i.name() : "nothing") + System.Environment.NewLine;
                if (i != null && i.name() == "Hourglass")
                {
                    graphic.ExtraFlag = ((Hourglass)i).getMoreTime();
                    graphic.Text += "+" + graphic.ExtraFlag + " secs" + System.Environment.NewLine;
                }
            }
            else if (command == "INVT")
            {
                graphic.Text = "You are carrying: " + player.showInventory() + System.Environment.NewLine;
            }
            else if (command == "INSPECT")
            {
                graphic.Text = player.inspectItems() + System.Environment.NewLine;
            }
            else if (command == "FLASHLIGHT")
            {
                //reveal surrounding areas
                graphic.Text = "Used Flashlight." + System.Environment.NewLine;
                graphic.setImage(player.Coord, player.useFlashLight(graphic));
            }

            return graphic;
        }
Ejemplo n.º 2
0
        //Command ENTER UP & ENTER Down helper
        private void enterElevator(bool up, Graphic graphic)
        {
            Player player = hb.getPlayer();
            Floor[] floors = hb.getFloors();
            CorrectElevator[] correct_elevator = hb.getCorrectElevators();
            WrongElevator[] wrong_elevator = hb.getWrongElevators();

            int currX = player.Coord.x;
            int currY = player.Coord.y;
            int currfloor = player.Floor.Number - 1;
            int newFloor = player.Floor.Number - 1;
            int flag = -1;

            if (correct_elevator[currfloor].isThereElevator(currX, currY))
            {
                //An attempt to go up or down a correct elevator is made and an elevator exists
                if (up ? correct_elevator[currfloor].canGoUp() : correct_elevator[currfloor].canGoDown())
                {
                    int lastFloor = correct_elevator[currfloor].getLast();
                    int nextFloor = correct_elevator[currfloor].getNext();

                    //determined that you are out of sequence
                    if ( (player.getLastFloor() == lastFloor) || (player.getLastFloor() == nextFloor))
                    {
                        //obtain the nextfloor in sequence
                        newFloor = up ? correct_elevator[currfloor].go_up() : correct_elevator[currfloor].go_down();
                        newFloor--;

                        //save the last floor of where the player was
                        player.UpdateLastFloor(currfloor+1);
                        flag = 2;
                    }
                    else
                    {
                        flag = 0;
                    }

                }
                else
                    flag = 1;
            }

            if (wrong_elevator[currfloor].isThereElevator(currX, currY))    //ive yet to work on it
            {
                //the last and next elevator that is correct in
                int lastCorrect = correct_elevator[currfloor].getLast();
                int nextCorrect = correct_elevator[currfloor].getNext();

                if (up ? wrong_elevator[currfloor].canGoUp() : wrong_elevator[currfloor].canGoDown())
                {
                    //We want to avoid sending a player to a correct floor and thus allowing entrance to a correct elevator
                    do
                    {
                        //obtain a random floor to go to.
                        newFloor = up ? wrong_elevator[currfloor].go_up() : wrong_elevator[currfloor].go_down();
                    } while ((newFloor == lastCorrect) || (newFloor == nextCorrect));

                    newFloor--;

                    //save the last floor of where the player was
                    if (newFloor == 9) { player.UpdateLastFloor(-1); } //allows for another chance to reach the first floor in sequence
                    else { player.UpdateLastFloor(currfloor + 1); }

                    flag = 2;
                }
                else
                    flag = 1;
            }

            switch (flag)
            {
                case 2: //Elevator taken
                    player.dropItems();
                    player.Floor = floors[newFloor];                   //set the new floor
                    player.Coord = player.Floor.randElevatorCoord();

                    graphic.Text = "Taking Elevator..." + System.Environment.NewLine;
                    graphic.Text = "Came from elevator " + (player.getLastFloor()) + System.Environment.NewLine;

                    graphic.setImage(player.Coord, null);
                    break;
                case 1: //Elevator limit reached
                    graphic.Text = "You can't go further " + (up ? "up." : "down.");
                    break;
                case 0: //Attempting to take correct elevator out of sequence
                    graphic.Text = "Unfortunately you can't take this elevator! (out of sequence)" + System.Environment.NewLine;
                    break;
                default:
                    graphic.Text = "You are not near an elevator! You are at " + player.stringCoord() + System.Environment.NewLine;
                    break;
            }
        }
Ejemplo n.º 3
0
        //Return a list of NamedCoord that are near the current player's coordinate;
        public ArrayList useFlashLight(Graphic graphic)
        {
            ArrayList marks = new ArrayList();

            foreach (NamedCoord mark in floor.Coordinates)
            {
                if (nearMe(mark.coord))
                {
                    marks.Add(mark);
                    if (mark.name == "Monster")
                    {
                        graphic.Text += "Monster!" + System.Environment.NewLine;
                    }
                }
            }

            return marks;
        }