Exemplo n.º 1
0
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="myCell"></param>
        /// <param name="myGameUI"></param>
        /// <param name="myPuzzleLocation"></param>
        /// <param name="myDepth"></param>
        public NodeCell(GameUI myGameUI, Cell myCell, VectorInt myPuzzleLocation, int myDepth)
            : base(myGameUI, myDepth)
        {
            Cell = myCell;
            puzzleLocation = myPuzzleLocation;
            Size = GameUI.GameCoords.GlobalTileSize;

            CurrentAbsolute = GameUI.GameCoords.PositionAbsoluteFromPuzzle(puzzleLocation);
            if (CurrentAbsolute == null) throw new InvalidOperationException();

            DockPoint = DockPoint.TopLeft;

            switch (myCell)
            {
                case (Cell.Void):
                    TileImage = GameUI.ResourceManager["Void"].LoadBitmap();
                    break;
                case (Cell.Floor):
                    TileImage = GameUI.ResourceManager["Floor"].LoadBitmap();
                    break;
                case (Cell.Crate):
                    TileImage = GameUI.ResourceManager["Crate"].LoadBitmap();
                    break;
                case (Cell.Player):
                    TileImage = GameUI.ResourceManager["Player"].LoadBitmap();
                    break;
                case (Cell.Goal):
                    TileImage = GameUI.ResourceManager["Goal"].LoadBitmap();
                    break;
                case (Cell.Wall):
                    TileImage = GameUI.ResourceManager["Wall"].LoadBitmap();
                    break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Strong Construction
 /// </summary>
 /// <param name="aGameUI"></param>
 public GameCoords(GameUI aGameUI)
 {
     GameUI = aGameUI;
     GlobalOffset = new VectorInt(10, 30);
     GlobalTileSize = new SizeInt(16, 16);
     windowRegion =  new RectangleInt(new VectorInt(0, 0), new SizeInt(400, 300));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="myCell"></param>
        /// <param name="myGameUI"></param>
        /// <param name="myPuzzleLocation"></param>
        /// <param name="myDepth"></param>
        public NodeCell(GameUI myGameUI, Cell myCell, VectorInt myPuzzleLocation, int myDepth)
            : base(myGameUI, myDepth)
        {
            Cell = myCell;
            puzzleLocation = myPuzzleLocation;
            Size = GameUI.GameCoords.GlobalTileSize;

            CurrentAbsolute = GameUI.GameCoords.PositionAbsoluteFromPuzzle(puzzleLocation);
            if (CurrentAbsolute.IsNull) throw new InvalidOperationException();

            DockPoint = DockPoint.TopLeft;

            switch (myCell)
            {
                case (Cell.Void):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTileVoid].DataAsImage;
                    break;
                case (Cell.Floor):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTileFloor].DataAsImage;
                    break;
                case (Cell.Crate):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTileCrate].DataAsImage;
                    break;
                case (Cell.Player):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTilePlayer].DataAsImage;
                    break;
                case (Cell.Goal):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTileGoal].DataAsImage;
                    break;
                case (Cell.Wall):
                    TileImage = GameUI.ResourceFactory[ResourceID.GameTileWall].DataAsImage;
                    break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Default construction
        /// </summary>
        public StaticImage(ResourceManager resource, VectorInt tileSize)
        {
            this.tileSize = tileSize;
            Resources = resource;

            InitTiles();
        }
Exemplo n.º 5
0
 public NodeEffectCircle(GameUI myGameUI, int myDepth, VectorInt myPos)
     : base(myGameUI, myDepth)
 {
     CurrentAbsolute = myPos;
     Path = new Linear(new VectorInt(10, 10), new VectorInt(32, 32), new VectorDouble(1, 1), false);
     pen = new Pen(Color.Goldenrod, 1.5f);
 }
Exemplo n.º 6
0
 public Linear(VectorInt aCurrent, VectorInt aTarget, VectorDouble aStep, bool useBounce)
 {
     _Start = new VectorDouble(aCurrent.X, aCurrent.Y);
     _Current = new VectorDouble(aCurrent.X, aCurrent.Y);
     _Target = _Start.Add(aTarget.ToVectorDouble());
     _Step = aStep;
     _Bounce = useBounce;
 }
Exemplo n.º 7
0
        public VectorDouble GetPhysFromLogical(VectorInt i)
        {
            var v = grid.Children[0] as Image;

            var s = new VectorDouble(grid.ColumnDefinitions.First().ActualWidth,
                                  grid.RowDefinitions.First().ActualHeight);
            return new VectorDouble(i.X, i.Y).Multiply(s).Add( s.Divide(new VectorDouble(2,2))) ;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Default construction
        /// </summary>
        public StaticImage(ResourceFactory resource, VectorInt tileSize)
        {
            if (resource == null) throw new ArgumentNullException("resource");
            this.tileSize = tileSize;
            Resources = resource;

            InitTiles();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Full Constructor.
 /// </summary>
 /// <param name="myGameUI">GameUI</param>
 /// <param name="myDepth">Depth Z-order</param>
 /// <param name="brush">Text Font Brush</param>
 /// <param name="brushShaddow">Shaddow Brush (Null for none)</param>
 /// <param name="text">Message</param>
 /// <param name="font">Text Font</param>
 public NodeEffectText(GameUI myGameUI, int myDepth, string text, Font font, Brush brush, Brush brushShaddow, VectorInt start)
     : base(myGameUI, myDepth)
 {
     CurrentAbsolute = start;
     this.brush = brush;
     this.brushShaddow = brushShaddow;
     this.text = text;
     this.font = font;
     IsVisible = true;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Semi-Strong construction
        /// </summary>
        /// <param name="myGameUI">Game to which the node belongs</param>
        /// <param name="myDepth">Z-Order</param>
        public NodeBase(GameUI myGameUI, int myDepth)
        {
            if (myGameUI == null) throw new ArgumentNullException("myGameUI");

            gameUI = myGameUI;
            depth = myDepth;
            dockPoint = DockPoint.Centre;
            size = new SizeInt(0, 0);
            currentAbsolute = VectorInt.Zero;
            isRemoved = false;
        }
Exemplo n.º 11
0
        public NodePuzzleWin(GameUI myGameUI, int myDepth, VectorInt pos)
            : base(myGameUI, myDepth)
        {
            CurrentAbsolute = pos;
            chain = new ActionChain();
            chain.Add(new ActionCounter(0, 100, 2, ReSizeText));

            chain.Init();

            winner = new NodeEffectText(myGameUI, myDepth+1, "Congratz!!!", new Font("Arial", 10f), font, fontBK, pos);
            myGameUI.Add(winner);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Generate the move map for a current position
        /// </summary>
        /// <param name="boundryMap"></param>
        /// <param name="crateMap">May be null, assumes boundryMap is constraintmap</param>
        /// <param name="playerPosition"></param>
        /// <returns></returns>
        public static Bitmap GenerateMoveMap(Bitmap boundryMap, Bitmap crateMap, VectorInt playerPosition)
        {
            Bitmap constraints = boundryMap;
            if (crateMap != null) constraints = boundryMap.BitwiseOR(crateMap);

            // Flood fill from player position to remove any unreachable positions
            FloodFillStrategy floodFill = new FloodFillStrategy(constraints, playerPosition);
            Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
            eval.Evaluate(floodFill);

            return floodFill.Result;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Simple Constructor. No path, Arial 12, White, Shaddow. No path.
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string Text, VectorInt Start)
            : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;
            text = Text;
            font = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefault].DataAsFont;
            brush = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrush].DataAsBrush;
            brushShaddow = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrushShaddow].DataAsBrush;
            Path = null;
            IsVisible = true;

            UpdateSize();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Simple Constructor. No path, Arial 12, White, Shaddow. No path.
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string Text, VectorInt Start)
            : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;
            text = Text;
            font = new Font("Arial", 12, FontStyle.Bold);
            brush = new SolidBrush(Color.White);
            brushShaddow = new SolidBrush(Color.FromArgb(80,80,80));
            Path = null;
            IsVisible = true;

            UpdateSize();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Simple Constructor. Display a random message
        /// Linear Path (diagonal), Arial 12, Yellow, Shaddow. 
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string[] Text, VectorInt Start)
            : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;

            font = new Font("Arial", 12, FontStyle.Bold);
            brush = new SolidBrush(Color.Yellow);
            brushShaddow = new SolidBrush(Color.FromArgb(80, 80, 80));
            Path = new Linear(CurrentAbsolute, new VectorInt(20, 20), new VectorDouble(1, 1), false);
            text = RandomHelper.Select<string>(Text);
            IsVisible = true;

            UpdateSize();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Simple Constructor. Display a random message
        /// Linear Path (diagonal), Arial 12, Yellow, Shaddow. 
        /// </summary>
        /// <param name="myGameUI">GameUI</param>
        /// <param name="myDepth">Depth Z-order</param>
        /// <param name="Text">Display Message</param>
        /// <param name="Start">StartPosition</param>
        public NodeEffectText(GameUI myGameUI, int myDepth, string[] Text, VectorInt Start)
            : base(myGameUI, myDepth)
        {
            CurrentAbsolute = Start;

            font = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefault].DataAsFont;
            brush = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrush].DataAsBrush;
            brushShaddow = myGameUI.ResourceFactory[ResourceID.GameMiscFontDefaultBrushShaddow].DataAsBrush;
            Path = new Linear(CurrentAbsolute, new VectorInt(20, 20), new VectorDouble(1, 1), false);
            text = RandomHelper.Select<string>(Text);
            IsVisible = true;

            UpdateSize();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Find the shortest path from the player position to a destination position
        /// </summary>
        /// <param name="Map">Map</param>
        /// <param name="Destination">Destination goal position</param>
        /// <returns>NULL if no path is found</returns>
        public static List<VectorInt> FindPlayerPath(SokobanMap Map, VectorInt Destination)
        {
            Bitmap boundry = MapAnalysis.GenerateBoundryMap(Map);
            boundry = boundry.BitwiseOR(MapAnalysis.GenerateCrateMap(Map));

            // Find all positble moves for the player
            FloodFillStrategy floodFill = new FloodFillStrategy(boundry, Map.Player);
            Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
            eval.Evaluate(floodFill);

            List<LocationNode> result = floodFill.GetShortestPath(Destination);
            if (result == null) return null;

            // Path found, convert to VectoInt
            return result.ConvertAll<VectorInt>(delegate(LocationNode item) { return item.Location; });
        }
Exemplo n.º 18
0
        public IEnumerable<Direction> End(VectorInt e)
        {
            if (mode == Mode.PlayerMove)
            {
                CrateAnalysis.ShortestCratePath path = CrateAnalysis.FindCratePath(map, start, end);
                //if (path != null)
                //{
                //    var p = map.Player;
                //    foreach (Direction step in path.PlayerPath.Moves)
                //    {
                //        p.Add(new VectorInt(step));
                //        stack.Add(p);
                //    }
                //}
            }

            return null;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="myGameUI"></param>
        /// <param name="myDepth"></param>
        /// <param name="PositionAbs"></param>
        /// <param name="resImage">Resource of the UI button image</param>
        /// <param name="ClickCommand">Command string passed back in the click event</param>
        public NodeUIButton(GameUI myGameUI, int myDepth, VectorInt PositionAbs, ResourceID resImage, string ClickCommand)
            : base(myGameUI, myDepth)
        {
            imageNormal = myGameUI.ResourceFactory[resImage].DataAsImage;
            imageBack = myGameUI.ResourceFactory[ResourceID.GameButtonBackGround].DataAsImage;
            Size = new SizeInt(imageBack.Size);
            CurrentAbsolute = PositionAbs;
            clickCommand = ClickCommand;

            mouseOverBrush = myGameUI.ResourceFactory[ResourceID.GameButtonMouseOverBrush].DataAsBrush;
            maskEffect = null;
            toolTip = null;

            if (GameUI.Cursor != null)
            {
                GameUI.Cursor.OnClick += new EventHandler<NodeCursorEventArgs>(cursor_OnClick);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="myGameUI"></param>
        /// <param name="myDepth"></param>
        /// <param name="PositionAbs"></param>
        /// <param name="FileImage">Filename</param>
        /// <param name="ClickCommand">Command string passed back in the click event</param>
        public NodeUIButton(GameUI myGameUI, int myDepth, VectorInt PositionAbs, string FileImage, string ClickCommand)
            : base(myGameUI, myDepth)
        {
            imageNormal = new Bitmap(FileManager.getContent(FileImage));
            imageBack = new Bitmap(FileManager.getContent("$Graphics\\Icons\\BasicButtonBK.png"));
            Size = new SizeInt(imageBack.Size);
            CurrentAbsolute = PositionAbs;
            clickCommand = ClickCommand;

            mouseOverBrush = new SolidBrush(Color.FromArgb(60, Color.Yellow));
            maskEffect = null;
            toolTip = null;

            if (GameUI.Cursor != null)
            {
                GameUI.Cursor.OnClick += new EventHandler<NodeCursorEventArgs>(cursor_OnClick);
            }
        }
Exemplo n.º 21
0
        public void Start(VectorInt s)
        {
            if (map.Check(Cell.Crate, s))
            {
                mode = Mode.CrateMove;
                start = s;
                return;
            }

            if (map.Check(Cell.Floor, s))
            {
                mode = Mode.PlayerMove;
                start = s;
                return;
            }

            start = VectorInt.Null;
            mode = Mode.Error;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Check an individual node
        /// </summary>
        /// <param name="context"></param>
        /// <param name="checkCell"></param>
        /// <returns></returns>
        private bool CheckCorner(StaticAnalysis context, VectorInt checkCell)
        {
            // Check to see if this if a floor. As we do not have an explicit floor map use the wall map implicitly
            if (context.WallMap[checkCell]) return false;

            // Check TopRight
            if (context.WallMap[checkCell.Add(0, -1)] && context.WallMap[checkCell.Add(1, 0)]) return true;

            // Check TopLeft
            if (context.WallMap[checkCell.Add(0, -1)] && context.WallMap[checkCell.Add(-1, 0)]) return true;

            // Check BottomRight
            if (context.WallMap[checkCell.Add(0, 1)] && context.WallMap[checkCell.Add(1, 0)]) return true;

            // Check BottomLeft
            if (context.WallMap[checkCell.Add(-1, 0)] && context.WallMap[checkCell.Add(0, 1)]) return true;

            return false;
        }
 /// <summary>
 /// From a logical position, return the element
 /// </summary>
 /// <param name="LogicalCell"></param>
 /// <returns></returns>
 public override GridVisualisationElement this[VectorInt LogicalCell]
 {
     get
     {
         if (LogicalCell.X >= 0 && LogicalCell.Y >= 0 && LogicalCell.X < GridSize.X && LogicalCell.Y < GridSize.Y)
         {
             return cells[LogicalCell.X, LogicalCell.Y];
         }
         return null;
     }
     set
     {
         if (LogicalCell.X >= 0 && LogicalCell.Y >= 0 && LogicalCell.X < GridSize.X && LogicalCell.Y < GridSize.Y)
         {
             cells[LogicalCell.X, LogicalCell.Y] = value as BitmapViewerVisualisationElement;
             if (value != null && cells[LogicalCell.X, LogicalCell.Y] == null) throw new InvalidCastException("Wrong type");
         }
         throw new ArgumentOutOfRangeException("LogicalCell");
     }
 }
Exemplo n.º 24
0
 public NodeStaticCell(GameUI myGameUI, Cell myCell, VectorInt myPuzzleLocation, int myDepth)
     : base(myGameUI, myCell, myPuzzleLocation, myDepth)
 {
 }
Exemplo n.º 25
0
 public VectorInt Add(VectorInt value)
 {
     return new VectorInt(x + value.X, y + value.Y);
 }
Exemplo n.º 26
0
 public VectorInt(VectorInt copy)
 {
     this.x = copy.x;
     this.y = copy.y;
 }
Exemplo n.º 27
0
        /// <summary>
        /// Is the player adjacent to a puzzle position
        /// </summary>
        /// <param name="B"></param>
        /// <returns></returns>
        private static Direction IsAdjacentPlayer(VectorInt A, VectorInt B)
        {
            if (A.Offset(Direction.Up) == B) return Direction.Up;
            if (A.Offset(Direction.Down) == B) return Direction.Down;
            if (A.Offset(Direction.Left) == B) return Direction.Left;
            if (A.Offset(Direction.Right) == B) return Direction.Right;

            return Direction.None;
        }
Exemplo n.º 28
0
 public VectorInt Subtract(VectorInt value)
 {
     return new VectorInt(x - value.X, y - value.Y);
 }
Exemplo n.º 29
0
 public VectorInt Multiply(VectorInt value)
 {
     return new VectorInt(x * value.X, y * value.Y);
 }
Exemplo n.º 30
0
 public VectorInt Divide(VectorInt value)
 {
     return new VectorInt(x / value.X, y / value.Y);
 }