public void Build() { builder.Build(info); var firstBonusLocation = new FieldCoords(info.Width / 2, info.Length / 2); SpawnBonus(Bonus.Growth, firstBonusLocation); }
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; }
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; }
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); }
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; } } } } } }
public void SpawnBonus(Bonus bonus) { var where = new FieldCoords() { X = random.Next(info.Width), Y = random.Next(info.Length), }; SpawnBonus(bonus, where); }
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); }
private Point GetFieldCoords(FieldCoords coords) { if (coords.IsCenter) { return(GetFieldCoords(-1, -1)); } var edge = (FieldCoords.Edge)coords; return(GetFieldCoords(edge.Item1, edge.Item2)); }
public void DestroyBonus(FieldCoords where) { Transform bonusView; if (spawnedBonuses.TryGetValue(where, out bonusView)) { spawnedBonuses.Remove(where); GameObject.Destroy(bonusView.gameObject); } }
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); }
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); } }
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); } }
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; }
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); }
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))); }
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(); }
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); }
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); } }
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); } }
private Point GetFieldCoords(FieldCoords coords) { if (coords.IsCenter) return GetFieldCoords(-1, -1); var edge = (FieldCoords.Edge)coords; return GetFieldCoords(edge.Item1, edge.Item2); }
private void OnMouseMove(FieldCoords coords) { MouseMove?.Invoke(this, coords); }
private void HandleInputControllerMouseUp(object sender, FieldCoords coords) { EngineRequest(EventTypeEnum.EventMouseUp); }
private bool CheckValidMove(FieldCoords from, FieldCoords to) { return _ValidMoves.Any(m => m.Item1.Equals(from) && m.Item3.Equals(to)); }
private bool CheckValidMove(FieldCoords from, FieldCoords to) { return(_ValidMoves.Any(m => m.Item1.Equals(from) && m.Item3.Equals(to))); }
public CreateVisualElementModel(FieldCoords cellCoords, GameElementType name) { CellCoords = cellCoords; Name = name; }
private void OnMouseUp(FieldCoords coords) { MouseUp?.Invoke(this, coords); }
private void HandleInputControllerMouseDown(object sender, FieldCoords coords) { MouseDown = coords; MouseMove = coords; MouseUp = coords; }
private void HandleInputControllerMouseMove(object sender, FieldCoords coords) { //MouseMove = coords; //MouseUp = coords; }
public MoveElementCoordsModel(FieldCoords startCoords, FieldCoords endCoords) { StartCoords = startCoords; EndCoords = endCoords; }
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; }
public bool Use(FieldCoords coords) { return(consumedBonuses.Remove(coords)); }
private void OnMouseDown(FieldCoords coords) { MouseDown?.Invoke(this, coords); }
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); }
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); } }