コード例 #1
0
        public void InitializeSfml()
        {
            var tilesets = new EditorTilesets();

            model     = new HexModel(40);
            resources = new ResourceManager();
            resources.Add(tilesets);

            CreateBrushes(tilesets);
            toolBar.SelectPlayer(PlayerColour.Red);

            world = new Map(model, resources);
            world.Create(new Vector2i(10, 10));

            window     = drawingSurface.InitializeSfml();
            editorView = new EditorView(window, world);

            window.OnKeyPress(Keyboard.Key.Space, () => editorView.Return());
            window.OnKeyHold(Keyboard.Key.Left, () => editorView.Scroll(Direction.Left));
            window.OnKeyHold(Keyboard.Key.Right, () => editorView.Scroll(Direction.Right));
            window.OnKeyHold(Keyboard.Key.Up, () => editorView.Scroll(Direction.Up));
            window.OnKeyHold(Keyboard.Key.Down, () => editorView.Scroll(Direction.Down));
            window.OnKeyHold(Keyboard.Key.Add, editorView.IncrementScrollSpeed);
            window.OnKeyHold(Keyboard.Key.Subtract, editorView.DecrementScrollSpeed);
        }
コード例 #2
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit hit;
         Ray        ray       = Camera.main.ScreenPointToRay(Input.mousePosition);
         int        layerMask = LayerIDForHexTiles.value;
         if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
         {
             GameObject go     = hit.rigidbody.gameObject;
             GameObject parent = go.transform.parent.gameObject;
             //Debug.Log(parent.name);
             HexModel hmodel      = hm.getMap()[parent];
             int      hmodelIndex = em.hexes.FindIndex(d => d == hmodel);
             Debug.Log("Size: " + em.hexes.Count + " Index: " + hmodelIndex);
             if (hmodelIndex >= 0 && em.hexes[hmodelIndex].type != HexMaterials[em.currentTool.value].name)
             {
                 Debug.Log("Drawing " + HexMaterials[em.currentTool.value].name);
                 em.hexes[hmodelIndex].type = HexMaterials[em.currentTool.value].name;
                 hm.getMap().Remove(parent);
                 GameObject.Destroy(parent);
                 em.notifyObservers();
             }
         }
         else
         {
         }
     }
 }
コード例 #3
0
ファイル: MapInteractor.cs プロジェクト: bhaddad5/Hexmaster
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            HexModel hex = GetRaycastedHex();
            if (hex != null)
            {
                HandleHexSelection(hex);
            }
        }
        if (Input.GetMouseButtonDown(1))
        {
            HexModel hex = GetRaycastedHex();
            if (hex != null)
            {
                SelectedUnitController.MoveAttempted(hex);
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            HexView[] hexViews = FindObjectsOfType(typeof(HexView)) as HexView[];
            foreach (HexView hexView in hexViews)
            {
                hexView.ToggleCoordinates();
            }
        }
    }
コード例 #4
0
    public void Execute()
    {
        _planet = _planetController.SelectedPlanet;
        for (int i = 0; i <= 100; i++)
        {
            _planet.Props[R.Temperature].HexDistribution[i].Weight = 0f;
            _planet.Props[R.Pressure].HexDistribution[i].Weight    = 0f;
            _planet.Props[R.Humidity].HexDistribution[i].Weight    = 0f;
            _planet.Props[R.Radiation].HexDistribution[i].Weight   = 0f;
        }

        for (int x = 0; x < _planet.Map.Width; x++)
        {
            for (int y = 0; y < _planet.Map.Height; y++)
            {
                _hex = _planet.Map.Table[x][y];
                _hexUpdateCommand.Execute(_hex);

                _planet.Props[R.Temperature].HexDistribution[Mathf.FloorToInt(_hex.Props[R.Temperature].Value * 100)].Weight += .05f;
                _planet.Props[R.Pressure].HexDistribution[Mathf.FloorToInt(_hex.Props[R.Pressure].Value * 100)].Weight       += .05f;
                _planet.Props[R.Humidity].HexDistribution[Mathf.FloorToInt(_hex.Props[R.Humidity].Value * 100)].Weight       += .05f;
                _planet.Props[R.Radiation].HexDistribution[Mathf.FloorToInt(_hex.Props[R.Radiation].Value * 100)].Weight     += .05f;
            }
        }
    }
コード例 #5
0
 private void OnHexChange(HexModel value)
 {
     _hex = value;
     if (_hex == null)
     {
         _building = null;
         BuildPanel.SetActive(true);
         BuildButton.interactable = false;
     }
     else
     if (_hex.Building != null)
     {
         SetBuilding(_hex);
         BuildPanel.SetActive(false);
     }
     else
     {
         _building = null;
         BuildPanel.SetActive(true);
         if (_hex.Unit == null)
         {
             BuildButton.interactable = false;
         }
         else
         {
             BuildButton.interactable = true;
         }
     }
 }
コード例 #6
0
    public void InitializeModel()
    {
        HexModel = gameObject.AddComponent <HexModel>();

        HexModel.GenMesh();
        //hex.renderer.material.mainTexture = Resources.Load("textures/hex") as Texture2D;
    }
コード例 #7
0
    public void Execute(HexModel hex)
    {
        if (_planet == null)
        {
            return;
        }

        /**/
        UpdateProp(Temperature, hex.Props[R.Temperature]);
        UpdateProp(Pressure, hex.Props[R.Pressure]);
        UpdateProp(Humidity, hex.Props[R.Humidity]);
        //UpdateProp( Radiation, hex.Props[ R.Radiation ] );
        /**/

        float altitude = hex.Props[R.Altitude].Value / 2f;

        if (Humidity.Value > altitude)
        {
            hex.Props[R.Humidity].Value     = 1f;
            hex.Props[R.Pressure].Value    += ((float)Humidity.Value - altitude) * 1f;
            hex.Props[R.Temperature].Value -= (hex.Props[R.Temperature].Value - .5f) * .33f;
        }

        hex.Props[R.Temperature].Color = Color.Lerp(Color.red, Color.green, _resistanceConfig[R.Temperature].GetFloatAt(hex.Props[R.Temperature].Value));
        hex.Props[R.Humidity].Color    = Color.Lerp(Color.red, Color.green, _resistanceConfig[R.Humidity].GetFloatAt(hex.Props[R.Humidity].Value));
        hex.Props[R.Pressure].Color    = Color.Lerp(Color.red, Color.green, _resistanceConfig[R.Pressure].GetFloatAt(hex.Props[R.Pressure].Value));

        if (hex.Unit != null)
        {
            _unitDefenseUpdateCommand.Execute(hex.Unit);
        }
    }
コード例 #8
0
 private void TryAddAdjacency(int x, int z, HexModel hex)
 {
     if (x < Map.Length && x >= 0 &&
         z < Map[0].Length && z >= 0)
     {
         hex.Neighbors.Add(Map[x][z]);
     }
 }
コード例 #9
0
        // GET: api/Login/5

        public USER_MASTER Get(int id)
        {
            using (HexModel db = new HexModel())
            {
                List <USER_MASTER> users = db.USER_MASTER.ToList();
                return(users[0]);
            }
        }
コード例 #10
0
        public void UpdateHexViewModelFromModel_UnselectHex(HexModel hexModel)
        {
            var hexViewModel = GetHexViewModel(hexModel.Column, hexModel.Row);

            if (hexViewModel != null)
            {
                hexViewModel.UnselectHex();
            }
        }
コード例 #11
0
        public void UpdateHexViewModelFromModel_DegreExploration(HexModel hexModel)
        {
            var hexViewModel = GetHexViewModel(hexModel.Column, hexModel.Row);

            if (hexViewModel != null)
            {
                hexViewModel.UpdateDegreExploration(hexModel.DegreExploration);
            }
        }
コード例 #12
0
ファイル: Hex.cs プロジェクト: jconstable/HexGridManager
 public void Start()
 {
     GameObject hex = new GameObject();
     HexModel = hex.AddComponent< HexModel > ();
     HexModel.GridSize = GridSize;
     hex.transform.parent = transform;
     hex.transform.localPosition = new Vector3(0, 0, 0);
     hex.GetComponent<Renderer>().material = MaterialToUse;
 }
コード例 #13
0
 private void CheckAndMark(int x, int y, UnitModel unit)
 {
     _hex = _hexMapModel.Table[x][y];
     if (_hex.Unit == null)
     {
         _hex.isMarked.Value   = true;
         _hex.isExplored.Value = true;
         _markedHexes.Add(_hex);
     }
 }
コード例 #14
0
ファイル: MapController.cs プロジェクト: bhaddad5/Hexmaster
    private static void HandleCombat(UnitModel attacker, UnitModel defender, HexModel location)
    {
        float defenderDamage = DmgScale * (attacker.GetAttackValue() / defender.GetDefenseValue());

        defender.InvokeUpdateHP(defender.HealthCurr - defenderDamage);

        float attackerDamage = DmgScale * (defender.GetDefenseValue() / attacker.GetAttackValue());

        attacker.InvokeUpdateHP(attacker.HealthCurr - attackerDamage);
    }
コード例 #15
0
ファイル: Hex.cs プロジェクト: leelnfei/HexGridManager
    public void Start()
    {
        GameObject hex = new GameObject();

        HexModel                               = hex.AddComponent <HexModel> ();
        HexModel.GridSize                      = GridSize;
        hex.transform.parent                   = transform;
        hex.transform.localPosition            = new Vector3(0, 0, 0);
        hex.GetComponent <Renderer>().material = MaterialToUse;
    }
コード例 #16
0
    private void SetHex(HexModel hex, R type, float minAltitude = 0)
    {
        //normalize value to be between 0 - 1
        hex.Props[type].Delta = _planetModel.Props[type].Variation * (Mathf.InverseLerp(Ranges[(int)type].x, Ranges[(int)type].y, hex.Props[type].Delta) - 0.5f);

        //add variation to properties based on planet values
        hex.Props[type].Value = Mathf.Clamp((float)_planetModel.Props[type].Value + hex.Props[type].Delta, minAltitude, 1);

        hex.Props[type].Color = Color.Lerp(Color.red, Color.green, _resistanceConfig[type].GetFloatAt(hex.Props[type].Value));
    }
コード例 #17
0
ファイル: GameLogic.cs プロジェクト: vlad-malkav/VersionBase
        public void SetSelectedColorImageFromHexPosition(int column, int row)
        {
            HexModel hexModel = GetHexModelFromPosition(column, row).Result;

            Messenger.Default.Send(new SetSelectedColorImageIdsRequestMessage
            {
                TileColorModelId = hexModel.TileColorModel.Id,
                TileImageModelId = hexModel.TileImageModel.Id
            });
        }
コード例 #18
0
 private void CheckAndMark(int x, int y, UnitModel unit)
 {
     _hex = _hexMapModel.Table[x][y];
     if (_hex.Unit == null && Math.Abs(_hex.Props[R.Altitude].Value - unit.Props[R.Altitude].Value) <= .5)        //check if it can climb
     {
         _hex.isMarked.Value   = true;
         _hex.isExplored.Value = true;
         _markedHexes.Add(_hex);
     }
 }
コード例 #19
0
 private void SelectHex(HexModel hexModel)
 {
     Label             = hexModel.GetLabel();
     Description       = hexModel.Description;
     DegreExploration  = hexModel.DegreExploration;
     SelectedHexColumn = hexModel.Column;
     SelectedHexRow    = hexModel.Row;
     SelectedHexColor  = hexModel.TileColorModel.Name;
     SelectedHexImage  = hexModel.TileImageModel.Name;
     IsHexSelected     = true;
 }
コード例 #20
0
ファイル: HexMap.cs プロジェクト: nikbr/Heroes-of-Might
 private bool ContainsValue(HexModel h)
 {
     foreach (KeyValuePair <GameObject, HexModel> hex in map)
     {
         if (h.Q == hex.Value.Q && h.R == hex.Value.R)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #21
0
    public void ExecuteHex(HexModel hex)
    {
        hex.Props[R.HexScore].Value =
            (GetPropBellCurveValue(R.Temperature, hex) +
             GetPropBellCurveValue(R.Pressure, hex) +
             GetPropBellCurveValue(R.Humidity, hex)     // +
             //GetPropBellCurveValue( R.Radiation, hex )
            ) / 3f;

        hex.Props[R.HexScore].Color = Color.Lerp(Color.red, Color.green, hex.Props[R.HexScore].Value);
    }
コード例 #22
0
        public void UpdateHexViewModelFromModel_TileData(HexModel hexModel)
        {
            var hexViewModel = GetHexViewModel(hexModel.Column, hexModel.Row);

            if (hexViewModel != null)
            {
                hexViewModel.UpdateTileData(
                    hexModel.TileColorModel.GetDrawingColor(),
                    hexModel.TileImageModel.ImageName);
            }
        }
コード例 #23
0
    public void InitializeModel()
    {
        var hex = new GameObject();

        hex.AddComponent <HexModel>();
        HexModel                    = hex.GetComponent <HexModel>();
        hex.transform.parent        = transform;
        hex.transform.localPosition = new Vector3(0, 0, 0);
        hex.GetComponent <Renderer>().material.shader      = Shader.Find("Diffuse");
        hex.GetComponent <Renderer>().material.mainTexture = Resources.Load("textures/hex") as Texture2D;
    }
コード例 #24
0
    private void SetInitialHexValue(HexModel hex, R lens, float value)
    {
        hex.Props[lens].Delta = value;

        if (value > Ranges[(int)lens].y)
        {
            Ranges[(int)lens].y = value;
        }
        if (value < Ranges[(int)lens].x)
        {
            Ranges[(int)lens].x = value;
        }
    }
コード例 #25
0
    private void OnHexChange(HexClickedMessage message)
    {
        disposables.Clear();
        _hex = message.Hex;

        _hex.Props[R.Altitude]._Value.Subscribe(_ => Altitude.SetValue(GetPropValue(_))).AddTo(disposables);
        //hex.Props[ R.Temperature ]._Value.Subscribe( _ => Temperature.SetValue( ( _ * 873 ) - 273 ) ).AddTo( disposables );
        _hex.Props[R.Temperature]._Value.Subscribe(_ => Temperature.SetValue(GetPropValue(_))).AddTo(disposables);
        _hex.Props[R.Pressure]._Value.Subscribe(_ => Pressure.SetValue(GetPropValue(_))).AddTo(disposables);
        _hex.Props[R.Humidity]._Value.Subscribe(_ => Humidity.SetValue(GetPropValue(_))).AddTo(disposables);
        _hex.Props[R.Radiation]._Value.Subscribe(_ => Radiation.SetValue(GetPropValue(_))).AddTo(disposables);
        _hex.Props[R.HexScore]._Value.Subscribe(_ => HexScore.SetValue(_)).AddTo(disposables);
    }
コード例 #26
0
    public void ExecuteAverageArmorInTime(UnitModel unit, float timeDelta)
    {
        _tempHexModel = _planet.Map.Table[unit.X][unit.Y];
        _tempUnit     = unit;

        unit.Props[R.Armor].Value =
            (
                GetAverage(R.Temperature, timeDelta) +
                GetAverage(R.Pressure, timeDelta) +
                GetAverage(R.Humidity, timeDelta) //+
                //GetAverage( R.Radiation, timeDelta )
            ) / 3;
    }
コード例 #27
0
ファイル: SaveHelper.cs プロジェクト: vlad-malkav/VersionBase
        public static HexData SaveHexModel(HexModel hexModel)
        {
            HexData hexData = new HexData
            {
                Column   = hexModel.Column,
                Row      = hexModel.Row,
                TileData = new TileData(
                    new TileColorData(hexModel.TileColorModel.GetDrawingColor()),
                    new TileImageData(hexModel.TileImageModel.Id)),
                DegreExploration = hexModel.DegreExploration,
                Description      = hexModel.Description
            };

            return(hexData);
        }
コード例 #28
0
ファイル: Hex.cs プロジェクト: atamis/hexdecks
        public void init(WorldMap w, HexLoc loc)
        {
            this.loc = loc;
            this.w   = w;
            this.transform.position = GameManager.l.HexPixel(loc);

            tileType = TileType.Normal;
            triggers = new List <Trigger>();
            selected = false;

            model = new GameObject("Hex Model").AddComponent <HexModel> ();
            model.init(this);

            model.transform.parent  = transform;
            transform.localPosition = GameManager.l.HexPixel(loc);
        }
コード例 #29
0
    public void Execute(UnitModel unit)
    {
        if (_planet == null)
        {
            return;
        }

        _tempHexModel             = _planet.Map.Table[unit.X][unit.Y];
        unit.Props[R.Armor].Value =
            (
                unit.Resistance[R.Temperature].GetFloatAt(_tempHexModel.Props[R.Temperature].Value) +
                unit.Resistance[R.Pressure].GetFloatAt(_tempHexModel.Props[R.Pressure].Value) +
                unit.Resistance[R.Humidity].GetFloatAt(_tempHexModel.Props[R.Humidity].Value)   //+
                //unit.Resistance[ R.Radiation ].GetFloatAt( _tempHexModel.Props[ R.Radiation ].Value )
            ) / 3;
    }
コード例 #30
0
    private void SetBuilding(HexModel hex)
    {
        disposables.Clear();

        _building = _hex.Building;
        _building._State.Subscribe(_ => SetState()).AddTo(disposables);

        _abilityMessage.Index = _building.Index;
        _abilityMessage.X     = _building.X;
        _abilityMessage.Y     = _building.Y;

        NameText.text        = _building.Name;
        DescriptionText.text = "PRICE: " + _pay.GetUnlockPrice(_building.Index);

        RemoveAllChildren(EffectsGrid);
        RemoveAllChildren(MaintenanceGrid);

        foreach (KeyValuePair <R, float> item in _building.Effects)
        {
            if (item.Key == R.Minerals)
            {
                AddEffect(MaintenanceGrid, R.Minerals, item.Value);
            }
            else
            if (item.Value < 0)
            {
                AddEffect(EffectsGrid, item.Key, item.Value);
            }
        }
        foreach (KeyValuePair <R, float> item in _building.Effects)
        {
            if (item.Value > 0)
            {
                AddEffect(EffectsGrid, item.Key, item.Value);
            }
        }

        if (hex.Unit != null)
        {
            SetState();
        }
        else
        {
            ActivateButton.interactable = false;
            DemolishButton.interactable = false;
        }
    }
コード例 #31
0
    public static void ExecuteAIMove(UnitModel unit)
    {
        HexModel hex = MapController.Model.GetHex(unit.CurrentPos);

        MoveOptions possibleMoves = hex.PossibleMoves(unit.MovementCurr, unit.Faction);

        SortedDupList <UnitMoves> RankedMoves = new SortedDupList <UnitMoves>();

        RankedMoves.Insert(new UnitMoves(hex), hex.DefenseMod);

        foreach (HexModel potentialMove in possibleMoves.Movable.Keys)
        {
            RankedMoves.Insert(new UnitMoves(potentialMove), potentialMove.DefenseMod);
        }

        foreach (HexModel potentialAttack in possibleMoves.Attackable.Keys)
        {
            UnitModel UnitToAttack = MapController.Model.GetUnit(potentialAttack.Coord);
            RankedMoves.Insert(new UnitMoves(potentialAttack), hex.DefenseMod + GetAttackGoodness(unit, UnitToAttack));
        }

        foreach (KeyValuePair <HexModel, float> pair in possibleMoves.Movable)
        {
            foreach (HexModel attackableNeighbor in pair.Key.Neighbors)
            {
                if (pair.Value - attackableNeighbor.MoveDifficulty >= 0 &&
                    attackableNeighbor.ContainsEnemy(unit.Faction))
                {
                    UnitModel UnitToAttack = MapController.Model.GetUnit(attackableNeighbor.Coord);
                    RankedMoves.Insert(new UnitMoves(pair.Key, attackableNeighbor), pair.Key.DefenseMod + GetAttackGoodness(unit, UnitToAttack));
                }
            }
        }

        Debug.Log(unit.UnitName + " ranked moves: ");
        foreach (KeyValuePair <float, UnitMoves> rankedMove in RankedMoves.GetList())
        {
            string moves = "";
            foreach (HexModel move in rankedMove.Value.Moves)
            {
                moves = moves + ", " + move.Coord.ToString();
            }
            Debug.Log(rankedMove.Key + ", " + moves);
        }

        ExecuteChosenMoves(unit, RankedMoves.TopValue());
    }