Esempio n. 1
0
 //Create public method "Move(Vector2D direction)" to move the object in the given direction
 public virtual void Move(Vector2D direction)
 {
     if (direction.X <= 1 && direction.X >= -1 && direction.Y <= 1 && direction.Y >= -1)
     {
         position += direction;
     }
 }
Esempio n. 2
0
        private static List<GameObject> BuildBoxObjectsList()
        {
            List<GameObject> objectsList = new List<GameObject>();

            foreach (int[] objParams in MapBuilder.AbstractMap.GameObjects["box"])
            {
                int x = objParams[0];
                int y = objParams[1];
                Vector2D coordinates = new Vector2D(x, y);
                objectsList.Add(new Box(coordinates));
            }

            return objectsList;
        }
Esempio n. 3
0
        public ConsoleRenderer(int visibleConsoleRows, int visibleConsoleCols, Vector2D origin)
        {
            renderContextMatrix = new char[visibleConsoleRows, visibleConsoleCols];

            this.renderContextMatrixRows = renderContextMatrix.GetLength(0);
            this.renderContextMatrixCols = renderContextMatrix.GetLength(1);
            this.origin = origin;

            Console.Title = "Sokoban";
            Console.CursorVisible = false;
            Console.OutputEncoding = UnicodeEncoding.Unicode;
            this.ClearQueue();
            this.Clear();
        }
Esempio n. 4
0
 public bool Equals(Vector2D otherVector)
 {
     return (this.X == otherVector.X && this.Y == otherVector.Y);
 }
Esempio n. 5
0
 // Methods
 // --- Constructors
 public Player(Vector2D position, int playerCount)
     : base(position)
 {
     this.body = images[playerCount % 2];
 }
Esempio n. 6
0
        private static Vector2D BuildSize()
        {
            int width = MapBuilder.AbstractMap.Size[0];
            int height = MapBuilder.AbstractMap.Size[1];
            Vector2D size = new Vector2D(width, height);

            return size;
        }
Esempio n. 7
0
        private static List<GameObject> BuildPlayerObjectsList()
        {
            List<GameObject> objectsList = new List<GameObject>();

            foreach (int[] objParams in MapBuilder.AbstractMap.GameObjects["player"])
            {
                int x = objParams[0];
                int y = objParams[1];
                Vector2D coordinates = new Vector2D(x, y);
                objectsList.Add(new Player(coordinates, MapBuilder.AbstractMap.GameObjects["player"].Count));
            }

            return objectsList;
        }
Esempio n. 8
0
        private static Vector2D BuildOrigin()
        {
            int x = MapBuilder.AbstractMap.Origin[0];
            int y = MapBuilder.AbstractMap.Origin[1];
            Vector2D origin = new Vector2D(x, y);

            return origin;
        }
Esempio n. 9
0
 protected GameObject(Vector2D position)
 {
     this.position = position;
     this.body = ' ';
     this.IsVisible = true;
 }
Esempio n. 10
0
        protected StaticObject(Vector2D position)
            : base(position)
        {

        }
Esempio n. 11
0
 protected MoveableObject(Vector2D position)
     : base(position)
 {
 }
Esempio n. 12
0
 //Wrapper method for all methods executed when objects move
 private void PerformMove(Vector2D direction, int playerType)
 {
     HandleCollisions(direction,playerType);
     DetermineTargetVisibility();
     RenderAllObjects();
     hasPlayerWon = Referee.CheckForWin(allObjects["target"], allObjects["box"]);
 }
Esempio n. 13
0
        //Move objects according to collision occurrence
        private void HandleCollisions(Vector2D direction, int playerType)
        {
            //Get a player refference
            Player player;
            if (allObjects.Keys.Contains("player"))
            {
                if (playerType != 0)
                {
                    if (allObjects["player"].Count <= 1)
                    {
                        return;
                    }
                    player = (Player)allObjects["player"][playerType % 2];
                }
                else
                {
                    player = (Player)allObjects["player"][0];
                }
            }
            else
            {
                throw new ArgumentException("No players in game");
            }

            List<GameObject> movingObjects = new List<GameObject>(); //Objects that are enqueued to be moved
            List<GameObject> movedObjects = new List<GameObject>();  //Objects that have already been moved

            movingObjects.Add(player);
            int count = 0; // Number of boxes that have once been added to movingObjects list.
            bool collisionFound = false;

            //Perform moving objects
            while (movingObjects.Count > 0 && count <= NumberPushableBoxes && !collisionFound)
            {
                MoveableObject objectToMove = (MoveableObject)movingObjects.ElementAt(0); //Take the first object that has to be moved
                movingObjects.RemoveAt(0); //Remove that object from the list
                objectToMove.Move(direction); //Move the object
                movedObjects.Add(objectToMove); //Add the object to movedObjects list
                List<GameObject> walls = CollisionDetector.CheckForCollision(objectToMove, allObjects["wall"]); //Check for collisions with walls
                List<GameObject> otherPlayers = CollisionDetector.CheckForCollision(objectToMove, allObjects["player"]); //Check for collisions with other players

                if (walls.Count > 0 || otherPlayers.Count > 0)
                {
                    collisionFound = true;
                }

                List<GameObject> boxes = CollisionDetector.CheckForCollision(objectToMove, allObjects["box"]); //Check for collisions with boxes
                movingObjects.AddRange(boxes);
                count += boxes.Count;
            }

            //Check if moving objects is valid. If not - move them back.
            if (movingObjects.Count > 0 || collisionFound)
            {
                Vector2D oppositeDirection = direction * (-1);
                foreach (MoveableObject obj in movedObjects) //Could occur problem because movedObjects are GameObjects
                {
                    obj.Move(oppositeDirection);
                }
            }
        }
Esempio n. 14
0
 // Methods
 // --- Constructors
 public Target(Vector2D position)
     : base(position)
 {
     this.body = 'x';
 }
Esempio n. 15
0
File: Box.cs Progetto: Bezideiko/OOP
 // Methods
 // --- Constructors
 public Box(Vector2D position)
     : base(position)
 {
     this.body = '\u25a0';
 }
Esempio n. 16
0
 // Methods
 // --- Constructors
 public Wall(Vector2D position)
     : base(position)
 {
     this.body = '\u2593';
 }