예제 #1
0
        public void Build()
        {
            builder.Build(info);
            var firstBonusLocation = new FieldCoords(info.Width / 2, info.Length / 2);

            SpawnBonus(Bonus.Growth, firstBonusLocation);
        }
예제 #2
0
 protected override void OnStart()
 {
     _direction = Context.GetValue <SharedValue <FieldCoords> >(ActionConsts.UnitDirection).Value;
     _speed     = Context.GetValue <SharedValue <float> >(ActionConsts.UnitSpeed).Value * 1.5f;
     _unit      = Context.GetValue <GameEntity>(ActionConsts.Unit);
     _leftTime  = _time;
 }
예제 #3
0
        public VisualState()
        {
            _FieldMap    = new Tuple <FieldCoords, Point> [19];
            _FieldMap[0] = Tuple.Create(FieldCoords.Center, GetFieldCoords(-1, -1));
            int i = 1;

            for (int en = 0; en < 3; en++)
            {
                for (int fn = 0; fn < 6; fn++)
                {
                    _FieldMap[i] = Tuple.Create(FieldCoords.NewEdge(en, fn), GetFieldCoords(en, fn));
                    i++;
                }
            }

            _MainPictureBox      = new PictureBox();
            _MainPictureBox.Size = new Size(_CanvasSize, _CanvasSize);
            this.Controls.Add(_MainPictureBox);
            _MainPictureBox.Dock = DockStyle.Fill;

            _MainPictureBox.MouseMove  += HandleMouseMove;
            _MainPictureBox.MouseLeave += (s, e) =>
                                          HandleMouseMove(s, new MouseEventArgs(MouseButtons.None, 0, -1, -1, -1));
            _MainPictureBox.MouseClick += HandleMouseClick;
        }
예제 #4
0
        private void DrawField(Graphics canvas, FieldCoords coords, FieldState state, FieldDrawType drawType)
        {
            int en = coords.IsCenter ? -1 : ((FieldCoords.Edge)coords).Item1;
            int fn = coords.IsCenter ? -1 : ((FieldCoords.Edge)coords).Item2;

            DrawField(canvas, en, fn, state, drawType);
        }
예제 #5
0
        private IEnumerable <MoveElementCoordsModel> FindDropElements(VisualElementModel[,] grid)
        {
            for (var coll = 0; coll < grid.GetLength(0); coll++)
            {
                for (var row = 0; row < grid.GetLength(1); row++)
                {
                    var currentElement = grid[coll, row];
                    if (currentElement.Name == GameElementType.Empty)
                    {
                        var endMove = new FieldCoords(coll, row);
                        for (var dropRow = row; dropRow < grid.GetLength(1); dropRow++)
                        {
                            var dropElement = grid[coll, dropRow];
                            if (dropElement.Name != GameElementType.Empty)
                            {
                                var startMove = new FieldCoords(coll, dropRow);
                                yield return(new MoveElementCoordsModel(startMove, endMove));

                                endMove = startMove;
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
 public void SpawnBonus(Bonus bonus)
 {
     var where = new FieldCoords()
     {
         X = random.Next(info.Width),
         Y = random.Next(info.Length),
     };
     SpawnBonus(bonus, where);
 }
예제 #7
0
 public void SpawnBonus(Bonus bonus, FieldCoords where)
 {
     if (bonusesOnMap.ContainsKey(where))
     {
         Debug.Log("Bonus spawn location is occupied.");
         return;
     }
     bonusesOnMap.Add(where, bonus);
     builder.SpawnBonus(bonus, where);
 }
예제 #8
0
        private Point GetFieldCoords(FieldCoords coords)
        {
            if (coords.IsCenter)
            {
                return(GetFieldCoords(-1, -1));
            }
            var edge = (FieldCoords.Edge)coords;

            return(GetFieldCoords(edge.Item1, edge.Item2));
        }
예제 #9
0
        public void DestroyBonus(FieldCoords where)
        {
            Transform bonusView;

            if (spawnedBonuses.TryGetValue(where, out bonusView))
            {
                spawnedBonuses.Remove(where);
                GameObject.Destroy(bonusView.gameObject);
            }
        }
예제 #10
0
        private void SpawnBodySegment(FieldCoords coords)
        {
            var segment = new BodySegment();

            segment.Position = coords;
            segments.Add(segment);
            var pos         = segment.Position.ToVector3();
            var segmentView = GameObject.Instantiate(settings.BodySegment, pos, Quaternion.identity, bodyContainer);

            segment.SetView(segmentView);
        }
예제 #11
0
        private void MakeStep()
        {
            var         firstSegmentPos = segments[0].Position;
            var         direction       = input.GetLastDirection();
            FieldCoords deltaPos;

            switch (direction)
            {
            case MoveDirection.Up:
                deltaPos = FieldCoords.up;
                break;

            case MoveDirection.Right:
                deltaPos = FieldCoords.right;
                break;

            case MoveDirection.Down:
                deltaPos = FieldCoords.down;
                break;

            case MoveDirection.Left:
                deltaPos = FieldCoords.left;
                break;

            default:
                throw new NotImplementedException(string.Format("Unknown move direction", direction));
            }
            FieldCoords nextPos = firstSegmentPos + deltaPos;

            if (segments.Count > 1)
            {
                var secondSegmentPos = segments[1].Position;
                if (nextPos == secondSegmentPos)
                {
                    // incorrect direction input
                    nextPos = firstSegmentPos - deltaPos;
                }
            }

            for (int i = 0; i < segments.Count; i++)
            {
                var segment = segments[i];
                var oldPos  = segment.Position;
                segment.Position        = nextPos;
                segment.View.position   = nextPos.ToVector3();
                segment.View.localScale = bonuses.Has(nextPos) ? fatSegmentScale : Vector3.one;

                nextPos = oldPos;
            }
            if (bonuses.Use(nextPos))
            {
                SpawnBodySegment(nextPos);
            }
        }
예제 #12
0
        public void SpawnBonus(Bonus what, FieldCoords where)
        {
            Transform prefab;

            if (bonusPrefabs.TryGetValue(what, out prefab))
            {
                var pos = where.ToVector3();
                pos.y = bonusSpawnHeight;
                var bonusView = GameObject.Instantiate(prefab, pos, Quaternion.identity, fieldRoot);
                spawnedBonuses.Add(where, bonusView);
            }
        }
예제 #13
0
 private void ClearMarks(Graphics canvas)
 {
     if (_HighlightedField != null)
     {
         DrawField(canvas, _HighlightedField, State[_HighlightedField], FieldDrawType.Default);
     }
     if (_SelectedField != null)
     {
         DrawField(canvas, _SelectedField, State[_SelectedField], FieldDrawType.Default);
     }
     _SelectedField    = null;
     _HighlightedField = null;
 }
예제 #14
0
        private bool CanBeHighlighted(FieldCoords field)
        {
            if (State[field].IsColor && ((FieldState.Color)State[field]).Item.Equals(CurrentPlayer))
            {
                return(_ValidMoves.Any(m => m.Item1.Equals(field)));
            }

            if (_SelectedField != null && State[field].IsEmpty)
            {
                return(_ValidMoves.Any(m => m.Item1.Equals(_SelectedField) && m.Item3.Equals(field)));
            }
            return(false);
        }
예제 #15
0
        private FieldCoords MouseMoveCoordsToDirecting(FieldCoords mouseDownCoords, FieldCoords mouseUpCoords)
        {
            var deltaCor = mouseUpCoords - mouseDownCoords;

            if (Mathf.Abs(deltaCor.X) == Mathf.Abs(deltaCor.Y))
            {
                return(FieldCoords.zero);
            }
            if (Mathf.Abs(deltaCor.X) > Mathf.Abs(deltaCor.Y))
            {
                return(new FieldCoords(deltaCor.X / Mathf.Abs(deltaCor.X), 0));
            }
            return(new FieldCoords(0, deltaCor.Y / Mathf.Abs(deltaCor.Y)));
        }
예제 #16
0
        private void HandleMouseClick(object sender, MouseEventArgs mouseEventArgs)
        {
            if (_HighlightedField == null)
            {
                return;
            }
            var hit = HitTest(mouseEventArgs.Location);

            if (!hit.HasValue)
            {
                return;
            }

            var         highlighted = _HighlightedField;
            FieldCoords selected    = null;

            if (hit.Value.Item2.IsColor)
            {
                var clickedColor = ((FieldState.Color)hit.Value.Item2).Item;
                if (clickedColor.Equals(CurrentPlayer))
                {
                    selected = hit.Value.Item1;
                }
            }
            else
            {
                if (_SelectedField != null)
                {
                    if (CheckValidMove(_SelectedField, hit.Value.Item1))
                    {
                        selected    = null;
                        highlighted = null;
                        MoveRequested.Raise(this, Tuple.Create(_SelectedField, hit.Value.Item1));
                    }
                    else
                    {
                        selected = _SelectedField;
                    }
                }
            }

            using (var canvas = Graphics.FromImage(_MainPictureBox.Image))
            {
                ClearMarks(canvas);
                SetMarks(canvas, highlighted, selected);
            }
            _MainPictureBox.Invalidate();
        }
예제 #17
0
        public Bonus TryConsumeBonusAt(FieldCoords coords)
        {
            Bonus res = Bonus.None;

            if (bonusesOnMap.TryGetValue(coords, out res))
            {
                bonusesOnMap.Remove(coords);
                builder.DestroyBonus(coords);
                consumedCount++;
                // check respawn
                var bonusesToSpawn = settings.Bonuses.Where(b => consumedCount % b.Frequency == 0);
                foreach (var bonus in bonusesToSpawn)
                {
                    SpawnBonus(bonus.type);
                }
            }
            return(res);
        }
예제 #18
0
 private void SetMarks(Graphics canvas, FieldCoords highlighted, FieldCoords selected)
 {
     _HighlightedField = highlighted;
     _SelectedField    = selected;
     if (highlighted == null && selected == null)
     {
         return;
     }
     if (highlighted?.Equals(selected) == true)
     {
         DrawField(canvas, highlighted, State[highlighted], FieldDrawType.Highlighted | FieldDrawType.Selected);
         return;
     }
     if (highlighted != null)
     {
         DrawField(canvas, highlighted, State[highlighted], FieldDrawType.Highlighted);
     }
     if (selected != null)
     {
         DrawField(canvas, selected, State[selected], FieldDrawType.Selected);
     }
 }
예제 #19
0
        private void DrawLine(Graphics canvas, FieldCoords from, FieldCoords to, FieldCoords over)
        {
            Point pFrom, pTo;
            Point pOver = Point.Empty;

            {
                int en = from.IsCenter ? -1 : ((FieldCoords.Edge)from).Item1;
                int fn = from.IsCenter ? -1 : ((FieldCoords.Edge)from).Item2;
                pFrom = GetFieldCoords(en, fn);
            }
            {
                int en = to.IsCenter ? -1 : ((FieldCoords.Edge)to).Item1;
                int fn = to.IsCenter ? -1 : ((FieldCoords.Edge)to).Item2;
                pTo = GetFieldCoords(en, fn);
            }
            if (over != null)
            {
                int en = over.IsCenter ? -1 : ((FieldCoords.Edge)over).Item1;
                int fn = over.IsCenter ? -1 : ((FieldCoords.Edge)over).Item2;
                pOver = GetFieldCoords(en, fn);
            }

            Pen pen = over != null
            ? new Pen(Color.DarkOrange, 3)
            : new Pen(Color.LimeGreen, 6);

            if (over != null)
            {
                canvas.DrawLine(pen, pFrom, pOver);
                canvas.DrawLine(pen, pOver, pTo);
            }
            else
            {
                canvas.DrawLine(pen, pFrom, pTo);
            }
        }
예제 #20
0
        private void DrawLine(Graphics canvas, FieldCoords from, FieldCoords to, FieldCoords over)
        {
            Point pFrom, pTo;
            Point pOver = Point.Empty;
            {
                int en = from.IsCenter ? -1 : ((FieldCoords.Edge)from).Item1;
                int fn = from.IsCenter ? -1 : ((FieldCoords.Edge)from).Item2;
                pFrom = GetFieldCoords(en, fn);
            }
            {
                int en = to.IsCenter ? -1 : ((FieldCoords.Edge)to).Item1;
                int fn = to.IsCenter ? -1 : ((FieldCoords.Edge)to).Item2;
                pTo = GetFieldCoords(en, fn);
            }
            if (over != null)
            {
                int en = over.IsCenter ? -1 : ((FieldCoords.Edge)over).Item1;
                int fn = over.IsCenter ? -1 : ((FieldCoords.Edge)over).Item2;
                pOver = GetFieldCoords(en, fn);
            }

            Pen pen = over != null
            ? new Pen(Color.DarkOrange, 3)
            : new Pen(Color.LimeGreen, 6);

            if (over != null)
            {
                canvas.DrawLine(pen, pFrom, pOver);
                canvas.DrawLine(pen, pOver, pTo);
            }
            else
            {
                canvas.DrawLine(pen, pFrom, pTo);
            }
        }
예제 #21
0
 private void DrawField(Graphics canvas, FieldCoords coords, FieldState state, FieldDrawType drawType)
 {
     int en = coords.IsCenter ? -1 : ((FieldCoords.Edge)coords).Item1;
     int fn = coords.IsCenter ? -1 : ((FieldCoords.Edge)coords).Item2;
     DrawField(canvas, en, fn, state, drawType);
 }
예제 #22
0
 private Point GetFieldCoords(FieldCoords coords)
 {
     if (coords.IsCenter) return GetFieldCoords(-1, -1);
     var edge = (FieldCoords.Edge)coords;
     return GetFieldCoords(edge.Item1, edge.Item2);
 }
예제 #23
0
 private void OnMouseMove(FieldCoords coords)
 {
     MouseMove?.Invoke(this, coords);
 }
예제 #24
0
 private void HandleInputControllerMouseUp(object sender, FieldCoords coords)
 {
     EngineRequest(EventTypeEnum.EventMouseUp);
 }
예제 #25
0
 private bool CheckValidMove(FieldCoords from, FieldCoords to)
 {
     return _ValidMoves.Any(m => m.Item1.Equals(from) && m.Item3.Equals(to));
 }
예제 #26
0
 private bool CheckValidMove(FieldCoords from, FieldCoords to)
 {
     return(_ValidMoves.Any(m => m.Item1.Equals(from) && m.Item3.Equals(to)));
 }
예제 #27
0
 public CreateVisualElementModel(FieldCoords cellCoords, GameElementType name)
 {
     CellCoords = cellCoords;
     Name       = name;
 }
예제 #28
0
 private void OnMouseUp(FieldCoords coords)
 {
     MouseUp?.Invoke(this, coords);
 }
예제 #29
0
 private void HandleInputControllerMouseDown(object sender, FieldCoords coords)
 {
     MouseDown = coords;
     MouseMove = coords;
     MouseUp   = coords;
 }
예제 #30
0
 private void HandleInputControllerMouseMove(object sender, FieldCoords coords)
 {
     //MouseMove = coords;
     //MouseUp = coords;
 }
예제 #31
0
 public MoveElementCoordsModel(FieldCoords startCoords, FieldCoords endCoords)
 {
     StartCoords = startCoords;
     EndCoords   = endCoords;
 }
예제 #32
0
        private bool CanBeHighlighted(FieldCoords field)
        {
            if (State[field].IsColor && ((FieldState.Color)State[field]).Item.Equals(CurrentPlayer))
                return _ValidMoves.Any(m => m.Item1.Equals(field));

            if (_SelectedField != null && State[field].IsEmpty)
                return _ValidMoves.Any(m => m.Item1.Equals(_SelectedField) && m.Item3.Equals(field));
            return false;
        }
예제 #33
0
 public bool Use(FieldCoords coords)
 {
     return(consumedBonuses.Remove(coords));
 }
예제 #34
0
 private void ClearMarks(Graphics canvas)
 {
     if (_HighlightedField != null)
     {
         DrawField(canvas, _HighlightedField, State[_HighlightedField], FieldDrawType.Default);
     }
     if (_SelectedField != null)
     {
         DrawField(canvas, _SelectedField, State[_SelectedField], FieldDrawType.Default);
     }
     _SelectedField = null;
     _HighlightedField = null;
 }
예제 #35
0
 private void OnMouseDown(FieldCoords coords)
 {
     MouseDown?.Invoke(this, coords);
 }
예제 #36
0
        public bool  TryFillIslandsMatch(VisualElementModel[,] grid, out bool[,] match)
        {
            int colsCount = grid.GetLength(0);
            int rowsCount = grid.GetLength(1);

            var matchList = new List <FieldCoords>();
            var result    = false;

            match = new bool[colsCount, rowsCount];

            for (var row = 0; row < rowsCount; row++)
            {
                for (var col = 0; col < colsCount - 1; col++)
                {
                    matchList.Clear();
                    var startingPoint = new FieldCoords(col, row);
                    matchList.Add(startingPoint);
                    for (col++; col < colsCount; col++)
                    {
                        if (grid[startingPoint.X, startingPoint.Y].Name == GameElementType.Empty ||
                            grid[col, row].Name == GameElementType.Empty ||
                            grid[startingPoint.X, startingPoint.Y].Name !=
                            grid[col, row].Name)
                        {
                            break;
                        }

                        matchList.Add(new FieldCoords(col, row));
                    }
                    col--;
                    if (matchList.Count < 3)
                    {
                        continue;
                    }

                    foreach (var coords in matchList)
                    {
                        match[coords.X, coords.Y] = true;
                        result = true;
                    }
                }
            }
            for (var col = 0; col < colsCount; col++)
            {
                for (var row = 0; row < rowsCount - 1; row++)
                {
                    matchList.Clear();
                    var startingPoint = new FieldCoords(col, row);
                    matchList.Add(startingPoint);
                    for (row++; row < rowsCount; row++)
                    {
                        if (grid[startingPoint.X, startingPoint.Y].Name == GameElementType.Empty ||
                            grid[col, row].Name == GameElementType.Empty ||
                            grid[startingPoint.X, startingPoint.Y].Name !=
                            grid[col, row].Name)
                        {
                            break;
                        }

                        matchList.Add(new FieldCoords(col, row));
                    }
                    row--;
                    if (matchList.Count < 3)
                    {
                        continue;
                    }

                    foreach (var coords in matchList)
                    {
                        match[coords.X, coords.Y] = true;
                        result = true;
                    }
                }
            }
            return(result);
        }
예제 #37
0
 private void SetMarks(Graphics canvas, FieldCoords highlighted, FieldCoords selected)
 {
     _HighlightedField = highlighted;
     _SelectedField = selected;
     if (highlighted == null && selected == null) return;
     if (highlighted?.Equals(selected) == true)
     {
         DrawField(canvas, highlighted, State[highlighted], FieldDrawType.Highlighted | FieldDrawType.Selected);
         return;
     }
     if (highlighted != null)
     {
         DrawField(canvas, highlighted, State[highlighted], FieldDrawType.Highlighted);
     }
     if (selected != null)
     {
         DrawField(canvas, selected, State[selected], FieldDrawType.Selected);
     }
 }