コード例 #1
0
        /**
         * Makes the Minotaurs turn given a gameboard and entity positions.
         * Minotaur movement logic: primary movement left/right secondary movement up/down. seek Theseus where possible -else back up a step or two
         * if T.theY = M.theY dont worry about left/right
         * elseif T.theY > M.theY, go right
         * else
         */
        private static bool MinotaurTurn(ref GameBoard board, ref Dictionary <EntityType, Point> entities)
        {
            // minotaur seeking ai now?
            Direction direction = Direction.Omit;

            if (entities[EntityType.Theseus].X < entities[EntityType.Minotaur].X)
            {
                direction = Direction.Left;
            }
            if (entities[EntityType.Theseus].X > entities[EntityType.Minotaur].X)
            {
                direction = Direction.Right;
            }
            // is desired movement permissable?
            if (MoveUtil.CanMakeMove(ref board, EntityType.Minotaur, ref entities, direction))
            {
                if (direction == Direction.Left)
                {
                    entities[EntityType.Minotaur] = new Point(entities[EntityType.Minotaur].X - 1, entities[EntityType.Minotaur].Y);
                    return(true);
                }
                else if (direction == Direction.Right)
                {
                    entities[EntityType.Minotaur] = new Point(entities[EntityType.Minotaur].X + 1, entities[EntityType.Minotaur].Y);
                    return(true);
                }
            }

            direction = Direction.Omit;

            if (entities[EntityType.Theseus].Y < entities[EntityType.Minotaur].Y)
            {
                direction = Direction.Up;
            }
            if (entities[EntityType.Theseus].Y > entities[EntityType.Minotaur].Y)
            {
                direction = Direction.Down;
            }
            // is desired movement permissable?
            if (MoveUtil.CanMakeMove(ref board, EntityType.Minotaur, ref entities, direction))
            {
                if (direction == Direction.Up)
                {
                    entities[EntityType.Minotaur] = new Point(entities[EntityType.Minotaur].X, entities[EntityType.Minotaur].Y - 1);
                    return(true);
                }
                else if (direction == Direction.Down)
                {
                    entities[EntityType.Minotaur] = new Point(entities[EntityType.Minotaur].X, entities[EntityType.Minotaur].Y + 1);
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        /**
         * Given a game board, entity positions and a direction that theseus wants to move in either perform or not.
         * Includes call to minotaurs turns.
         */
        public static bool TheseusTurn(ref GameBoard board, ref Dictionary <EntityType, Point> entities, Direction direction)
        {
            bool move = false;

            // can theseus make the turn?
            // cross reference arrow keys or WASD keys against validated move options
            // if valid and asked for commit the move, and turn -1. If invalid do we give user feedback? but still has tun to try different direction

            // when Theseus had a turn run comparison (is Entity.theX == theExit.theX && Entity.theY == theExit.theY?) if so level is over;
            //      else: the minotaur must now move(twice).
            // if (MinotaurTurn(board, entities)) MinotaurTurn(board, entities);

            if (MoveUtil.CanMakeMove(ref board, EntityType.Theseus, ref entities, direction))
            {
                if (direction == Direction.Left)
                {
                    entities[EntityType.Theseus] = new Point(entities[EntityType.Theseus].X - 1, entities[EntityType.Theseus].Y);
                }
                else if (direction == Direction.Right)
                {
                    entities[EntityType.Theseus] = new Point(entities[EntityType.Theseus].X + 1, entities[EntityType.Theseus].Y);
                }
                else if (direction == Direction.Up)
                {
                    entities[EntityType.Theseus] = new Point(entities[EntityType.Theseus].X, entities[EntityType.Theseus].Y - 1);
                }
                else if (direction == Direction.Down)
                {
                    entities[EntityType.Theseus] = new Point(entities[EntityType.Theseus].X, entities[EntityType.Theseus].Y + 1);
                }

                move = true;
            }

            if (MinotaurTurn(ref board, ref entities))
            {
                MinotaurTurn(ref board, ref entities);
            }
            return(move);
        }