예제 #1
0
 private void OnClickPos(chess.Board board, Coord pos)
 {
     if (!searching)
     {
         if (board[pos] != null)
         {
             var piece = board[pos];
             if (board[pos].Flag != AiFlag)
             {
                 selectedPos = pos;
                 dropPoses   = GetDropPoses(board, pos);
             }
             else
             {
                 if (dropPoses != null && dropPoses.Exists(p => p.Equals(pos)))
                 {
                     MovePiece(selectedPos.Value, pos);
                 }
             }
         }
         else
         {
             if (dropPoses != null && dropPoses.Exists(p => p.Equals(pos)))
             {
                 MovePiece(selectedPos.Value, pos);
             }
         }
     }
 }
        /// <summary>
        /// Overridden from <see cref="PhaseLogic.OnMouseLeftClick(Vector3)"/>.
        /// </summary>
        protected override void OnMouseLeftClick(Vector3 position)
        {
            Coord?fetchCoord = GetSectorAtScreen(position);

            if (!fetchCoord.HasValue) // if the player clicked off-screen, clear selection
            {
                DoUnitSelection(null, s => 0);
            }
            else if (ContainsUnit(fetchCoord.Value, true)) // if player clicked on owned unit, shift selection to that one
            {
                DoUnitSelection(fetchCoord.Value, s =>
                                s.OccupyingUnit.HasAttacked || s.OccupyingUnit.ManaAttackCost > s.OccupyingUnit.Owner.Mana ?
                                0 : s.OccupyingUnit.AttackRange);
                if (SelectedUnit != null) // if the player was able to select the unit
                {                         // this should pass anyway, but it's good to double check
                  // unit just selected
                }
                else
                {
                    Debug.Log("Owned unit selection failed");
                }
            }
            else if (SelectedUnit != null) // if player has clicked a unit before, and has now clicked on a separate space, we need to prepare to move
            {
                SelectSector(fetchCoord);  // try to select the clicked sector
                // only consider an attack selection if it wasn't traversable and if an enemy was on it
                if (SelectedSector != null && SelectedSectorContainsUnit(true))
                {
                    if (SelectedRange.Contains(SelectedSector)) // only attack the unit if it was in range
                    {
                        AttackUnit();
                    }
                }
            }
        }
예제 #3
0
 private void OnClickPos(chess.Board board, Coord cd)
 {
     if (turnSelf && (!waitOk))
     {
         if (board[cd] != null)
         {
             var piece = board[cd];
             if (board[cd].Flag == selfFlag)
             {
                 selectedPos = cd;
                 dropPoses   = GetDropPoses(board, cd);
             }
             else
             {
                 if (dropPoses != null && dropPoses.Exists(p => p.Equals(cd)))
                 {
                     MovePiece(selectedPos.Value, cd);
                 }
             }
         }
         else
         {
             if (dropPoses != null && dropPoses.Exists(p => p.Equals(cd)))
             {
                 MovePiece(selectedPos.Value, cd);
             }
         }
     }
 }
예제 #4
0
 private void chkPoison_CheckedChanged(object sender, EventArgs e)
 {
     if (!chkPoison.Checked)
     {
         _poisonAreaStartingPoint = null;
     }
 }
예제 #5
0
        // move *your* peice
        private bool IsMovable(
            BPiece piece, Coord to, bool isDrop, Coord?dropTo)
        {
            if (piece == null)
            {
                return(false);
            }

            // failFlag is used for tell onFailure() is called in CheckIf funcitons
            bool failFlag = false;

            Coord from;

            if (isDrop)
            {
                if (!dropTo.HasValue)
                {
                    Trace.TraceError("dropFrom cannot be null when isDrop == true");
                    Environment.Exit(1);
                }
                from = dropTo.Value;
            }
            else
            {
                CheckIfMapContains(piece, () => failFlag = false);
                if (failFlag)
                {
                    return(false);
                }

                from = GetCoord(piece);
            }

            CheckIfCoordIsOnBoard(from, () => failFlag = true);
            CheckIfCoordIsOnBoard(to, () => failFlag   = true);
            if (failFlag)
            {
                return(false);
            }

            // cannot move to outside of the control
            if (!piece.HasControlTo(to - from))
            {
                return(false);
            }
            // cannot move onto your piece
            if (GetPiece(to) != null && GetPiece(to).White == piece.White)
            {
                return(false);
            }
            // cannot move over pieces, except for non-promoted knight
            if ((from.Row == to.Row || from.Col == to.Col) &&
                !piece.CanJump() &&
                !this.IsEmptyBetween(from, to))
            {
                return(false);
            }

            return(true);
        }
예제 #6
0
 private void RandomizeFood()
 {
     foodLocation = new Coord
     {
         X = (short)RandomNumberGenerator.GetInt32(gameSize.X),
         Y = (short)RandomNumberGenerator.GetInt32(gameSize.Y)
     };
 }
예제 #7
0
 public TextForm(string content = null, Coord?location = null)
 {
     InitializeComponent();
     if (location is Coord loc)
     {
         Location = loc;
     }
     SetContent(content);
 }
예제 #8
0
        void AttackAfterMove(ref StackUnit choosenUnit)
        {
            ConsoleKey read;
            Coord?     selectedCoord = null;

            do
            {
                read = 0;
                Console.SetCursorPosition(arrow.pos.x * 5 + 39, arrow.pos.y * 3 + 2);
                if (Console.KeyAvailable)
                {
                    read = ReadyForInput();
                }

                if (read != 0)
                {
                    if (read == ConsoleKey.Escape)
                    {
                        return;
                    }
                    selectedCoord = arrow.ControlArrows(read);
                    arrow.PrintControllArrows();
                }
                Thread.Sleep(1);
            } while (selectedCoord == null);


            StackUnit currEnemyUnit = GetEnemyPlayer().GetUnit(selectedCoord.Value);

            if (currEnemyUnit != null)
            {
                UnitAttack?dealedDmg = choosenUnit.Attack(selectedCoord.Value);
                if (dealedDmg.HasValue)
                {
                    currEnemyUnit.GetAttack(
                        new UnitAttack((short)(dealedDmg.Value.physicalDmg * choosenUnit.GetLuckBonus(currPlayer.hero)),
                                       (byte)(dealedDmg.Value.attack + currPlayer.hero.atk)),
                        GetEnemyPlayer().hero
                        );

                    if (currEnemyUnit.isAttackBack && currEnemyUnit.IsAlive())
                    {
                        dealedDmg = currEnemyUnit.Attack(choosenUnit.pos);
                        choosenUnit.GetAttack(
                            new UnitAttack((short)(dealedDmg.Value.physicalDmg * currEnemyUnit.GetLuckBonus(GetEnemyPlayer().hero)),
                                           (byte)(dealedDmg.Value.attack + GetEnemyPlayer().hero.atk)),
                            currPlayer.hero
                            );
                        SingleLogBattle.log.LogAddToLine(" (Back)");
                        currEnemyUnit.isAttackBack = false;
                    }

                    currEnemyUnit.ClearColorBeforeMove(ref map);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Determines whether the specified <see cref="object"/> is equal to
        /// the current <see cref="Coord"/>.
        /// </summary>
        /// <param name="obj">The <see cref="object"/> to compare with the current <see cref="Coord"/>.</param>
        /// <returns><c>true</c> if the specified <see cref="object"/> is equal to the current <see cref="Coord"/>;
        /// otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            Coord?b = obj as Coord?;

            if (b == null)
            {
                return(false);
            }
            return(this == b);
        }
예제 #10
0
        public ClipboardPreviewForm(Image image, string description, Coord?location = null) : this(description, location)
        {
            SetImage(image);

            Shown += (o, e) => {
                if (Image != null)
                {
                    Size = Image.Size;
                }
            };
        }
 /// <summary>
 /// Does the owned unit selection cycle.
 /// Cycle:
 ///     Clear current selection highlights,
 ///     Select sector at coord,
 ///     if selected, select the range using the range function.
 /// </summary>
 /// <param name="coord">The coordinate to centre the selection at.</param>
 /// <param name="range">The range function used to calculated the selection range from the given sector.</param>
 protected void DoUnitSelection(Coord?coord, Func <Sector, int> range)
 {
     ClearHighlights();
     SelectUnit(coord);
     if (SelectedUnit != null)
     {
         SelectedUnit.Highlight = HighlightLevel.Bright;
         SelectRangeAround(coord, range(SelectedUnit));
         SelectedRangeHighlight = HighlightLevel.Dimmed;
     }
 }
예제 #12
0
        private static Estacion MakeEstacion(Coord?coord = null)
        {
            IPostprocessComposer <Estacion> builder = fixture.Build <Estacion>();

            if (coord != null)
            {
                builder = builder.With(e => e.Coord, coord.Value);
            }

            return(builder.Create());
        }
예제 #13
0
        public VolumeForm(float level, Coord?location = null)
        {
            InitializeComponent();
            Level      = Matht.Clamp(level, 0, 1);
            Location   = location != null ? (Coord)location : new Coord(10, 10);
            ClientSize = volSize;
            BackColor  = baseColor;

            Shown += (o, e) => {
                ClientSize = volSize;
                new Window(Handle).SetOpacity(0.9).SetAlwaysOnTop(true);
            };
        }
예제 #14
0
        public IEnumerable <Coord> EnumerateCoords(DynamicValueContext context)
        {
            Coord?coord = TryGetCoord(m_refCoords, context);

            if (coord.HasValue)
            {
                Coord?coord2 = TryGetCoord(m_symmetryCenter, context);
                if (coord2.HasValue)
                {
                    Coord value  = coord.Value;
                    Coord value2 = coord2.Value;
                    yield return(new Coord(2 * value2.x - value.x, 2 * value2.y - value.y));
                }
            }
        }
예제 #15
0
    /// <summary>
    /// Set ExitSide qui doit être différent de StartSide
    /// </summary>
    public Side SetExitSide()
    {
        Side exitSide = GetRandomSide();

        //Side end doit être différent de la Side start
        if (startSide != exitSide)
        {
            this.exitSide = exitSide;
            exitPoint     = GetRandomCoord(exitSide);
            return(exitSide);
        }
        else
        {
            return(SetExitSide());
        }
    }
 /// <summary>
 /// Selects the range around the given coordinate, exlcuding the given one.
 /// </summary>
 /// <param name="coord">The starting coordinate. If null, will deselect.</param>
 /// <param name="range">The size of the range.</param>
 protected void SelectRangeAround(Coord?coord, int range)
 {
     SelectedRange.Clear();
     if (coord.HasValue)
     {
         HashSet <Coord> coordRange = Gc.Map.Grid.GetRange(coord.Value, range);
         coordRange.Remove(coord.Value);
         foreach (Coord c in coordRange)
         {
             if (Gc.Map.Grid.IsTraversable(c))
             {
                 SelectedRange.Add(Gc.Map.Grid[c]);
             }
         }
     }
 }
예제 #17
0
        protected override void Update()
        {
            base.Update();

            Coord?fetchCoord = GetSectorAtScreen(Input.mousePosition);

            // build unit highlighting
            if (_currentSecondaryHighlightedSectors.Count > 0)
            {
                foreach (Sector sector in _currentSecondaryHighlightedSectors)
                {
                    if (sector.Highlight == HighlightLevel.Bright)
                    {
                        sector.Highlight = HighlightLevel.Dimmed;
                    }
                }
                _currentSecondaryHighlightedSectors.Clear();
            }
            if (_isBuildingUnit)
            {
                if (fetchCoord.HasValue && Gc.Map.Grid.IsTraversable(fetchCoord.Value) && SelectedRange.Contains(Gc.Map.Grid[fetchCoord.Value]))
                {
                    _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[fetchCoord.Value]);
                    Gc.Map.Grid[fetchCoord.Value].Highlight = HighlightLevel.Bright;
                }
            }
            else if (SelectedUnit != null)
            {
                if (fetchCoord.HasValue && _selectedUnitLocation.DistanceTo(fetchCoord.Value) <= SelectedUnit.OccupyingUnit.AvailableMove &&
                    Gc.Map.Grid.IsTraversable(fetchCoord.Value))
                {
                    Stack <Coord> path = Gc.Map.Grid.PathFind(_selectedUnitLocation, fetchCoord.Value);
                    Coord         item;
                    int           count = 0;
                    while (count < SelectedUnit.OccupyingUnit.AvailableMove && path.Count > 0)
                    {
                        item = path.Pop();
                        Gc.Map.Grid[item].Highlight = HighlightLevel.Bright;
                        _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[item]);
                        count++;
                    }
                }
            }
        }
예제 #18
0
        void GetPlayerInput()
        {
            Console.SetCursorPosition(arrow.pos.x * 5 + 39, arrow.pos.y * 3 + 2);

            ConsoleKey read = 0;

            while (read == 0)
            {
                if (Console.KeyAvailable)
                {
                    read = ReadyForInput();
                }
                Thread.Sleep(1);
            }

            if (read == ConsoleKey.Enter || read == ConsoleKey.RightArrow || read == ConsoleKey.UpArrow || read == ConsoleKey.DownArrow || read == ConsoleKey.LeftArrow)
            {
                if (read != ConsoleKey.Enter)
                {
                    arrow.ControlArrows(read);
                    arrow.PrintControllArrows();
                    return;
                }

                Coord?selectedCoord = arrow.ControlArrows(read);
                arrow.PrintControllArrows();

                if (selectedCoord.HasValue)
                {
                    StackUnit choosenUnit = currPlayer.GetUnit(selectedCoord.Value);
                    if (choosenUnit != null)
                    {
                        PeekUnitGetInput(ref choosenUnit);
                    }
                }
            }

            else if (read == ConsoleKey.Escape)
            {
                isRunning = false;
            }
        }
예제 #19
0
        public double Evaluate(IEnumerable <int> solution)
        {
            var problem     = _problemGenerator.GetProblem().ToDictionary(k => k.OrderId);
            var totalLength = 0.0;

            Coord?lastLocation = null;

            foreach (var stepOrderId in solution)
            {
                var step = problem[stepOrderId];

                if (lastLocation.HasValue)
                {
                    totalLength += _distanceCalculator.GetDistanceInKm(lastLocation.Value, step.RestaurantLocation);
                }

                totalLength += _distanceCalculator.GetDistanceInKm(step.CustomerLocation, step.RestaurantLocation);
                lastLocation = step.CustomerLocation;
            }

            return(totalLength);
        }
예제 #20
0
        public static Coord?HitTestPolyline(PointT point, Coord radius, IEnumerable <PointT> points, IList <int> divisions, out PointT projected)
        {
            var    maxQuadrance = radius * radius;
            int    i            = 0;
            Coord? bestHit      = null;
            PointT bestProj     = point;

            foreach (var line in points.AdjacentPairsCircular())
            {
                Coord  frac;
                PointT p;
                var    q = QuadranceTo(point, line, out frac, out p);
                if (q < maxQuadrance)
                {
                    maxQuadrance = q;
                    bestHit      = i + frac;
                    bestProj     = p;
                }
                i++;
            }
            projected = bestProj;
            return(bestHit);
        }
예제 #21
0
        public ClipboardPreviewForm(string description, Coord?location = null)
        {
            InitializeComponent();
            textContent.Visible   = false;
            labelContent.Location = new Point(Offset, Offset);
            if (location is Coord loc)
            {
                Location = loc;
            }
            SetDesc(description);
            CaptureClicks();

            Shown += async(o, e) => {
                this.AddShadow();
                ResetSize();
                var win = new Window(Handle);
                win.SetAlwaysOnTop(true);
                win.MoveTop();
                await Task.Delay(10);

                WinAPI.HideCaret(textContent.Handle);
            };
        }
 /// <summary>
 /// Select the sector at the given coordinate. If unit is true, t will only select the sector
 /// if it contains a unit that the current player owns.
 /// </summary>
 /// <param name="coord">The coordinate of the sector to select. If null, will deselect.</param>
 /// <param name="unit">Whether to force the selection regarless of if an owned unit is present.</param>
 protected void SelectSector(Coord?coord, bool unit = false)
 {
     if (unit)
     {
         SelectedUnit = null;
     }
     SelectedSector = null;
     if (coord.HasValue && Gc.Map.Grid.IsTraversable(coord.Value))
     {
         Sector selection = Gc.Map.Grid[coord.Value];
         if (unit)
         {
             if (ContainsUnit(selection, true))
             {
                 SelectedUnit = selection;
             }
         }
         else
         {
             SelectedSector = selection;
         }
     }
 }
        protected override void Update()
        {
            base.Update();

            Coord?fetchCoord = GetSectorAtScreen(Input.mousePosition);

            // build unit highlighting
            if (_currentSecondaryHighlightedSectors.Count > 0)
            {
                foreach (Sector sector in _currentSecondaryHighlightedSectors)
                {
                    if (sector.Highlight == HighlightLevel.Bright)
                    {
                        sector.Highlight = HighlightLevel.Dimmed;
                    }
                }
                _currentSecondaryHighlightedSectors.Clear();
            }
            if (SelectedUnit != null && fetchCoord.HasValue && Gc.Map.Grid.IsTraversable(fetchCoord.Value) && SelectedRange.Contains(Gc.Map.Grid[fetchCoord.Value]))
            {
                _currentSecondaryHighlightedSectors.Add(Gc.Map.Grid[fetchCoord.Value]);
                Gc.Map.Grid[fetchCoord.Value].Highlight = HighlightLevel.Bright;
            }
        }
예제 #24
0
 public ClipPreviewBox(Image image, string description, Coord?location = null) : this(description, location)
 {
     this.image = image;
     hasImage   = true;
 }
예제 #25
0
 /// <summary>
 /// Should be called when the current path is no longer valid for any reason.
 /// </summary>
 void InvalidatePath()
 {
     lastTargetCoords = null;
 }
예제 #26
0
 void UpdatePathTo(Coord target)
 {
     FindPath((Coord)transform.position, target, hostileRange, path);
     lastTargetCoords = target;
 }
예제 #27
0
 public PcbPrimitiveDisplayInfo(string name, Coord?sizeX, Coord?sizeY) =>
 (Name, SizeX, SizeY) = (name, sizeX, sizeY);
 /// <summary>
 /// A shorthand for <c>SelectSector(coord, true)</c>.
 /// </summary>
 /// <param name="coord"></param>
 protected void SelectUnit(Coord?coord) => SelectSector(coord, true);
예제 #29
0
        /// <summary>
        /// Overridden from <see cref="PhaseLogic.OnMouseLeftClick(Vector3)"/>.
        /// </summary>
        protected override void OnMouseLeftClick(Vector3 position)
        {
            Coord? fetchCoord     = GetSectorAtScreen(position);
            Sector prevUnitSector = SelectedUnit;

            // if we are attempting to build a unit, handle either creation or cancellation
            if (_isBuildingUnit)
            {
                SelectSector(fetchCoord); // we need to know where the player clicked
                if (SelectedSector != null && SelectedRange.Contains(SelectedSector) && SelectedSector.OccupyingUnit == null)
                {                         // if the player clicked a valid build spot, then build the unit
                    IUnit newUnit = Instantiate(Gc.UnitPrefabs[_unitToBuild]).GetComponent <IUnit>();
                    newUnit.Init(Gc.Map.SectorMaterials, SelectedUnit.OccupyingUnit.Owner, SelectedUnit.OccupyingUnit.College);
                    SelectedSector.OccupyingUnit = newUnit;
                    Gc.CurrentPlayer.Mana       -= newUnit.Cost;
                    UpdateMana();
                }
                // we are no longer building
                SetUnitBuildingState(false);
            }
            else
            {
                if (!fetchCoord.HasValue) // if the player clicked off-screen, clear selection
                {
                    DoUnitSelection(null, s => 0);
                }
                else if (ContainsUnit(fetchCoord.Value, true)) // if player clicked on owned unit, shift selection to that one
                {
                    DoUnitSelection(fetchCoord.Value, s => (int)Mathf.Clamp(Mathf.Floor(s.OccupyingUnit.Owner.Mana / s.OccupyingUnit.ManaMoveRatio), 0, s.OccupyingUnit.AvailableMove));
                    if (SelectedUnit != null) // if the player was able to select the unit
                    {                         // this should pass anyway, but it's good to double check
                        _selectedUnitLocation = fetchCoord.Value;
                    }
                    else
                    {
                        Debug.Log("Owned unit selection failed");
                    }
                }
                else if (SelectedUnit != null) // if player has clicked a unit before, and has now clicked on a separate space, we need to prepare to move
                {
                    SelectSector(fetchCoord);  // try to select the clicked sector
                                               // if it wasn't traversable, or it contains an enemy unit, then we won't bother moving
                    if (SelectedSector != null && !SelectedSectorContainsUnit(true) && !BuildMenuState)
                    {                          // only move the unit if we are allowed, and are actually looking to move
                        if (SelectedRange.Contains(SelectedSector))
                        {
                            MoveUnit();
                        }
                    }
                }

                if (SelectedUnit != null && SelectedUnit.OccupyingUnit.BuildRange > 0) // if this is a builder unit
                {
                    // if player selected a new builder unit, make sure the build menu is close and give the option to open it
                    if (!BuildMenuState || prevUnitSector != SelectedUnit)
                    {
                        buildMenuButton.SetActive(true);
                        BuildMenuState = false;
                    }
                }
                else // if not on a builder unit, then make sure the build menu and open button are hidden
                {
                    buildMenuButton.SetActive(false);
                    BuildMenuState = false;
                }
            }
        }
예제 #30
0
        void PeekUnitGetInput(ref StackUnit choosenUnit)
        {
            ConsoleKey read;
            Coord?     selectedCoord = null;
            bool       endOfTurn     = false;

            choosenUnit.ColorBeforeMove();

            do
            {
                read = 0;
                Console.SetCursorPosition(arrow.pos.x * 5 + 39, arrow.pos.y * 3 + 2);
                if (Console.KeyAvailable)
                {
                    read = ReadyForInput();
                }

                if (read != 0)
                {
                    if (read == ConsoleKey.Escape)
                    {
                        goto EXIT_WITHOUT_MOVE;
                    }
                    selectedCoord = arrow.ControlArrows(read);
                    arrow.PrintControllArrows();
                }
                Thread.Sleep(1);
            } while (selectedCoord == null);

            if (currPlayer.GetUnit(arrow.pos) != null)
            {
                goto EXIT_WITHOUT_MOVE;
            }

            StackUnit currEnemyUnit = GetEnemyPlayer().GetUnit(selectedCoord.Value);

            choosenUnit.isAttackBack = true;
            if (currEnemyUnit == null)
            {
                endOfTurn = choosenUnit.Move(selectedCoord.Value, ref map);
                if (endOfTurn && IsEnemyAround(ref choosenUnit))
                {
                    PrintCurrState();
                    choosenUnit.ColorBeforeMove();
                    AttackAfterMove(ref choosenUnit);
                }
            }
            else
            {
                UnitAttack?dealedDmg = choosenUnit.Attack(selectedCoord.Value);
                if (dealedDmg.HasValue)
                {
                    endOfTurn = true;
                    currEnemyUnit.GetAttack(
                        new UnitAttack((short)(dealedDmg.Value.physicalDmg * choosenUnit.GetLuckBonus(currPlayer.hero)),
                                       (byte)(dealedDmg.Value.attack + currPlayer.hero.atk)),
                        GetEnemyPlayer().hero
                        );
                    if (currEnemyUnit.isAttackBack && currEnemyUnit.IsAlive())
                    {
                        dealedDmg = currEnemyUnit.Attack(choosenUnit.pos);
                        choosenUnit.GetAttack(
                            new UnitAttack((short)(dealedDmg.Value.physicalDmg * currEnemyUnit.GetLuckBonus(GetEnemyPlayer().hero)),
                                           (byte)(dealedDmg.Value.attack + GetEnemyPlayer().hero.atk)),
                            currPlayer.hero
                            );
                        SingleLogBattle.log.LogAddToLine(" (Back)");
                        currEnemyUnit.isAttackBack = false;
                    }
                    currEnemyUnit.ClearColorBeforeMove(ref map);
                }
            }

            if (endOfTurn)
            {
                ChangePlayer();
            }

EXIT_WITHOUT_MOVE:
            choosenUnit.ClearColorBeforeMove(ref map);
        }