Beispiel #1
0
 string GetCollisionTile(Int2 position)
 {
     return(GetCollisionTile(position.x, position.y));
 }
Beispiel #2
0
 public Deck(Int2 position)
 {
     Position = position;
     State    = Ship.ShipState.fine;
 }
Beispiel #3
0
        public static bool PutDownShip(MenuEvent e)
        {
            MenuControllEvent ce   = (MenuControllEvent)e;
            TextLine          comm = new TextLine(new Int2(prepareMap.Position.x, prepareMap.Size.y + 1), " ", true);

            comm.Size      = new Int2(prepareMap.Size.x, 1);
            comm.Alignment = Stringer.TextAlignment.Middle;
            string id = ce.Controll.Identificator;

            id = id.Replace("len", "");
            int  len;
            bool done = false;
            bool save = false;

            if (!int.TryParse(id, out len))
            {
                return(false);
            }
            ;
            Ship s = prepareMap.AddShip(len, new Int2(0, 0));

            s.PickUp();
            prepareMap.GenerateCollisionsMap();
            s.UpdateCollisionState();
            Int2       cursorPosition = new Int2();
            bool       wereColliding  = false;
            bool       doUpdate       = true;
            ConsoleKey response;

            do
            {
                //prepareMap.GenerateCollisionsMap();
                if (s.Collision == Ship.CollisionState.overlap)
                {
                    wereColliding = true;
                    comm.SetText("SHIPS ARE OVERLAPPING!", Color.Red, Color.Black);
                }
                else if (s.Collision == Ship.CollisionState.zone)
                {
                    wereColliding = true;
                    comm.SetText("SHIP IN COLLISION ZONE!", Color.DarkRed, Color.Black);
                }
                else
                {
                    if (wereColliding)
                    {
                        wereColliding = false;
                        comm.SetText("");
                    }
                }
                if (doUpdate)
                {
                    prepareMap.Draw();
                }
                response = Console.ReadKey(true).Key;

                switch (response)
                {
                case ConsoleKey.A:
                case ConsoleKey.LeftArrow:
                    doUpdate = s.MoveBy(Int2.Left);
                    break;

                case ConsoleKey.W:
                case ConsoleKey.UpArrow:
                    doUpdate = s.MoveBy(Int2.Down);
                    break;

                case ConsoleKey.D:
                case ConsoleKey.RightArrow:
                    doUpdate = s.MoveBy(Int2.Right);
                    break;

                case ConsoleKey.S:
                case ConsoleKey.DownArrow:
                    doUpdate = s.MoveBy(Int2.Up);
                    break;

                case ConsoleKey.Enter:
                    done = true;
                    break;

                case ConsoleKey.Escape:
                    done = true;
                    s.Delete();
                    s        = null;
                    doUpdate = true;
                    break;

                case ConsoleKey.R:
                    doUpdate = s.RotateShip();
                    break;
                }

                if (s != null && s.Collision != Ship.CollisionState.none)
                {
                    done = false;
                }
            } while (!done);
            if (s != null)
            {
                s.PutDown();
                shipsOnBoard[s.lenght - 1]++;
                Renderer.AddDissapearingText("Added a new ship", 1000, new Int2(prepareMap.Position.x + prepareMap.Size.x - 8, 0));
            }
            prepareMap.GenerateCollisionsMap();
            prepareMap.Draw();

            return(save);
        }
Beispiel #4
0
 public bool IsTileColliding(Int2 position)
 {
     return(CollisionMap[position.x, position.y] <= collisionDistance);
 }
Beispiel #5
0
 public static bool InBoxInBox(Int2 aSize, Int2 aCoords, Int2 bSize, Int2 bCoords)
 {
     return(bCoords + bSize <= aSize + aCoords && bCoords >= aCoords);
 }
Beispiel #6
0
 public static bool InBox(Int2 aSizeInclusive, Int2 aCoords, Int2 bCoords)
 {
     return(bCoords <= aSizeInclusive + aCoords && bCoords >= aCoords);
 }
Beispiel #7
0
 ///<summary>
 ///Checks if a point is inside a given box (exclusive version).
 ///</summary>
 ///<param name="boxSize">The size of a box.</param>
 ///<param name="point">The point to be checked.</param>
 public static bool InBoxEx(Int2 boxSize, Int2 point)
 {
     return(point < boxSize && point > Zero);
 }
Beispiel #8
0
 public static Int2 Random(Int2 exclusiveMin, Int2 exclusiveMax)
 {
     return(new Int2(Rand.Int(exclusiveMin.x, exclusiveMax.y), Rand.Int(exclusiveMin.y, exclusiveMax.y)));
 }
Beispiel #9
0
 public static Int2 Random(Int2 exclusiveMax)
 {
     return(new Int2(Rand.Int(exclusiveMax.x), Rand.Int(exclusiveMax.y)));
 }