Implementation of hexagonal cell.
상속: Cell
    public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
    {
        PortalManager portalManager = PortalManager.GetInstance();

        if (target._entity == null)
        {
            if (target.Portal != null)
            {
                target.Portal.Destroy();
            }
            portalManager.CreatePortal(target);
        }
        else
        {
            Logger.Debug("PortalEffect : Targeted hexagon has an entity");
        }

        // Automatically teleport players that stand on portals
        if (portalManager.TwoPortalsActivated())
        {
            if (portalManager.Portal1.Position._entity is Character)
            {
                Character character = (Character)portalManager.Portal1.Position._entity;
                portalManager.Teleport(character);
            }
            else if (portalManager.Portal2.Position._entity is Character)
            {
                Character character = (Character)portalManager.Portal2.Position._entity;
                portalManager.Teleport(character);
            }
        }

        HistoricManager.GetInstance().AddText(String.Format(StringsErule.portal, caster.Name));
    }
 public void ApplyBoost(Hexagon.Boost boost)
 {
     Hexagon hex = PlayBoardManager.GetInstance().Board.GetHexagone(x, y);
     if (hex != null && !(hex._posX < 0))
     {
         hex.BoostElement = boost;
         // Air, Earth, Fire, Metal, Water, Wood, Nothing
         switch (boost)
         {
             case Hexagon.Boost.Air:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._air;
                 break;
             case Hexagon.Boost.Earth:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._earth;
                 break;
             case Hexagon.Boost.Fire:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._fire;
                 break;
             case Hexagon.Boost.Metal:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._metal;
                 break;
             case Hexagon.Boost.Water:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._water;
                 break;
             case Hexagon.Boost.Wood:
                 hex.GameObject.GetComponentInChildren<Renderer>().material.color = ColorErule._wood;
                 break;
             case Hexagon.Boost.Nothing:
                 break;
             default:
                 break;
         }
     }
 }
예제 #3
0
	/// <summary>
	/// Sets the hexagone.
	/// </summary>
	/// <returns><c>true</c>, if hexagone was set, <c>false</c> otherwise.</returns>
	/// <param name="hex">Hex.</param>
	/// <param name="replace">If set to <c>true</c> replace.</param>
	public bool SetHexagone(Hexagon hex, bool replace=true){

		int x = hex._posX;
		int y = hex._posY;

		if (x >= 0 && x < _width && y >= 0 && y < _height) {

			if (_grid [x] [y]._posX<0) {

				_grid [x] [y] = hex;
				return true;
			} 
			else {
				if (replace) {
					_grid [x] [y] = hex;
					return true;
				}
				else {
					return false;
				}
			}

		}

		return false;
	}
예제 #4
0
 protected void PlaceNextHexagon(int id, DegreeType degreeType, EdgeOrientation eo)
 {
     var pos = _lastPlacedHexagon.GetPositionNextTo(eo);
     Board.GetLimits(pos);
     var hex = Board.CreateHexagon(id, degreeType, pos);
     _lastPlacedHexagon = hex;
 }
예제 #5
0
 public void ActivatePortal(Hexagon position)
 {
     Position = position;
     _gameObject.SetActive(true);
     _gameObject.transform.position = position.GameObject.transform.position + new Vector3(0, 1, 0);
     _timestamp = Time.time;
 }
 /// <summary>
 /// Adds a GroundOnTimeAppliedEffect to every Hexagon in the area of effect.
 /// </summary>
 /// <param name="hexagons">The Hexagons in the area of effect.</param>
 /// <param name="target">The Hexagon aimed.</param>
 /// <param name="caster">The caster of the effect.</param>
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     foreach (Hexagon hexa in hexagons)
     {
         GroundOnTimeAppliedEffectGrowable effect = new GroundOnTimeAppliedEffectGrowable(_id, _effect, _nbTurn, caster);
         hexa.AddOnTimeEffect(effect);
     }
 }
예제 #7
0
 protected void PlaceHexagonsEnd()
 {
     _lastPlacedHexagon = null;
     foreach (var hex in Board.GetHexagons())
     {
         (new HexagonConstructor(hex)).PlaceEnd(Board);
     }
 }
 /// <summary>
 /// Reduces the number of turns remaining. Removes the effect from the Hexagon if nbTurn inferior to 1.
 /// </summary>
 /// <param name="hexagon">The Hexagon affected by the effect.</param>
 public void ReduceNbTurn(Hexagon hexagon)
 {
     _nbTurn--;
     if(_nbTurn < 1)
     {
         hexagon.RemoveOnTimeEffect(this);
     }
 }
 public KillableObstacle(Hexagon position, int life, Character caster) : base(position)
 {
     MaxLife = life;
     CurrentLife = life;
     Caster = caster;
     _onTimeEffects = new Dictionary<int, PlayerOnTimeAppliedEffect>();
     _onTimeEffectsToRemove = new List<int>();
 }
예제 #10
0
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     List<Killable> killables = PlayBoardManager.GetInstance().GetKillableInArea(hexagons);
     foreach (Killable k in killables)
     {
         if (k is Character)
             (k as Character).ReceiveShield(this);
     }
 }
예제 #11
0
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     Logger.Trace("Apply stabilization");
     List<Character> chars = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);
     foreach (Character c in chars)
     {
         c.ReceiveStabilization();
     }
 }
 /// <summary>
 /// Adds a GroundOnTimeAppliedEffect to every Hexagon in the area of effect.
 /// </summary>
 /// <param name="hexagons">The Hexagons in the area of effect.</param>
 /// <param name="target">The Hexagon aimed.</param>
 /// <param name="caster">The caster of the effect.</param>
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     foreach(Hexagon hexa in hexagons)
     {
         GroundOnTimeAppliedEffect effect = new GroundOnTimeAppliedEffect(_id, _effect, _nbTurn, caster);
         hexa.AddOnTimeEffect(effect);
     }
     HistoricManager.GetInstance().AddText(String.Format(StringsErule.area, caster.Name));
 }
예제 #13
0
 public void Destroy()
 {
     if (_position != null)
     {
         _position.Portal = null;
     }
     _position = null;
     _gameObject.SetActive(false);
 }
 /// <summary>
 /// Adds a PlayerOnTimeAppliedEffect on every Character in the area of effect.
 /// </summary>
 /// <param name="hexagons">The Hexagons affected by the Effect.</param>
 /// <param name="target">The Hexagon aimed.</param>
 /// <param name="caster">The caster of the effect.</param>
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     List<Killable> killable = PlayBoardManager.GetInstance().GetKillableInArea(hexagons);
     foreach(Killable c in killable)
     {
         PlayerOnTimeAppliedEffect effect = new PlayerOnTimeAppliedEffect(_id, _effect, _nbTurn, caster);
         c.ReceiveOnTimeEffect(effect);
     }
 }
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     Logger.Trace("Apply protection up effect : " + _protection);
     List<Character> chars = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);
     foreach (Character c in chars)
     {
         c.ReceiveProtectionGlobalUp(_protection);
     }
 }
예제 #16
0
    public Entity(Hexagon position)
    {
        if (position == null)
            return;

        if (!Hexagon.isHexagonSet(position) || position._entity != null)
            throw new Exception("Invalid Position");
        _position = position;
        position._entity = this;
    }
예제 #17
0
파일: HexTile.cs 프로젝트: beardhero/HEX
 public HexTile(Hexagon h, int p, List<int> neighbs, bool b, float hi, TileType t)
 {
     type = t;
     index = h.index;
     hexagon = h;
     plate = p;
     boundary = b;
     neighbors = new List<int>(neighbs);
     height = hi;
 }
    public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
    {
        List<Killable> killables = PlayBoardManager.GetInstance().GetKillableInArea(hexagons);
        foreach (var k in killables)
        {
            int damage = EruleRandom.RangeValue((int)_min, (int)_max + 1);

            damage += caster.DamageModifier;
            k.ReceiveDamage(damage, _element);
        }
    }
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     if (_nbTurn > 0)
     {
         _effect.ApplyEffect(hexagons, target, _caster);
     }
     else
     {
         Logger.Debug("Tried to apply a GroundOnTimeAppliedEffect with 0 as nbTurn");
     }
 }
	public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
    {
        /*Logger.Trace("Apply protection effect : " + _protection);
        List<Character> characters = PlayBoardManager.GetInstance ().GetCharacterInArea (hexagons);

		foreach(var ch in characters){
			ch.ReceiveGlobalProtection (_protection);
		}*/

        Logger.Error("You would have applied a global protection. But it doesn't exist, y'know ? Stop running after unreachable dreams.");
	}
예제 #21
0
 public Portal(Hexagon position, GameObject gameObject, int id)
 {
     if (position != null)
     {
         position.Portal = this;
     }
     _gameObject = gameObject;
     _position = position;
     _id = id;
     _gameObject.transform.GetChild(1).transform.rotation = Camera.main.transform.rotation;
 }
예제 #22
0
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     
     List<Character> chars = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);
     foreach (Character c in chars)
     {
         int heal = GetRandom();
         Logger.Trace("Apply heal effect : " + heal);
         c.ReceiveHeal(heal);
     }
 }
예제 #23
0
		public static Axis GetSeparationAxis(Hexagon a, Hexagon b) {
			if (RangesDisjoint(a.zMin, a.zMax, b.zMin, b.zMax)) {
				return Axis.Z;
			}
			if (RangesDisjoint(a.yMin, a.yMax, b.yMin, b.yMax)) {
				return Axis.Y;
			}
			if (RangesDisjoint(a.xMin, a.xMax, b.xMin, b.xMax)) {
				return Axis.X;
			}
			return Axis.None;
		}
 public void GrowUp(Hexagon hexagon)
 {
     Logger.Debug("grow up GroundOnTimeAppliedEffect begin");
     if (PlayBoardManager.GetInstance().isMyTurn(_caster)) { 
         foreach (Hexagon hex in hexagon.GetAllNeighbours())
         {
             Logger.Debug("add on time effect on hexa begin");
             hex.AddOnTimeEffect(new GroundOnTimeAppliedEffectGrowable(_id, _effect, _nbTurn, _caster));
             Logger.Debug("add on time effect on hexa end");
         }
     }
     Logger.Debug("grow up GroundOnTimeAppliedEffect end");
 }
예제 #25
0
    public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
    {
        int damage = GetRandom();
        List<Killable> killables = PlayBoardManager.GetInstance().GetKillableInArea(hexagons);

        foreach (var k in killables)
        {
            damage = k.ReceiveDamage(damage, _element);
            int heal = _vampiricPercentage * damage / 100;
            if (k is Character)
                caster.ReceiveHeal(heal);
        }
    }
예제 #26
0
    public void Spawn()
    {
        isLumberjackWaiting = true;
        SelectTarget();

        //2:Looking for the spawn hexagon
        _spawnHex = Map.instance.HexBorders[Random.Range(0, Map.instance.HexBorders.Length)];

        //4:Enable the movement
        transform.position = _spawnHex.transform.position;

        StartCoroutine(MoveLumberjack());
    }
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     if (_nbTurn-- > 0)
     {
         _effect.ApplyEffect(hexagons, target, _caster);
     }
     else
     {
         foreach(Character c in PlayBoardManager.GetInstance().GetCharacterInArea(hexagons))
         {
             Logger.Trace("Removing effect from " + c.Name);
             c.RemoveOnTimeEffect(this);
         }
     }
 }
예제 #28
0
    public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
    {
        List<Character> characters = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);

        for (int i = 0; i < characters.Count; i++)
        {
            if (!characters[i].IsStabilized)
            {
                Hexagon source = caster.Position;
                Direction.EnumDirection direction = Direction.GetDirection(source, target);
                characters[i].TranslateCharacter(direction, _nbDeplacement);
                characters[i].NextState = Character.State.Translating;
            }
        }
    }
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     Logger.Trace("Apply movement down effect : " + _movement);
     List<Character> chars = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);
     foreach (Character c in chars)
     {
         if (!c.EffectsTerminable.ContainsKey(_id) || !ApplyReverseEffect)
         {
             c.ReceiveMovementDown(_movement);
         }
         if (ApplyReverseEffect)
         {
             c.EffectsTerminable[_id] = new MovementUp(_id, _movement, NbTurn, false);
         }
     }
 }
예제 #30
0
 public override void ApplyEffect(List<Hexagon> hexagons, Hexagon target, Character caster)
 {
     Logger.Trace("Apply range down effect : " + _range);
     List<Character> chars = PlayBoardManager.GetInstance().GetCharacterInArea(hexagons);
     foreach (Character c in chars)
     {
         if (!c.EffectsTerminable.ContainsKey(_id) || !ApplyReverseEffect)
         {
             c.ReceiveRangeModifier(-_range);
         }
         if (ApplyReverseEffect)
         {
             c.EffectsTerminable[_id] = new RangeUp(_id, _range, NbTurn, false);
             HistoricManager.GetInstance().AddText(String.Format(StringsErule.rangeMalus, c.Name, _range, NbTurn));
         }
     }
 }
예제 #31
0
 public abstract void MoveTo(Hexagon destination);
예제 #32
0
    /*
     *  Goes through all the hexagons of every platform (which means going through EVERY single hexagon) and add it to the different lists
     *  At the end, give it its individual colour settings
     */
    private void CollectTilesForListsAndColorThem(bool inEditor)
    {
        int tilesCounter = 0;
        for(int i = 0; i < platforms.Count; i++)
        {
            List<Hexagon> platformTiles = platforms[i].GetTilesList();
            for(int k = 0; k < platformTiles.Count; k++)
            {
                Hexagon hexagon = platformTiles[k];
                HexagonBehaviour behaviour = hexagon.GetComponent<HexagonBehaviour>();
                allTiles[tilesCounter] = hexagon;
                tileColors[hexagon] = hexagon.GetColor();                
                bool destroyVFX = true;
                hexagon.SetStandardTile(true);

                if(inEditor && hexagon.GetAudioSource())
                {
                    DestroyImmediate(hexagon.GetAudioSource());
                }
                
                if(hexagon.IsPathTile())
                {
                    SaveHexagonInList(pathTiles, hexagon, hexagon.GetPathNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(pathHexagons);
                    //hexagon.SetAudio("cracked");
                    //GameObject child = hexagon.transform.GetChild(0).gameObject;
                    //Material material = child.GetComponent<MeshRenderer>().material;
                    //material.EnableKeyword("_NORMALMAP");
                    //material.SetTexture("_BumpMap", crackedHexagonPattern);
                    //material.SetTextureScale("_MainTex", new Vector2(1.95f, 1.95f)); //aka tiling
                    //material.SetTextureOffset("_MainTex", new Vector2(-0.087f, 0.013f));
                    // Debug.Log("texture");
                }

                if(hexagon.IsCrackedTile())
                {
                    SaveHexagonInList(crackedTiles, hexagon, hexagon.GetCrackedNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetAudio("cracked");
                    hexagon.SetMaterial(crackedHexagons);
                }

                if(hexagon.IsDistractionTile())
                {
                    SaveHexagonInList(distractionTiles, hexagon, hexagon.GetDistractionNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(distractionHexagons);

                    if(!hexagon.GetComponent<HexagonDistraction>()) hexagon.gameObject.AddComponent<HexagonDistraction>();

                    hexagon.GetComponent<HexagonDistraction>().GetStarted(hexagon.GetDistractionNumber(), platforms[i].GetAllPlatformTiles(), 
                                                                            allTiles, tileColors, distractionTiles, hexagon);
                }
                else
                {
                    if(inEditor)
                    {
                        HexagonDistraction distractionScript = hexagon.GetComponent<HexagonDistraction>();
                        if(distractionScript)
                        {                           
                            DestroyImmediate(distractionScript);
                        }                            
                    }
                }

                if(hexagon.IsCheckpointTile())
                {
                    SaveHexagonInList(checkpointTiles, hexagon, hexagon.GetCheckpointNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(checkpointHexagons);
                }

                if(hexagon.IsSpecialTile())
                {                    
                    SaveHexagonInList(specialTiles, hexagon, hexagon.GetSpecialNumber());                    
                    hexagon.SetStandardTile(false);
                    switch (hexagon.GetSpecialNumber()) {
                        case 0: {
                                hexagon.SetMaterial(teleporterHexagons);
                                break;
                            }
                        case 1: {
                                hexagon.SetMaterial(velocityHexagons);
                                break;
                            }
                        case 2: {
                                hexagon.SetMaterial(jumpPadHexagons);
                                break;
                            }
                        case 3: {
                                hexagon.SetMaterial(loosingHexagons);
                                break;
                            }   
                        defaut: {
                                hexagon.SetMaterial(standardHexagons);
                                break;
                            }
                    }
                    if(!hexagon.GetComponent<HexagonSpecial>()) hexagon.gameObject.AddComponent<HexagonSpecial>();
                    HexagonSpecial specialScript = hexagon.GetComponent<HexagonSpecial>();                
                    specialScript.GetStarted(specialTiles, this, hexagon, inEditor);
                    destroyVFX = !specialScript.HasVFX();
                }
                else
                {
                    if(inEditor)
                    {
                        HexagonSpecial specialScript = hexagon.GetComponent<HexagonSpecial>();
                        if(specialScript)
                        {                           
                           DestroyImmediate(specialScript);
                        }                                                    
                    }
                }

                if(hexagon.IsMovingTile())
                {
                    SaveHexagonInList(movingTiles, hexagon, hexagon.GetMovingNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(movingHexagons);
                    if(!hexagon.GetComponent<HexagonMovingTiles>()) hexagon.gameObject.AddComponent<HexagonMovingTiles>();                    
                }
                else
                {
                    if(inEditor)
                    {
                        HexagonMovingTiles movingTilesScript = hexagon.GetComponent<HexagonMovingTiles>();
                        if(movingTilesScript)
                        {
                            DestroyImmediate(movingTilesScript);
                        }                            
                    }
                }

                if(hexagon.IsStartingTile())
                {
                    SaveHexagonInList(startingTiles, hexagon, hexagon.GetStartingNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(startingHexagons);
                    hexagon.SetVisualEffect("StartingVFX", inEditor);
                    destroyVFX = false;
                }

                if(hexagon.IsWinningTile())
                {
                    SaveHexagonInList(winningTiles, hexagon, hexagon.GetWinningNumber());
                    hexagon.SetStandardTile(false);
                    hexagon.SetMaterial(winningHexagons);
                    hexagon.SetVisualEffect("WinningVFX", inEditor);
                    destroyVFX = false;
                }

                if(hexagon.IsStandardTile())
                {
                    standardTiles.Add(hexagon);
                    hexagon.SetMaterial(standardHexagons);
                    if(inEditor && hexagon.GetComponent<AudioSource>())
                    {
                        DestroyImmediate(hexagon.GetComponent<AudioSource>());
                    }
                }

                if(inEditor && hexagon.GetComponent<AudioSource>())
                {
                    if(hexagon.GetComponent<AudioSource>().clip == null)
                    {
                        DestroyImmediate(hexagon.GetComponent<AudioSource>());
                    }
                }

                if(destroyVFX && hexagon.GetVisualEffect()) hexagon.DestroyVisualEffect(inEditor);

                Color[] getAllTouchingColors = this.GetComponent<TileColorsTouching>().GiveColorSet(); // get all Colors when the ball for touching and leaving a hexagon
                behaviour.SetColors(getAllTouchingColors); // give current hexagon the set, in order to get its individual color settings
                tilesCounter++;
            }
        }        
    }
예제 #33
0
        static void Main(string[] args)
        {
            #region StartUpConfig
            bool             runApp      = true;
            bool             shapeSelect = true;
            string           usersInput  = "";
            double           dimension;
            bool             triangleType = false; //true if 90 degrees, false if otherwise
            Rectangle        rectangle    = null;
            RectangularPrism rp           = null;
            Square           square       = null;
            Cube             cube         = null;
            Circle           circle       = null;
            Sphere           sphere       = null;
            Triangle         triangle     = null;
            Octagon          octagon      = null;
            Hexagon          hexagon      = null;
            Pentagon         pentagon     = null;

            // make sure to include any new shapes into the shapeList array
            string[] shapeList =
            {
                "Rectangle",
                "Rectangular Prism",
                "Square",
                "Cube",
                "Circle",
                "Sphere",
                "Triangle",
                "Octagon",
                "Hexagon",
                "Pentagon"
            };
            #endregion
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("============================================");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Shape Area Calculator");

            while (runApp == true)
            {
                if (shapeSelect == false)
                {
                    shapeSelect = true;
                }
                Console.Write("Enter a supported shape or a command (type \"");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("/help");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\" to see commands)\n\n");
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.Write("> ");
                Console.ForegroundColor = ConsoleColor.White;
                usersInput = Console.ReadLine().ToLower();
                Console.WriteLine();

                if (usersInput == "/shapes" || usersInput == "/s")
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("--------------------------------------------");
                    Console.ForegroundColor = ConsoleColor.White;
                    // Lists out all the shapes as long as they are included in the shapeList
                    shapeList.ToList().ForEach(i => Console.WriteLine(i));
                    Console.WriteLine();
                }
                else if (usersInput == "/help" || usersInput == "/h")
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("--------------------------------------------");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("\"");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("/shapes");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\" : shows a list of all supported shapes");
                    Console.Write("\"");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("/quit");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\" : exit the program");
                    Console.Write("\"");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("shapename");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\" : begins the process to gather area for shape\n");
                }
                else if (usersInput == "/quit" || usersInput == "/q")
                {
                    runApp = false;
                }
                else if (usersInput == "shapename")
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("--------------------------------------------");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("shapename is an invalid command\ntry entering an actual shape name such as \"");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("circle");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("\"\n");
                }
                else
                {
                    Console.Clear();
                    while (shapeSelect == true)
                    {
                        switch (usersInput) // SWITH CASE FOR ALL SUPPORTED SHAPES TO CALCULATE THE AREA GOES HERE
                        {
                            #region Rectangle
                        case "rectangle":
                            try
                            {
                                if (rectangle == null)
                                {
                                    rectangle = new Rectangle();
                                }
                                Console.WriteLine("Rectangle\n");

                                Console.Write("Enter length:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    rectangle.setLength(dimension);     // Set Rectangle shapes length
                                    Console.Write("\nEnter height:\n\n");
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.Write("> ");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    usersInput = Console.ReadLine();
                                    dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                    if (dimension > 0)
                                    {
                                        rectangle.setHeight(dimension);                      // Set Rectangle shapes height
                                        Console.WriteLine("");
                                        Console.WriteLine("Area: {0}", rectangle.getArea()); // Output the Area
                                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                                        Console.WriteLine("--------------------------------------------");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        shapeSelect             = false; // Exits the shape selection loop
                                    }
                                    else
                                    {
                                        Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                        usersInput = "rectangle";
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "rectangle";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "rectangle";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Square
                        case "square":
                            try
                            {
                                if (square == null)
                                {
                                    square = new Square();
                                }
                                Console.WriteLine("Square\n");

                                Console.Write("Enter length or width:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    square.setLength(dimension);                      // Set Square shapes length
                                    square.setHeight(dimension);                      // Set Square shapes height
                                    Console.WriteLine("");
                                    Console.WriteLine("Area: {0}", square.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "square";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "square";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Cube
                        case "cube":
                            try
                            {
                                if (cube == null)
                                {
                                    cube = new Cube();
                                }
                                Console.WriteLine("Cube\n");

                                Console.Write("Enter edge(a length):\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    cube.setEdge(dimension);                          // Set Cube shapes edge
                                    Console.WriteLine("");
                                    Console.WriteLine("Volume: {0}", cube.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "cube";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "cube";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Circle
                        case "circle":
                            try
                            {
                                if (circle == null)
                                {
                                    circle = new Circle();
                                }
                                Console.WriteLine("Circle\n");

                                Console.Write("Enter radius:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    circle.setRadius(dimension);                      // Set Circle shapes radius
                                    Console.WriteLine("");
                                    Console.WriteLine("Area: {0}", circle.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "circle";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "circle";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Sphere
                        case "sphere":
                            try
                            {
                                if (sphere == null)
                                {
                                    sphere = new Sphere();
                                }
                                Console.WriteLine("Sphere\n");

                                Console.Write("Enter radius:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    sphere.setRadius(dimension);                        // Set Sphere shapes radius
                                    Console.WriteLine("");
                                    Console.WriteLine("Volume: {0}", sphere.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "sphere";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "sphere";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Triangle
                        case "triangle":
                            try
                            {
                                if (triangle == null)
                                {
                                    triangle = new Triangle();
                                }
                                Console.WriteLine("Triangle\n");

                                Console.Write("90 Degree angle triangle? Please enter: ");
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.Write("yes ");
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.Write("or ");
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.Write("no");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("\n\n> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine().ToLower();
                                Console.WriteLine();

                                if (usersInput == "yes")
                                {
                                    triangleType = true;
                                    Console.Write("Enter base:\n\n");
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.Write("> ");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    usersInput = Console.ReadLine();
                                    dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                    if (dimension > 0)
                                    {
                                        triangle.setBase(dimension);     // Set Triangle shapes base
                                        Console.Write("\nEnter height:\n\n");
                                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                                        Console.Write("> ");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        usersInput = Console.ReadLine();
                                        dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                        if (dimension > 0)
                                        {
                                            triangle.setHeight(dimension);                      // Set Triangle shapes height
                                            Console.WriteLine("");
                                            Console.WriteLine("Area: {0}", triangle.getArea()); // Output the Area
                                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                                            Console.WriteLine("--------------------------------------------");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            shapeSelect             = false; // Exits the shape selection loop
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("\nERROR");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            Console.WriteLine(": Number must be greater than 0\n");
                                            usersInput = "triangle";
                                        }
                                    }
                                    else
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.Write("\nERROR");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        Console.WriteLine(": Number must be greater than 0\n");
                                        usersInput = "triangle";
                                    }
                                }
                                else if (usersInput == "no")
                                {
                                    triangleType = false;
                                    Console.Write("Enter base:\n\n");
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.Write("> ");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    usersInput = Console.ReadLine();
                                    dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                    if (dimension > 0)
                                    {
                                        triangle.setBase(dimension);     // Set Triangle shapes base
                                        Console.Write("\nEnter side length:\n\n");
                                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                                        Console.Write("> ");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        usersInput = Console.ReadLine();
                                        dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                        if (dimension > 0)
                                        {
                                            triangle.setSide(dimension);     // Set Triangle shapes side

                                            Console.Write("\nEnter angle(degrees):\n\n");
                                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                                            Console.Write("> ");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            usersInput = Console.ReadLine();
                                            dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                            if (dimension > 0)
                                            {
                                                triangle.setAngle(dimension);     // Set Triangle shapes angle

                                                Console.WriteLine("");
                                                Console.WriteLine("Area: {0}", triangle.getAreaWithAngle());     // Output the Area
                                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                                Console.WriteLine("--------------------------------------------");
                                                Console.ForegroundColor = ConsoleColor.White;
                                                shapeSelect             = false; // Exits the shape selection loop
                                            }
                                            else
                                            {
                                                Console.ForegroundColor = ConsoleColor.Red;
                                                Console.Write("\nERROR");
                                                Console.ForegroundColor = ConsoleColor.White;
                                                Console.WriteLine(": Number must be greater than 0\n");
                                                usersInput = "triangle";
                                            }
                                        }
                                        else
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.Write("\nERROR");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            Console.WriteLine(": Number must be greater than 0\n");
                                            usersInput = "triangle";
                                        }
                                    }
                                    else
                                    {
                                        Console.ForegroundColor = ConsoleColor.Red;
                                        Console.Write("\nERROR");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        Console.WriteLine(": Number must be greater than 0\n");
                                        usersInput = "triangle";
                                    }
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.Write("ERROR");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    Console.WriteLine(": Invalid Input\n");
                                    usersInput = "triangle";     // sets the userInput to triangle to put the user back into trying to get the area for triangle
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Write("\nERROR");
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine(": Invalid Input\n");
                                usersInput = "triangle";
                            }
                            catch (Exception)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Write("\nERROR");
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine(": Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Octagon
                        case "octagon":
                            try
                            {
                                if (octagon == null)
                                {
                                    octagon = new Octagon();
                                }
                                Console.WriteLine("Octagon\n");

                                Console.Write("Enter side:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    octagon.setSide(dimension);                        // Set Octagon shapes side length
                                    Console.WriteLine("");
                                    Console.WriteLine("Area: {0}", octagon.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "octagon";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "octagon";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Hexagon
                        case "hexagon":
                            try
                            {
                                if (hexagon == null)
                                {
                                    hexagon = new Hexagon();
                                }
                                Console.WriteLine("Hexagon\n");

                                Console.Write("Enter side:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    hexagon.setSide(dimension);                        // Set Hexagon shapes side length
                                    Console.WriteLine("");
                                    Console.WriteLine("Area: {0}", hexagon.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "hexagon";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "hexagon";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region Pentagon
                        case "pentagon":
                            try
                            {
                                if (pentagon == null)
                                {
                                    pentagon = new Pentagon();
                                }
                                Console.WriteLine("Pentagon\n");

                                Console.Write("Enter side:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    pentagon.setSide(dimension);                        // Set Pentagon shapes side length
                                    Console.WriteLine("");
                                    Console.WriteLine("Area: {0}", pentagon.getArea()); // Output the Area
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.WriteLine("--------------------------------------------");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    shapeSelect             = false; // Exits the shape selection loop
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "pentagon";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "pentagon";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                            #region RectangularPrism
                        case "rectangular prism":
                            try
                            {
                                if (rp == null)
                                {
                                    rp = new RectangularPrism();
                                }
                                Console.WriteLine("Rectangular Prism\n");

                                Console.Write("Enter length:\n\n");
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                                Console.Write("> ");
                                Console.ForegroundColor = ConsoleColor.White;
                                usersInput = Console.ReadLine();
                                dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                if (dimension > 0)
                                {
                                    rp.setLength(dimension);     // Set RP shapes length
                                    Console.Write("\nEnter width:\n\n");
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                    Console.Write("> ");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    usersInput = Console.ReadLine();
                                    dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                    if (dimension > 0)
                                    {
                                        rp.setWidth(dimension);     // Set RP shapes width
                                        Console.Write("\nEnter height:\n\n");
                                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                                        Console.Write("> ");
                                        Console.ForegroundColor = ConsoleColor.White;
                                        usersInput = Console.ReadLine();
                                        dimension  = Convert.ToDouble(usersInput);    // Parse Input to Double
                                        if (dimension > 0)
                                        {
                                            rp.setHeight(dimension);                        // Set RP shapes height
                                            Console.WriteLine("");
                                            Console.WriteLine("Volume: {0}", rp.getArea()); // Output the Area
                                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                                            Console.WriteLine("--------------------------------------------");
                                            Console.ForegroundColor = ConsoleColor.White;
                                            shapeSelect             = false; // Exits the shape selection loop
                                        }
                                        else
                                        {
                                            Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                            usersInput = "rectangular prism";
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                        usersInput = "rectangular prism";
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("\nERROR: Number must be greater than 0\n");
                                    usersInput = "rectangular prism";
                                }
                            }
                            catch (FormatException)     // This catchs if they enter a string
                            {
                                Console.WriteLine("\nERROR: Must enter a valid number\n");
                                usersInput = "rectangular prism";
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n");
                                shapeSelect = false;
                            }
                            break;

                            #endregion
                        default:
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("ERROR");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine(": Invalid Input\n"); shapeSelect = false; break;     // Note: Setting the shapeSelect to false to avoid infinite loops.
                        }
                    }
                }
            }
        }
예제 #34
0
    private bool CheckNoMoreMovement()
    {
        for (int j = 0; j < _gridHeight; j++)
        {
            for (int i = 0; i < _gridWidth; i++)
            {
                Tile    tile       = _tilemap.GetTile(_startingCellPosition + new Vector3Int(i, j, 1)) as Tile;
                Hexagon hexaScript = tile.gameObject.GetComponent <Hexagon>();
                foreach (var linkedHexa in hexaScript.MyLinks)
                {
                    Tile    otherTile       = _tilemap.GetTile(_startingCellPosition + new Vector3Int(linkedHexa.X, linkedHexa.Y, 1)) as Tile;
                    Hexagon otherHexaScript = tile.gameObject.GetComponent <Hexagon>();

                    if (otherHexaScript.Y == hexaScript.Y)
                    {
                        var left = hexaScript.X < otherHexaScript.X ? hexaScript : otherHexaScript;
                        if (left.Y % 2 == 0)
                        {
                            if (
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X, left.Y + 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X, left.Y + 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 1, left.Y + 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 2, left.Y + 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X, left.Y - 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 1, left.Y + 1, 1)) as Tile)?.color == tile.color
                                )
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            if (
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X - 1, left.Y + 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X, left.Y + 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 1, left.Y + 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 1, left.Y + 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X, left.Y - 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(left.X + 1, left.Y + 1, 1)) as Tile)?.color == tile.color
                                )
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        var upper = hexaScript.Y > otherHexaScript.Y ? hexaScript : otherHexaScript;
                        if (upper.Y % 2 == 0)
                        {
                            if (
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y, 1)) as Tile)?.color == tile.color
                                )
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            if (
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X - 2, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X - 4, upper.Y + 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X + 1, upper.Y, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X + 2, upper.Y - 1, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X, upper.Y - 2, 1)) as Tile)?.color == tile.color ||
                                (_tilemap.GetTile(_startingCellPosition + new Vector3Int(upper.X + 1, upper.Y - 2, 1)) as Tile)?.color == tile.color
                                )
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
        }
        return(false);
    }
예제 #35
0
        private object GetFrontBlock(GameObject objA, GameObject objB)
        {
            // magic, don't touch.
            // any kind of randomness or antisymmetry in this function
            // will lead to cyclic dependencies in the drawing order graph,
            // resulting in neither object every being drawn.

            // tiles never overlap
            if (objA is MapTile && objB is MapTile)
            {
                return(null);
            }

            var boxA = objA.GetBounds();
            var boxB = objB.GetBounds();

            if (!boxA.IntersectsWith(boxB))
            {
                return(null);
            }

            var hexA = GetIsoBoundingBox(objA);
            var hexB = GetIsoBoundingBox(objB);

            var sepAxis = Hexagon.GetSeparationAxis(hexA, hexB);

            // tiles can only be in front based on z-axis separation
            if ((objA is MapTile) ^ (objB is MapTile) && sepAxis != Axis.Z)
            {
                return((objA is MapTile) ? objB : objA);
            }

            // flat stuff always loses
            if (objA.Drawable.Flat ^ objB.Drawable.Flat)
            {
                if (sepAxis != Axis.Z)
                {
                    return((objA.Drawable.Flat) ? objB : objA);
                }
            }

            switch (sepAxis)
            {
            case Axis.X:
                if (hexA.xMin > hexB.xMax)
                {
                    return(objA);
                }
                else if (hexB.xMin > hexA.xMax)
                {
                    return(objB);
                }
                break;

            case Axis.Y:
                if (hexA.yMin > hexB.yMax)
                {
                    return(objA);
                }
                else if (hexB.yMin > hexA.yMax)
                {
                    return(objB);
                }
                break;

            case Axis.Z:
                if (hexA.zMin > hexB.zMax)
                {
                    return(objA);
                }
                else if (hexB.zMin > hexA.zMax)
                {
                    return(objB);
                }
                break;
            }

            // units on bridges can only be drawn after the bridge
            if (objA is OverlayObject && SpecialOverlays.IsHighBridge(objA as OverlayObject) &&
                objB is OwnableObject && (objB as OwnableObject).OnBridge)
            {
                return(objB);
            }
            else if (objB is OverlayObject && SpecialOverlays.IsHighBridge(objB as OverlayObject) &&
                     objA is OwnableObject && (objA as OwnableObject).OnBridge)
            {
                return(objA);
            }

            // no proper separation is possible, if one of both
            // objects is flat then mark the other one as in front,
            // otherwise use the one with lowest y
            if (objA.Drawable.Flat && !objB.Drawable.Flat)
            {
                return(objB);
            }
            else if (objB.Drawable.Flat && !objA.Drawable.Flat)
            {
                return(objA);
            }

            // try to make distinction based on object type
            // tile, smudge, overlay, terrain, unit/building, aircraft
            var priorities = new Dictionary <Type, int> {
                { typeof(MapTile), 0 },
                { typeof(SmudgeObject), 1 },
                { typeof(OverlayObject), 2 },
                { typeof(TerrainObject), 3 },
                { typeof(StructureObject), 3 },
                { typeof(AnimationObject), 3 },
                { typeof(UnitObject), 3 },
                { typeof(InfantryObject), 3 },
                { typeof(AircraftObject), 4 },
            };
            int prioA = priorities[objA.GetType()];
            int prioB = priorities[objB.GetType()];

            if (prioA > prioB)
            {
                return(objA);
            }
            else if (prioA < prioB)
            {
                return(objB);
            }

            // finally try the minimal y coordinate
            if (boxA.Bottom > boxB.Bottom)
            {
                return(objA);
            }
            else if (boxA.Bottom < boxB.Bottom)
            {
                return(objB);
            }

            // finally if nothing worked up to here, which is very unlikely,
            // we'll use a tie-breaker that is at least guaranteed to yield
            // the same result regardless of argument order
            return(objA.Id < objB.Id ? objA : objB);
        }
예제 #36
0
    /// <summary>
    /// Take a hexagon from object pool and set its new properties for use
    /// </summary>
    /// <param name="_prev"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    Hexagon CreateNewHexagon(Hexagon _prev, int x, int y)
    {
        System.Random rnd = new System.Random();
        Vector2       offsetPosition, worldPosition, startPosition;
        float         startX = Helpers.GetGridStartX(gridWidth);

        // calculate offset world position
        offsetPosition = Helpers.HexOffset(x, y, startX);

        // assing offset positions to world position
        worldPosition = new Vector3(offsetPosition.x, offsetPosition.y, 0);
        startPosition = new Vector2(worldPosition.x, worldPosition.y + 20f);
        GameObject hexGO;

        // we are taking bomb from pool if bomb flag is true
        if (bombProduction)
        {
            hexGO = HexagonPool.Instance.GetPooledObject(true);
            //add to bomb list
            bombs.Add(hexGO.GetComponent <Bomb>());
            //and close bomb flag
            bombProduction = false;
        }
        else
        {
            hexGO = HexagonPool.Instance.GetPooledObject(false);
            hexGO.SetActive(true);
        }
        // get a game object from our pool and use it on grid
        hexGO.transform.position = startPosition;

        hexGO.transform.parent = gameObject.transform.GetChild(0);

        hexGO.name = $"X:{x} , Y:{y}";

        hexGO.SetActive(true);

        var hexagon = hexGO.GetComponent <Hexagon>();

        //setting world position
        hexagon.ChangeWorldPosition(worldPosition);
        //setting grid position
        hexagon.ChangeGridPosition(x, y);
        //Set random color
        hexagon.SetColor(colorList[rnd.Next(0, 1000) % colorList.Count]);

        // add new hexagon to out hexagon grid for keeping track
        hexagons[x, y] = hexagon;

        // close spot for production logical grid
        logicalGrid[x, y] = false;

        //calculating color match on creating
        if (!Helpers.CheckNull(_prev))
        {
            while (hexagon.Color == _prev.Color)
            {
                hexagon.SetColor(colorList[rnd.Next(0, 1000) % colorList.Count]);
            }
        }
        return(hexagon);
    }
예제 #37
0
 /// <summary>
 /// Set new grid grid position
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="h"></param>
 public void SetNewGridPosition(int x, int y, Hexagon h)
 {
     hexagons[x, y] = h;
 }
예제 #38
0
 public HexTile(Hexagon h)
 {
     index   = h.index;
     hexagon = h;
 }
예제 #39
0
    public IEnumerator CastSingleTargetAbility()
    {
        waiting = true;
        targets = null;
        List <AbilityModifier> mods = new List <AbilityModifier>();

        if (GetComponent <BoardUnit>().isEnfeebled)
        {
            mods.Add(new AbilityModifier(AbilityModifier.Modifier.Damage, .5f));
        }
        switch (AbilityInProgress.DisplayName)
        {
        case "SonicStrike": {
            targetHexagon.OccupiedUnit.ReceiveAbilityHit(AbilityInProgress, mods);
            mods.Add(new AbilityModifier(AbilityModifier.Modifier.Damage, .5f));
            TemplateManager.instance.TemplateHit(this, TemplateManager.TargetTemplate.Cone, 3, GetComponent <BoardUnit>().CurrentlyOccupiedHexagon, targetHexagon);
            while (waiting)
            {
                yield return(null);
            }
            for (int i = 0; i < targets.Count; i++)
            {
                Hexagon h = targets [i];
                if (HexagonHittable(h))
                {
                    h.OccupiedUnit.ReceiveAbilityHit(AbilityInProgress, mods);
                }
            }
            break;
        }

        case "StaticRush": {
            BoardUnit      u         = targetHexagon.OccupiedUnit;
            bool           collision = false;
            List <Hexagon> path      = BoardManager.instance.CanPushCharacter(GetComponent <BoardUnit>().CurrentlyOccupiedHexagon, targetHexagon, out collision);

            int     i    = 1;
            Hexagon curr = null;
            while (i < path.Count - 1)                     //Count-1 because the path leads ontop of another unit, so stop 1 short
            {
                curr = path[i];
                if (!collision && i == path.Count - 2)                         //If there was no collision, push them forwards
                {
                    path[path.Count - 2].OccupiedUnit.IssueMovement(path[path.Count - 1]);
                    mods.Add(new AbilityModifier(AbilityModifier.Modifier.RemoveStunEffect, 1));                              //If we are pushing them we dont stun
                }
                GetComponent <BoardUnit>().IssueMovement(curr);
                yield return(new WaitForSeconds(0.33f));

                i++;
            }
            u.ReceiveAbilityHit(AbilityInProgress, mods);

            break;
        }

        default: {
            targetHexagon.OccupiedUnit.ReceiveAbilityHit(AbilityInProgress, mods);
            break;
        }
        }
        castingAbility = false;
    }
예제 #40
0
 public void init()
 {
     gun     = new Gun((int)X, (int)Y, Face: Face);
     hexagon = new Hexagon(X, Y);
 }
예제 #41
0
    /// <summary>
    /// This method will remove matched hexagons from game and open place in logical grid for missing hexagons
    /// </summary>
    /// <param name="matchList"></param>
    /// <returns></returns>
    public IEnumerator HandleMatch(List <Hexagon> matchList)
    {
        if (matchList.Count > 0 && state == States.ExplosionState)
        {
            // Sound and score delegates for listeners
            PlaySound?.Invoke(SoundTypes.Explosion);
            OnPlayerScore?.Invoke(HexMetrics.SCORE_MULTIPLIER * matchList.Count);
            foreach (var item in matchList)
            {
                if (item.GetType() != typeof(Bomb))
                {
                    BombTick?.Invoke();
                }
                //Removing every hex from game logic
                RemoveHexFromGame(item);

                yield return(new WaitForSeconds(HexMetrics.EXPLOSION_DELAY));
            }

            yield return(new WaitForSeconds(HexMetrics.AFTER_EXPLOSION_DELAY));

            //this loop rearrange all hexes in correct positions
            for (int x = 0; x < logicalGrid.GetLength(0); x++)
            {
                bool space  = false;
                int  spaceY = 0;
                var  y      = 0;

                while (y <= logicalGrid.GetLength(1) - 1)
                {
                    Hexagon h = hexagons[x, y];
                    if (space)
                    {
                        if (!Helpers.CheckNull(h))
                        {
                            h.ChangeGridPosition(x, spaceY);
                            logicalGrid[x, spaceY] = false;
                            hexagons[x, y]         = null;
                            logicalGrid[x, y]      = true;
                            h.ChangeWorldPosition(Helpers.HexOffset(x, spaceY, Helpers.GetGridStartX(gridWidth)));
                            space = false;
                            y     = spaceY;

                            spaceY = 0;
                        }
                    }
                    else if (Helpers.CheckNull(h))
                    {
                        space = true;
                        if (spaceY == 0)
                        {
                            spaceY = y;
                        }
                    }
                    y++;
                }
            }

            SetState(States.PlacingState);
            StartCoroutine(PlaceCellsOnGrid(logicalGrid, false));
        }
    }