示例#1
0
    public Belonging GetBelongingFromObject(Object searchedObject)
    {
        Belonging potentialBelonging = null;

        for (int i = 0; i < belongings.Count; i++)
        {
            if (belongings[i].ownedObject == searchedObject)
            {
                potentialBelonging = belongings[i];
            }
        }
        return(potentialBelonging);
    }
示例#2
0
 public Blast(Vector2 newPositiion, Belonging newBelonging)
 {
     Belonging    = newBelonging;
     GameObject   = GameObject.Blast;
     position     = newPositiion;
     State        = 0;
     frameToStage = 3;
     Counter      = 0;
     IsComplete   = false;
     if (Belonging == Belonging.None)
     {
         IsComplete = true;
     }
 }
示例#3
0
        /// <summary>
        /// Assessment of the overall ability to move checkers
        /// </summary>
        /// <param name="from">Checker position</param>
        /// <param name="max_distance">Move distance of checker</param>
        /// <param name="enemy">Enemy side</param>
        /// <returns>Can checker move</returns>
        public bool CanMove(Point from, int max_distance, Belonging enemy)
        {
            // Beating a checker is required - move available
            if (NeedCheckerBeating(from, max_distance, enemy).Count > 0)
            {
                return(true);
            }

            // Evaluation in all directions
            for (int kx = -1; kx <= 1; kx += 2)
            {
                for (int ky = -1; ky <= 1; ky += 2)
                {
                    // Limiting directions for simple checkers
                    if (!_state.checkers[from.X, from.Y].king)
                    {
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.WhiteRose && ky == 1)
                        {
                            continue;
                        }
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.RedRose && ky == -1)
                        {
                            continue;
                        }
                    }

                    // Assessment of the possibility of a diagonal move
                    for (int y = from.Y + ky, x = from.X + kx;
                         Math.Abs(y - from.Y) < max_distance + 1;
                         y += ky, x += kx)
                    {
                        // The end of the board, the inability to move in a given direction
                        if (!CheckBounds(x, y))
                        {
                            break;
                        }

                        // Free field, move is possible
                        if (_state.checkers[x, y] == null)
                        {
                            return(true);
                        }
                    }
                }
            }

            // Move is impossible
            return(false);
        }
示例#4
0
 private void OnAddThing()
 {
     if (SelectedPerson == null)
     {
         MessageBox.Show("Select  a person first!", "Select person", MessageBoxButton.OK, MessageBoxImage.Asterisk);
         return;
     }
     else
     {
         Belonging newItem = new Belonging()
         {
             Name = "NewItem", Quantity = "1"
         };
         SelectedPerson.ThingsOwned.Add(newItem);
         PersonThingsOwnedDataGrid.Add(newItem);
     }
 }
示例#5
0
        /// <summary>
        /// Building the list of available moves for computer
        /// Move can rely to one of following categories:
        /// 1 - one or more enemy checker was beaten
        /// 2 - safe move (checker is not on the dangerous position)
        /// 3 - unsafe move (checker is on dangerous position)
        /// </summary>
        /// <param name="from">Moving checker position</param>
        /// <param name="max_distance">Move distance of checker</param>
        /// <param name="enemy">Enemy side</param>
        /// <returns>List of all available moves</returns>
        public List <Point>[] GetComputerMoves(Point from, int max_distance, Belonging enemy)
        {
            // Categories init
            List <Point>[] moves = new List <Point> [3];
            for (int i = 0; i < 3; i++)
            {
                moves[i] = new List <Point>();
            }

            // Try finding the moves of 1st category
            var beat_dir = NeedCheckerBeating(from, max_distance, enemy);

            if (beat_dir.Count > 0)
            {
                foreach (var item in beat_dir)
                {
                    Point to = new Point(from.X + item.direction.X * item.minimum_distance, from.Y + item.direction.Y * item.minimum_distance);
                    moves[0].Add(to);
                }
                return(moves);
            }

            // Try finding the moves of 2nd and 3rd categories
            for (int kx = -1; kx <= 1; kx += 2)
            {
                for (int ky = -1; ky <= 1; ky += 2)
                {
                    // Determining the permissible sides of a move without beating a checker
                    if (!_state.checkers[from.X, from.Y].king)
                    {
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.WhiteRose && ky == 1)
                        {
                            continue;
                        }
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.RedRose && ky == -1)
                        {
                            continue;
                        }
                    }

                    // Assessment of the possibility of a move to different positions in the diagonal
                    for (int y = from.Y + ky, x = from.X + kx;
                         Math.Abs(y - from.Y) < max_distance + 1;
                         y += ky, x += kx)
                    {
                        // End of the board, termination of directional assessment
                        if (!CheckBounds(x, y))
                        {
                            break;
                        }

                        // Free cell, move is possible
                        if (_state.checkers[x, y] == null)
                        {
                            // Definition of a category of a move, fitting of a checker on an estimated position
                            bool prioritized = true;
                            for (int predict_kx = -1; predict_kx <= 1; predict_kx += 2)
                            {
                                for (int predict_ky = -1; predict_ky <= 1; predict_ky += 2)
                                {
                                    // Restriction of permissible take sides to comply with the rules of English checkers
                                    if (!Properties.Settings.Default.rules_russian)
                                    {
                                        if (enemy == Belonging.WhiteRose && ky == 1)
                                        {
                                            continue;
                                        }
                                        if (enemy == Belonging.RedRose && ky == -1)
                                        {
                                            continue;
                                        }
                                    }

                                    // Finding the enemy's checkers located nearby and threatening to walk
                                    if (CheckBounds(x + predict_kx, y + predict_ky) && _state.checkers[x + predict_kx, y + predict_ky] != null &&
                                        _state.checkers[x + predict_kx, y + predict_ky].belong_to == enemy)
                                    {
                                        // Check for the presence of a free cell, allowing the enemy to beat the moving checker
                                        if (CheckBounds(x - predict_kx, y - predict_ky) && (_state.checkers[x - predict_kx, y - predict_ky] == null || from == new Point(x - predict_kx, y - predict_ky)))
                                        {
                                            prioritized = false;
                                        }
                                    }
                                }
                            }

                            // The final determination of the move to 2 or 3 categories
                            if (prioritized)
                            {
                                moves[1].Add(new Point(x, y));
                            }
                            else
                            {
                                moves[2].Add(new Point(x, y));
                            }
                        }
                        // The cell is occupied by an ally - the move is impossible
                        else if (_state.checkers[x, y].belong_to != enemy)
                        {
                            break;
                        }
                    }
                }
            }
            return(moves);
        }
示例#6
0
        /// <summary>
        /// Assessing the need to beat a checker and build a list of possible directions for beating
        /// </summary>
        /// <param name="from">Position of moving checker</param>
        /// <param name="max_distance">Distance of moving checkers</param>
        /// <param name="enemy">Enemy side</param>
        /// <returns>The list of possible directions for beating a checker</returns>
        public LinkedList <BeatDirection> NeedCheckerBeating(Point from, int max_distance, Belonging enemy)
        {
            // Initial values
            LinkedList <BeatDirection> beating_directions_list = new LinkedList <BeatDirection>();
            bool single_enemy             = false;
            bool fail                     = false;
            int  minimum_beating_distance = 0;

            // Diagonal test in all directions
            for (int kx = -1; kx <= 1; kx += 2)
            {
                for (int ky = -1; ky <= 1; ky += 2)
                {
                    // Restriction of permissible take sides to comply with the rules of English drafts
                    if (!Properties.Settings.Default.rules_russian && !_state.checkers[from.X, from.Y].king)
                    {
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.WhiteRose && ky == 1)
                        {
                            continue;
                        }
                        if (_state.checkers[from.X, from.Y].belong_to == Belonging.RedRose && ky == -1)
                        {
                            continue;
                        }
                    }

                    // Checking the diagonal for the presence of single opponent checkers
                    for (int y = from.Y + ky, x = from.X + kx;
                         Math.Abs(y - from.Y) < max_distance + 1;
                         y += ky, x += kx)
                    {
                        // If going beyond the board stop the diagonal test
                        if (!CheckBounds(x, y))
                        {
                            if (single_enemy)
                            {
                                fail = true;
                            }
                            break;
                        }

                        // Checker found on the diagonal
                        if (_state.checkers[x, y] != null)
                        {
                            // If the found checker belongs to the enemy
                            if (_state.checkers[x, y].belong_to == enemy)
                            {
                                // Checking the position following the checker
                                Point next = new Point(x + kx, y + ky);

                                // End of the board, termination of the diagonal test
                                if (!CheckBounds(next.X, next.Y))
                                {
                                    fail = true;
                                    break;
                                }

                                // Free field, can beat
                                if (_state.checkers[next.X, next.Y] == null)
                                {
                                    fail                     = false;
                                    single_enemy             = true;
                                    minimum_beating_distance = Math.Abs(next.Y - from.Y);
                                    break;
                                }
                                else
                                {
                                    // The field is occupied by another checker, the termination of the diagonal test
                                    fail = true;
                                    break;
                                }
                            }
                            else
                            {
                                // Found allied checker, stopping diagonal test
                                fail = true;
                                break;
                            }
                        }
                    }

                    // If the search for checkers that can be beat was successful
                    if (single_enemy && !fail)
                    {
                        beating_directions_list.AddLast(new BeatDirection(new Point(kx, ky), minimum_beating_distance));
                    }

                    // Clearing all flags to test the next diagonal
                    fail         = false;
                    single_enemy = false;
                }
            }
            return(beating_directions_list);
        }
示例#7
0
        public static void Render(Vector2 position, int state, Belonging belonging, GameObject gameObject)
        {
            GL.Color4(Color4.White);
            GL.Translate(position.X * WindowProperty.ObjectSize / WindowProperty.WindowSize.X, position.Y * WindowProperty.ObjectSize / WindowProperty.WindowSize.Y, 0);
            switch (gameObject)
            {
            case GameObject.Player:
            {
                _player.Bind();
                break;
            }

            case GameObject.Blast:
            {
                if (belonging == Belonging.Enemy)
                {
                    _enemyBlast[state].Bind();
                }
                else if (belonging == Belonging.Player)
                {
                    _enemyBlast[state].Bind();
                }
                break;
            }

            case GameObject.Boss:
            {
                _boss[state].Bind();
                break;
            }

            case GameObject.Bullet:
            {
                _bullet.Bind();
                break;
            }

            case GameObject.Enemy:
            {
                _enemies[state].Bind();
                break;
            }

            case GameObject.Star:
            {
                _star[state].Bind();
                break;
            }
            }
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(1, 1);
            GL.Vertex2(-WindowProperty.GlObjectSize.X / 2, -WindowProperty.GlObjectSize.Y / 2);
            GL.TexCoord2(0, 1);
            GL.Vertex2(WindowProperty.GlObjectSize.X / 2, -WindowProperty.GlObjectSize.Y / 2);
            GL.TexCoord2(0, 0);
            GL.Vertex2(WindowProperty.GlObjectSize.X / 2, WindowProperty.GlObjectSize.Y / 2);
            GL.TexCoord2(1, 0);
            GL.Vertex2(-WindowProperty.GlObjectSize.X / 2, WindowProperty.GlObjectSize.Y / 2);
            GL.End();

            GL.Translate(-position.X * WindowProperty.ObjectSize / WindowProperty.WindowSize.X, -position.Y * WindowProperty.ObjectSize / WindowProperty.WindowSize.Y, 0);
        }
示例#8
0
 public void GetBelonging(Belonging bel)
 {
     belonging = bel;
 }
示例#9
0
 void FillBox(Belonging belonging)
 {
     belonging.isStored           = true;
     belonging.transform.position = new Vector3(transform.position.x, transform.position.y, belonging.transform.position.z);
     belonging.transform.SetParent(transform);
 }