コード例 #1
0
ファイル: Battlefield.cs プロジェクト: Doggeti/KartonKrieger
        public void InitCells(int lengthInCells, int widthInCells)
        {
            Random rnd = new Random();

            Cells = new BattlefieldCell[lengthInCells, widthInCells];

            for (int l = 0; l < Cells.GetLength(0); l++)
            {
                for (int w = 0; w < Cells.GetLength(1); w++)
                {
                    BattlefieldCell cell = new BattlefieldCell();

                    if (rnd.Next(10) < 1)
                    {
                        cell.Ground = new CellGround {
                            AggregateState = AggregateState.Liquid
                        };
                    }
                    else
                    {
                        cell.Ground = new CellGround {
                            AggregateState = AggregateState.Solid
                        };
                    }

                    Cells[l, w] = cell;
                }
            }
        }
コード例 #2
0
 public void LinkAdjacentCell(BattlefieldCell cell, CardinalDirection direction)
 {
     if (cell == null)
     {
         return;
     }
     AdjacentCells[direction] = cell;
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: Doggeti/KartonKrieger
 private bool CanEnterCell(Character character, BattlefieldCell cell)
 {
     if (cell.Ground.AggregateState == AggregateState.Solid)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #4
0
ファイル: Game.cs プロジェクト: Doggeti/KartonKrieger
        public void TryMoveNorth()
        {
            ActiveCharacter.Facing = CardinalDirection.North;

            var coordinates = Field.FindCharacter(ActiveCharacter);

            int x = coordinates.Item1;
            int y = coordinates.Item2;

            if (y == 0)
            {
                return;
            }

            int targetX = x;
            int targetY = y - 1;

            BattlefieldCell targetCell = Field.Cells[targetX, targetY];

            if (targetCell.Character != null)
            {
                return;
            }

            if (!CanEnterCell(ActiveCharacter, targetCell))
            {
                return;
            }

            int moveCosts = GetMoveCosts(targetX, targetY);

            if (moveCosts > ActiveCharacter.ActionPoints)
            {
                return;
            }

            ActiveCharacter.ActionPoints -= moveCosts;

            targetCell.Character        = ActiveCharacter;
            Field.Cells[x, y].Character = null;

            ActiveCharacter.Facing = CardinalDirection.North;
        }
コード例 #5
0
ファイル: Battlefield.cs プロジェクト: Doggeti/KartonKrieger
        public void LinkCells()
        {
            for (int x = 0; x < Cells.GetLength(0); x++)
            {
                for (int y = 0; y < Cells.GetLength(1); y++)
                {
                    BattlefieldCell current = Cells[x, y];

                    if (x > 0)
                    {
                        BattlefieldCell west = Cells[x - 1, y];
                        current.LinkAdjacentCell(west, CardinalDirection.West);
                        west.LinkAdjacentCell(current, CardinalDirection.East);
                    }

                    if (x < Cells.GetLength(0) - 1)
                    {
                        BattlefieldCell east = Cells[x + 1, y];
                        current.LinkAdjacentCell(east, CardinalDirection.East);
                        east.LinkAdjacentCell(current, CardinalDirection.West);
                    }

                    if (y > 0)
                    {
                        BattlefieldCell north = Cells[x, y - 1];
                        current.LinkAdjacentCell(north, CardinalDirection.North);
                        north.LinkAdjacentCell(current, CardinalDirection.South);
                    }

                    if (y < Cells.GetLength(1) - 1)
                    {
                        BattlefieldCell south = Cells[x, y + 1];
                        current.LinkAdjacentCell(south, CardinalDirection.South);
                        south.LinkAdjacentCell(current, CardinalDirection.North);
                    }
                }
            }
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: Doggeti/KartonKrieger
        public Character FindTargetForAttack()
        {
            if (ActiveCharacter?.SelectedAttack == null)
            {
                return(null);
            }

            var             start       = Field.FindCharacter(ActiveCharacter);
            BattlefieldCell currentCell = Field.Cells[start.Item1, start.Item2];

            int minRange = ActiveCharacter.SelectedAttack.MinRange;
            int maxRange = ActiveCharacter.SelectedAttack.MaxRange;

            for (int step = 1; step <= maxRange; step++)
            {
                if (currentCell.AdjacentCells[ActiveCharacter.Facing] == null)
                {
                    return(null);
                }
                else
                {
                    currentCell = currentCell.AdjacentCells[ActiveCharacter.Facing];
                }

                if (step < minRange)
                {
                    continue;
                }

                if (currentCell.Character != null && ActiveCharacter.Faction != currentCell.Character.Faction)
                {
                    return(currentCell.Character);
                }
            }

            return(null);
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: Doggeti/KartonKrieger
        private void DrawCells()
        {
            int activeX = 0;
            int activeY = 0;

            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    RichTextBox     rtb       = Cells[x, y];
                    BattlefieldCell cell      = Game.Field.Cells[x, y];
                    Character       character = cell.Character;

                    switch (cell.Ground.AggregateState)
                    {
                    case AggregateState.Solid: rtb.BackColor = System.Drawing.Color.LightGreen; break;

                    case AggregateState.Liquid: rtb.BackColor = System.Drawing.Color.LightBlue; break;
                    }

                    if (character == null)
                    {
                        rtb.Text = string.Empty;
                        rtb.Font = new System.Drawing.Font(rtb.Font, System.Drawing.FontStyle.Regular);
                    }
                    else
                    {
                        rtb.Text = character.Name;

                        if (character.Alive)
                        {
                            rtb.Text += Environment.NewLine + $"{character.GetPropertyValue<Live>()} / {character.GetPropertyMax<Live>()}";
                            rtb.Text += Environment.NewLine + $"{character.Initiative} ({character.InitiativeGain})";

                            switch (cell.Character.Facing)
                            {
                            case CardinalDirection.North:
                                rtb.Text += Environment.NewLine + "↑";
                                break;

                            case CardinalDirection.South:
                                rtb.Text += Environment.NewLine + "↓";
                                break;

                            case CardinalDirection.East:
                                rtb.Text += Environment.NewLine + "→";
                                break;

                            case CardinalDirection.West:
                                rtb.Text += Environment.NewLine + "←";
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            rtb.Text += Environment.NewLine + "✝";
                        }

                        if (cell.Character == Game.ActiveCharacter)
                        {
                            activeX = x;
                            activeY = y;

                            rtb.Font = new System.Drawing.Font(rtb.Font, System.Drawing.FontStyle.Bold);
                        }
                        else
                        {
                            rtb.Font = new System.Drawing.Font(rtb.Font, System.Drawing.FontStyle.Regular);
                        }
                    }
                }
            }

            if (activeX > 0)
            {
                DrawMoveCosts(activeX - 1, activeY);
            }
            if (activeX < BOARD_SIZE - 1)
            {
                DrawMoveCosts(activeX + 1, activeY);
            }
            if (activeY > 0)
            {
                DrawMoveCosts(activeX, activeY - 1);
            }
            if (activeY < BOARD_SIZE - 1)
            {
                DrawMoveCosts(activeX, activeY + 1);
            }
        }