예제 #1
0
        public Visualizer(Grid.Grid xGrid, Drone.Drone xDrone)
        {
            InitializeComponent();

            srcGrid  = xGrid;
            srcDrone = xDrone;

            flightPathOptimized = false;

            preComputeFlightPath = xDrone.preComputeFlightPath;
            currFlightPath       = null;
            calcTimer            = null;

            //set up our window to be the proper aspect ratio for our grid
            float aspectRatio  = srcGrid.width / srcGrid.height;
            float frameBufferX = 17;
            float frameBufferY = 40;

            //our maximum height should be 720 pixels (720p), but we still want to fit everything on the screen in a way that looks neat
            //if the aspect ratio is > 16:9, then we should set our width at 1280 since height will be smaller than 720 at that point

            if (aspectRatio >= 16D / 9D)
            {
                Width  = 1280;
                Height = (int)(Width / aspectRatio);
            }
            else
            {
                Height = 720;
                Width  = (int)(Height * aspectRatio);
            }

            //add the necessary height & width for our tool panel and frame buffers
            Height = Height + toolPanel.Height + (int)frameBufferY;
            Width  = Width + (int)frameBufferX;

            //create our graphics object that we will be using to draw
            g = drawPanel.CreateGraphics();

            //calculate the transform that we will need to use to display graphics objects on our form

            float panelBufferX = 1;
            float panelBufferY = 1;

            RectangleF mapFrame = new RectangleF(0, 0, srcGrid.width, srcGrid.height);

            PointF[] drawCorners = new PointF[] { new PointF(0, 0), new PointF(drawPanel.Width - panelBufferX, 0), new PointF(0, drawPanel.Height - panelBufferY) };

            //scale the transform properly
            System.Drawing.Drawing2D.Matrix tMatrix = new System.Drawing.Drawing2D.Matrix(mapFrame, drawCorners);
            g.Transform = tMatrix;

            g.ScaleTransform(1, -1);
            g.TranslateTransform(0, -1 * (drawPanel.Height) / tMatrix.Elements.ElementAt(3) + panelBufferY);

            //initialize window and draw the control
            Show();
        }
예제 #2
0
        public Bitmap LayTile(Grid.Grid grid)
        {
            _logger.LogDebug("Laying tile...");
            var accumulator = new Bitmap(grid.Width, grid.Height);
            var result      = LayTile(grid.GetElements().ToArray(), accumulator);

            _logger.LogDebug("Finished laying tiles.");
            return(result);
        }
예제 #3
0
        private static void Solve(Grid.Grid grid, GridWalker.GridSolver solver)
        {
            int height;
            int width;
            var position = new Grid.Position(grid);

            solver.Solve(position, out height, out width);
            Console.WriteLine("Solved [{0}x{1}] using {2} with {3} wall checks, {4} steps, and {5} turns", height, width, solver.GetType()
                              , position.WallChecksMade, position.StepsTaken, position.TurnsMade);
        }
예제 #4
0
파일: Drone.cs 프로젝트: rakrob/GridNav
        public Drone(float droneRadius, float flightSpeed, Grid.Grid parentGrid)
        {
            //just setting some local variables, properties, things of that nature
            radius        = droneRadius; speed = flightSpeed; xPosition = parentGrid.startX; yPosition = parentGrid.startY;
            xGrid         = parentGrid;
            prevDirection = float.NaN;

            preComputeFlightPath = new FlightPath();
            preComputeFlightPath.addNode(xGrid.startX, xGrid.startY, false);
            preComputeFlightPath.addNode(xGrid.endX, xGrid.endY, true);
        }
예제 #5
0
파일: Normal.cs 프로젝트: eamonnjames/turle
        private bool IsVaildMove(Point point)
        {
            var boardWidthAndHeight = GameSettings.GameSettingSetBoardSize("Board Size", "Settings");
            var g1 = new Grid.Grid(boardWidthAndHeight.width, boardWidthAndHeight.height);

            try
            {
                g1.accessCoordinate(point.x, point.y);
                return(true);
            }catch (Exception e)
            {
                Console.WriteLine("Corrdinate is not present : {0}", e);
                return(false);
            }
        }
예제 #6
0
        public override bool CanTarget(GridOccupant target, GridOccupant wielder, Grid.Grid grid)
        {
            var direction = target.Position - wielder.Position;

            if (!direction.IsCardinal() || direction.CardinalMagnitude() > 1)
            {
                return(false);
            }

            var node = new Grid.Grid.Node();

            if (grid.TryGetNodeAt(wielder.Position, ref node))
            {
                return(node.Occupants.Any(it => TargetTypes.Contains(it.Type)));
            }

            return(false);
        }
예제 #7
0
        /// <summary>
        /// Checks All Conditions to See if Player Who Played Last Has Won
        /// </summary>
        /// <param name="LastPlayed">The Space Last Played.</param>
        public void CheckVictory(GridSpace LastPlayed)
        {
            Debug.Log("Checking Victory");

            //Get Grid Parent For Future Checks
            Grid.Grid Parent = LastPlayed.GetComponentInParent <Grid.Grid>();

            Debug.Log(string.Format("Grid to Check: {0}", Parent.name));
            Debug.Log(string.Format("Space to Check: {0}", LastPlayed.DisplayStr));

            bool PlayerWin = Parent.CheckRow(LastPlayed);

            if (!PlayerWin)
            {
                PlayerWin = Parent.CheckColumn(LastPlayed);

                if (!PlayerWin)
                {
                    PlayerWin = Parent.CheckDiagonal(LastPlayed);
                }
            }

            //After All Needed Checks, If Player Won
            if (PlayerWin)
            {
                //End Game
                EndGame(TurnManager.instance.CurrentPlayer);
            }
            else
            {
                //Check to See if Grid is Full
                if (Parent.CheckFull())
                {
                    //If So, End in Draw
                    EndGame(0);
                }
                else
                {
                    //Move to the Next Turn
                    TurnManager.instance.NextTurn();
                }
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            var gameSize = 10;
            var grid     = new Grid.Grid(gameSize);
            var game     = new BattleShipsGame(grid);

            game.ShipSunk   += ShipShunk;
            game.MissedShot += MissShot;
            game.ShipHit    += ShipHit;

            //TODO: read ships size from the configuration file
            game.TryAddShip(ShipType.Destroyer, 4);
            game.TryAddShip(ShipType.Destroyer, 4);
            game.TryAddShip(ShipType.Battleship, 5);

            _viewAdapter = new ViewAdapter(gameSize);
            while (!game.IsGameFinished)
            {
                try
                {
                    Console.WriteLine(_viewAdapter.ToString());

                    Console.WriteLine("Provide position to shoot");
                    var position = Console.ReadLine();

                    InputInterpreter.InterpretCell(position, out int rowNumber, out int columnNumber);

                    Console.WriteLine($"Shooting position: {position}.");

                    _lastShotPointRow    = rowNumber;
                    _lastShotPointColumn = columnNumber;

                    game.MakeShot(rowNumber, columnNumber);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine("Game finished !");
        }
예제 #9
0
        static void Main(string[] args)
        {
            var g = new Grid.Grid(1, 1);
            var circGridSolver    = new GridSolverCircular();
            var upNbackGridSolver = new GridSolverUpAndBack();

            Solve(g, circGridSolver);
            Solve(g, upNbackGridSolver);

            g = new Grid.Grid(5, 9);
            Solve(g, circGridSolver);
            Solve(g, upNbackGridSolver);

            g = new Grid.Grid(9, 5);
            Solve(g, circGridSolver);
            Solve(g, upNbackGridSolver);

            g = new Grid.Grid(22, 5);
            Solve(g, circGridSolver);
            Solve(g, upNbackGridSolver);
            Console.Read();
        }
예제 #10
0
        // public abstract Grid.Grid.Node[] FindTargets(Grid.Grid.Node wielder, Grid.Grid grid);
        //
        // public virtual List<IUnitAction> Apply(Grid.Grid.Node target, GameObject wielder)
        // {
        //     var actions = new List<IUnitAction>();
        //     foreach (var occupant in target.Occupants)
        //     {
        //         if (occupant.OccupantGameObject != wielder || EffectSelf)
        //         {
        //             foreach (var effect in Effects)
        //             {
        //                 var r = effect.Apply(occupant.OccupantGameObject, wielder);
        //                 actions.AddNullableRange(r);
        //             }
        //         }
        //     }
        //
        //     return actions;
        // }

        public abstract GridOccupant[] FindTargets(GridOccupant wielder, Vector2Int direction, Grid.Grid grid);
예제 #11
0
 public override List <GridOccupant> FindAllPossibleTargets(GridOccupant wielder, Grid.Grid grid)
 {
     return(FindTargets(wielder, Vector2Int.down, grid).ToList());
 }
예제 #12
0
 public override List <Grid.Grid.Node> FindAllPossibleEffectedNodes(GridOccupant wielder, Grid.Grid grid)
 {
     return(FindEffectedNodes(wielder, Vector2Int.down, grid));
 }
예제 #13
0
        // public override Grid.Grid.Node[] FindTargets(Grid.Grid.Node wielder, Grid.Grid grid)
        // {
        //     var neighbours = grid.GetNeighbours(wielder);
        //
        //     // todo(chris) consider optimising as this will be used by every mellee enemy on the grid
        //     return neighbours.Where(node => node.Occupants.Any(it => it.Tags.Intersect(TargetTypes).Any())).ToArray();
        // }

        // todo(chris) shouldnt this only find targets in direction??
        public override GridOccupant[] FindTargets(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var node = new Grid.Grid.Node();

            if (grid.TryGetNodeAt(wielder.Position, ref node))
            {
                var neighbours = grid.GetNeighbours(node);

                var targets = new List <GridOccupant>();

                foreach (var neighbour in neighbours)
                {
                    var validOccupants = neighbour.Occupants.Where(it => TargetTypes.Contains(it.Type));
                    targets.AddRange(validOccupants);
                }

                return(targets.ToArray());
            }

            return(null);
        }
예제 #14
0
 public AStar(Grid.Grid grid)
 {
     this.grid = grid;
 }
예제 #15
0
        public override bool CanTarget(GridOccupant target, GridOccupant wielder, Grid.Grid grid)
        {
            var targets = FindTargets(wielder, target.Position - wielder.Position, grid);

            return(Array.IndexOf(targets, target) > -1);
        }
예제 #16
0
 public void onInit(int row, int colum, float x, float y, float width, float height)
 {
     grid = Grid.Grid.getInst();
     grid.onInit(new Vector2(x, y), row, colum, width, height);
 }
예제 #17
0
        public virtual List <Grid.Grid.Node> FindAllPossibleEffectedNodes(GridOccupant wielder, Grid.Grid grid)
        {
            var occupants = new List <Grid.Grid.Node>();

            occupants.AddNullableRange(FindEffectedNodes(wielder, Vector2Int.up, grid));
            occupants.AddNullableRange(FindEffectedNodes(wielder, Vector2Int.down, grid));
            occupants.AddNullableRange(FindEffectedNodes(wielder, Vector2Int.left, grid));
            occupants.AddNullableRange(FindEffectedNodes(wielder, Vector2Int.right, grid));

            return(occupants);
        }
예제 #18
0
        public override GridOccupant[] FindTargets(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var path = CalculatePath(wielder, direction, grid);

            if (!path.IsLastNodeTarget)
            {
                return(null);
            }

            var targets = path.Travelled.Last().Occupants.Where(it => TargetTypes.Contains(it.Type));

            return(targets as GridOccupant[] ?? targets.ToArray());
        }
예제 #19
0
        public virtual List <IUnitAction> Use(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var actions = new List <IUnitAction>();

            var targets = FindTargets(wielder, direction, grid);

            foreach (var occupant in targets)
            {
                if (occupant != wielder || EffectSelf)
                {
                    foreach (var effect in Effects)
                    {
                        var r = effect.Apply(occupant.OccupantGameObject, wielder.OccupantGameObject);
                        actions.AddNullableRange(r);
                    }
                }
            }

            return(actions);
        }
예제 #20
0
        public virtual List <Grid.Grid.Node> FindEffectedNodes(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var occupants = FindTargets(wielder, direction, grid);
            var nodes     = new List <Grid.Grid.Node>();

            foreach (var occupant in occupants)
            {
                if (nodes.FindIndex(it => it.Position == occupant.Position) > -1)
                {
                    var n = new Grid.Grid.Node();
                    if (grid.TryGetNodeAt(occupant.Position, ref n))
                    {
                        nodes.Add(n);
                    }
                }
            }

            return(nodes);
        }
예제 #21
0
 public abstract bool CanTarget(GridOccupant target, GridOccupant wielder, Grid.Grid grid);
예제 #22
0
        public override bool CanTarget(GridOccupant target, GridOccupant wielder, Grid.Grid grid)
        {
            var path = CalculatePath(wielder, target.Position - wielder.Position, grid);

            return(path.IsLastNodeTarget);
        }
예제 #23
0
        public PathDetails CalculatePath(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            PathDetails path = new PathDetails
            {
                Travelled        = new List <Grid.Grid.Node>(),
                IsLastNodeTarget = false
            };

            var normalised = direction.CardinalNormalise();

            var magnitude = projectile.Range;
            var node      = new Grid.Grid.Node();

            for (int i = 1; i <= magnitude; i++)
            {
                if (grid.TryGetNodeAt(wielder.Position + i * normalised, ref node))
                {
                    path.Travelled.Add(node);

                    // if we have hit something that has a type then weve eiher hit something we cant move though
                    // or weve hit our target
                    if (node.Occupants.Any(it => it.Type != null))
                    {
                        path.IsLastNodeTarget = node.Occupants.Any(it => it.Type != null && TargetTypes.Contains(it.Type));
                        break;
                    }
                    // todo(chris) add back in when we implement penetration
                    // else
                    // {
                    //     var targetOccupants = node.Occupants.Where(it => TargetTypes.Contains(it.Type));
                    //
                    //     var gridOccupants = targetOccupants as GridOccupant[] ?? targetOccupants.ToArray();
                    //
                    //     // occupant isnt a target so cant go through
                    //     if (gridOccupants.Length == 0)
                    //     {
                    //         break;
                    //     }
                    //
                    //     path.Hits.Add(node);
                    //
                    //     var penetrating = gridOccupants.Where(occupant => projectile.PenitrationTags.Contains(occupant.Type));
                    //
                    //     var penetratingArray = penetrating as GridOccupant[] ?? penetrating.ToArray();
                    //
                    //     // cant penetrate target to this will be as far as we go
                    //     if (penetratingArray.Length == 0)
                    //     {
                    //         break;
                    //     }
                    //
                    //     // if we cant penetrate all then we are done
                    //     if (remainingDepth <= penetratingArray.Length)
                    //     {
                    //         break;
                    //     }
                    //
                    //    // continue;
                    // }
                }
                else
                {
                    break;
                }
            }

            if (path.IsLastNodeTarget && path.Travelled.Count == 0)
            {
                path = new PathDetails
                {
                    Travelled        = new List <Grid.Grid.Node>(),
                    IsLastNodeTarget = false
                };
            }
            else
            {
                path.Travelled.RemoveAt(0);
            }

            return(path);
        }
예제 #24
0
 public override List <Grid.Grid.Node> FindEffectedNodes(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
 {
     return(CalculatePath(wielder, direction, grid).Travelled);
 }
예제 #25
0
        public override List <IUnitAction> Use(GridOccupant wielder, Vector2Int direction, Grid.Grid grid)
        {
            var path = CalculatePath(wielder, direction, grid);

            if (path.Travelled.Count == 0)
            {
                return(null);
            }
            var endPoint = path.Travelled.Last();

            var outOfAmmo       = true;
            var spawnProjectile = true;

            var inventory = wielder.OccupantGameObject.GetComponent <IProvider <Inventory> >()?.Get();

            if (inventory != null)
            {
                if (initialAmmunition != null)
                {
                    AggregateSlot ammuntion;
                    if (inventory.RetrieveSlot(initialAmmunition.Key, out ammuntion))
                    {
                        if (ammuntion.Total < 1)
                        {
                            outOfAmmo       = true;
                            spawnProjectile = false;
                        }
                        else if (ammuntion.Total == 1)
                        {
                            outOfAmmo       = true;
                            spawnProjectile = true;
                        }
                        else
                        {
                            ammuntion.Total--;
                            inventory.UpdateSlot(initialAmmunition.Key, ammuntion);
                            spawnProjectile = true;
                            outOfAmmo       = false;
                        }
                    }
                }

                if (outOfAmmo && unequipWhenOutOfAmmo)
                {
                    inventory.RemoveWeaponSlot(_weaponKey);
                }
            }

            if (spawnProjectile)
            {
                return(new List <IUnitAction> {
                    new LaunchProjectileAction(wielder, endPoint, projectile)
                });
            }
            else
            {
                return(null);
            }
        }