Esempio n. 1
0
        /// <summary>
        /// Function to save the game.
        /// </summary>
        /// <param name="sfd">Object class SaveFileDialog.</param>
        /// <param name="d">Object class Debra.</param>
        /// <param name="g">Object of the Game class.</param>
        /// <param name="ai">Object class Squad (detachment of the computer).</param>
        /// <param name="pl">Object class Squad (squad players).</param>
        public void SaveGame(System.Windows.Forms.SaveFileDialog sfd, Debra d, Game g, Squad ai, Squad pl)
        {
            if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            using (Stream save = File.Open(sfd.FileName, FileMode.Create))
            using (var sw = new StreamWriter(save))
            {
                // TODO: Нормально реализовать данный функционал, а не как было.
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Function to loading games.
        /// </summary>
        /// <param name="ofd">Object class OpenFileDialog.</param>
        /// <param name="d">Object class Debra.</param>
        /// <param name="g">Object of the Game class.</param>
        /// <param name="ai">Object class Squad (detachment of the computer).</param>
        /// <param name="pl">Object class Squad (squad players).</param>
        public void LoadGame(System.Windows.Forms.OpenFileDialog ofd, Debra d, Game g, Squad ai, Squad pl)
        {
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            using (Stream save = File.Open(ofd.FileName, FileMode.Open))
            using (var sr = new StreamReader(save))
            {
                // TODO: Нормально реализовать данный функционал, а не как было.
            }
        }
Esempio n. 3
0
        /// <summary>
        /// To make progress.
        /// </summary>
        /// <param name="sqPl">An object class represents Squad Player.</param>
        /// <param name="sqAi">An object class represents Squad Computer.</param>
        /// <param name="monsters">Array monsters in the game.</param>
        /// <returns>Index "attraction factor" in the array.</returns>
        public int Make(Squad sqPl, Squad sqAi, Unit[] monsters)
        {
            // Remember the position of the previous turn.
            _previousX = PointX;
            _previousY = PointY;

            // Find the position of squad on the map.
            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 20; j++)
                {
                    if (_arrayLogic[i, j] != 28) continue;

                    PointX = i;
                    PointY = j;
                    break;
                }
            }

            // An array of factors attraction.
            int[] coefficients =
            {
                // To the left.
                AnalysisOfTheNeighboringCells(PointX, PointY - 1, sqPl, sqAi, monsters),
                // To the up.
                AnalysisOfTheNeighboringCells(PointX - 1, PointY, sqPl, sqAi, monsters),
                // To the right.
                AnalysisOfTheNeighboringCells(PointX, PointY + 1, sqPl, sqAi, monsters),
                // To the down.
                AnalysisOfTheNeighboringCells(PointX + 1, PointY, sqPl, sqAi, monsters)
            };

            // If we were at an impasse.
            if (coefficients[0] < 0 && coefficients[1] < 0 && coefficients[2] < 0 && coefficients[3] < 0)
                // Calculate the position of the minimum element in the array, the side where we were on the last course.
                return Array.IndexOf(coefficients, coefficients.Min());

            // If the detachment is not something important, you can try to make a random move.
            if (coefficients.Max() < 19)
            {
                var rnd = new Random();
                // With a 5% chance to make a random move.
                if (rnd.Next(0, 100) < 5)
                {
                    while (true)
                    {
                        var hand = coefficients[rnd.Next(coefficients.Length)];
                        if (hand >= 0)
                            return Array.IndexOf(coefficients, hand);
                    }
                }
            }

            // If the maximum coefficient in the array is equal to 0 && (AND), their number is greater than 1
            // This situation means that we have two or more empty spaces where you can walk
            // Between them it is necessary to select a random.
            if (coefficients.Max() == 0 && coefficients.Count(i => i == 0) > 1)
                return RandomBetween2EmptyCells(coefficients);

            // Calculate the position of the maximum element in the array, the side where it is necessary to be like.
            return Array.IndexOf(coefficients, coefficients.Max());
        }
Esempio n. 4
0
        /// <summary>
        /// Analysis of neighboring cell.
        /// </summary>
        /// <param name="x">Coordinate along the X axis.</param>
        /// <param name="y">Coordinate along the Y axis.</param>
        /// <param name="sqPl">Object of class represents Squad Player.</param>
        /// <param name="sqAi">Object of class represents Squad Computer.</param>
        /// <param name="monsters">Array monsters in the game.</param>
        /// <returns>"Coefficient of appeal" - shows how the important objects in neighboring cells.</returns>
        private int AnalysisOfTheNeighboringCells(int x, int y, Squad sqPl, Squad sqAi, IReadOnlyList<Unit> monsters)
        {
            // MAGIC IS GOING ON HERE.
            try
            {
                // If we came across an obstacle.
                if (_arrayLogic[x, y] > 0 && _arrayLogic[x, y] < 19)
                    return -1;

                // If those coordinates that we check are three coordinates,
                // Where we were on the last turn, it is necessary to return -2, which is constantly
                // Do not rush between the two neighboring empty cells.
                if (_previousX == x && _previousY == y)
                    return -2;

                // If you come across a monster.
                if (_arrayLogic[x, y] > 28 && _arrayLogic[x, y] < 43)
                {
                    if (SquadCanWin(monsters[42 - _arrayLogic[x, y]], sqAi))
                        return _arrayLogic[x, y];

                    return -1;
                }

                // If you stumbled upon an enemy unit.
                if (_arrayLogic[x, y] == 27)
                {
                    if (SquadCanWin(sqPl, sqAi))
                        return _arrayLogic[x, y];

                    return -1;
                }
            }
            catch(IndexOutOfRangeException)
            {
                // Since then an exhaustive search, it may be a situation where we were
                // At the edge of the map, in which case we Word Exception departure beyond the array
                // Make that the coefficient of attraction for such a cell is -1.
                return -1;
            }

            // In other cases.
            return _arrayLogic[x, y];
        }
Esempio n. 5
0
 /// <summary>
 /// Check whether the squad to win?
 /// </summary>
 /// <param name="sqPl">Player squad.</param>
 /// <param name="sqAi">Computer squad.</param>
 /// <returns>True - If the squad was able to win.</returns>
 private static bool SquadCanWin(Squad sqPl, Squad sqAi)
 {
     return sqAi.Damage >= sqPl.Hp;
 }
Esempio n. 6
0
 /// <summary>
 /// Check whether the squad to win?
 /// </summary>
 /// <param name="monster">Monster, who is being attacked.</param>
 /// <param name="sqAi">Squad of the computer that attacked.</param>
 /// <returns>True - If the squad was able to win.</returns>
 private static bool SquadCanWin(Unit monster, Squad sqAi)
 {
     return sqAi.Damage >= monster.Hp;
 }