Exemple #1
0
 /// <summary>
 /// Constructor for rod action to be performed
 /// </summary>
 /// <param name="type">Current Rod Type</param>
 /// <param name="rotation">Rotational move to be performed (default is undefined)</param>
 /// <param name="linear">Linear move to be performed (default is undefined)</param>
 public RodAction(eRod type, eRotationalMove rotation = eRotationalMove.NA, eLinearMove linear = eLinearMove.NA)
 {
     _dcPosition = 0;
     RodType     = type;
     Rotation    = rotation;
     Linear      = linear;
 }
Exemple #2
0
 /// <summary>
 /// Constructor for rod action to be performed
 /// </summary>
 /// <param name="type">Current Rod Type</param>
 /// <param name="rotation">Rotational move to be performed (default is undefined)</param>
 /// <param name="linear">Linear move to be performed (default is undefined)</param>
 public RodAction(eRod type, eRotationalMove rotation = eRotationalMove.NA, eLinearMove linear = eLinearMove.NA)
 {
     _dcPosition = 0;
     RodType = type;
     Rotation = rotation;
     Linear = linear;
 }
 public static void ControlRod_ClassInitialize(TestContext context)
 {
     _surveyorMock = Substitute.For <ISurveyor>();
     _ricochetMock = Substitute.For <IInitializableRicochet>();
     _stateMock    = Substitute.For <IRodState>();
     _rodType      = eRod.Defence;
 }
Exemple #4
0
 public static void ControlRod_ClassInitialize(TestContext context)
 {
     _surveyorMock = Substitute.For<ISurveyor>();
     _ricochetMock = Substitute.For<IInitializableRicochet>();
     _stateMock = Substitute.For<IRodState>();
     _rodType = eRod.Defence;
 }
Exemple #5
0
        /// <summary>
        /// Control Rod Constructor
        /// </summary>
        /// <param name="rodType">Rod Type to construct</param>
        /// <param name="surveyor">Used in for range check vector intersection calculation</param>
        /// <param name="ricochetCalc">Used for ricochet in vector intersection calculation</param>
        /// <param name="tableHeight">Foosbot table height - rod length (Y) in mm</param>
        /// <param name="rodStopperMin">Minimal point can be reached by stopper (Y) in mm</param>
        /// <param name="rodState">Rod state will be created in initialization method if passed null</param>
        public ControlRod(eRod rodType, ISurveyor surveyor, IInitializableRicochet ricochetCalc,
                          int tableHeight = -1, int rodStopperMin = -1, IRodState rodState = null)
        {
            _rodType     = rodType;
            _surveyor    = surveyor;
            _vectorUtils = ricochetCalc;
            State        = rodState;

            TABLE_HEIGHT = (tableHeight > 0) ? tableHeight
                : Configuration.Attributes.GetValue <int>(Configuration.Names.TABLE_HEIGHT);
            ROD_STOPPER_MIN = (rodStopperMin > 0) ? rodStopperMin
                : Configuration.Attributes.GetValue <int>(Configuration.Names.KEY_ROD_START_Y);
        }
        /// <summary>
        /// Communication Layer Constructor
        /// </summary>
        /// <param name="publisher">Rod Action publisher to observe</param>
        /// <param name="rodType">Current rod type</param>
        /// <param name="comPort">Com port of current arduino rod</param>
        public CommunicationUnit(Publisher <RodAction> publisher, eRod rodType, string comPort)
            : base(publisher)
        {
            //we don't wan't to receive anything before initialization finished
            _publisher.Detach(this);

            //set rod type for current rod
            _rodType = rodType;

            _converter = new ArduinoConverter(rodType);

            //Create arduino com object
            _arduino = new ArduinoCom(comPort, new ActionEncoder(_converter));
        }
Exemple #7
0
        /// <summary>
        /// Draw a rod by a given eMark sign , moving the rod on the linear and rotational axes
        /// </summary>
        /// <param name="rod">eMark of the wanted rod : GoalKeeper, Defence , Midfield, Attack</param>
        /// <param name="deltaYMovment">The change on the linear movement</param>
        /// <param name="rotationalMove">eRotationalMove of the rod : DEFENCE, RISE, ATTACK</param>
        public static void DrawRodPlayers(eRod rod, int linearMoveDestination, eRotationalMove rotationalMove, bool isLocation = true)
        {
            try
            {
                eMarks playersBase = 0;
                eMarks mark;
                Enum.TryParse <eMarks>(rod.ToString(), out mark);

                int eMarkType          = ((int)mark);
                int rodPlayersCount    = _rodPlayerCount[mark];
                int yDistance          = _rodsPlayersDistance[mark];
                int firstPlayerOffsetY = _rodsOffsetY[mark];
                int x = XTableToDeviceCoordinates(_rods[mark]);



                switch (eMarkType)
                {
                case (int)eMarks.GoalKeeper: playersBase = eMarks.GoalKeeperPlayer; break;

                case (int)eMarks.Defence: playersBase = eMarks.DefencePlayer1; break;

                case (int)eMarks.Midfield: playersBase = eMarks.MidfieldPlayer1; break;

                case (int)eMarks.Attack: playersBase = eMarks.AttackPlayer1; break;

                default: break;
                }

                for (int rodPlayer = 0; rodPlayer < rodPlayersCount; rodPlayer++)
                {
                    int y  = linearMoveDestination + firstPlayerOffsetY + yDistance * rodPlayer;
                    int y1 = y;
                    int x1 = x;
                    if (isLocation)
                    {
                        ConvertToLocation(ref x1, ref y);
                    }
                    DrawPlayer(playersBase + rodPlayer, new Point(x1 * _actualWidthRate, y1 * _actualHeightRate), 12, rotationalMove);
                }
            }
            catch (Exception e)
            {
                Log.Print(String.Format("Failed to draw rods players mark. Reason: {0}", e.Message), eCategory.Error, LogTag.COMMON);
            }
        }
Exemple #8
0
        public static Point PlayerPosition(eRod type)
        {
            eMarks mark = eMarks.NA;

            switch (type)
            {
            case eRod.GoalKeeper:
                mark = eMarks.GoalKeeper;
                break;

            case eRod.Defence:
                mark = eMarks.DefencePlayer1;
                break;

            case eRod.Midfield:
                mark = eMarks.MidfieldPlayer1;
                break;

            case eRod.Attack:
                mark = eMarks.AttackPlayer1;
                break;

            default:
                break;
            }

            if (_playerPositions.ContainsKey(mark))
            {
                object token = _positionToken[mark];
                Point? point = null;
                lock (token)
                {
                    point = new Point(_playerPositions[mark].X, _playerPositions[mark].Y);
                }

                if (point != null)
                {
                    return((Point)point);
                }
            }
            throw new NotSupportedException("Not supported player type");
        }
Exemple #9
0
        /// <summary>
        /// Constructor for Rod
        /// </summary>
        /// <param name="type">Rod type - based on this type rod location will be calculated</param>
        public Rod(eRod type)
        {
            //Set Rod Type
            _rodType = type;

            //Calculate Rod Location
            int actualRodXCoordinate = Configuration.Attributes.GetValue <int>(_rodType.ToString());
            int tableWidth           = Configuration.Attributes.GetValue <int>(Configuration.Names.TABLE_WIDTH);
            int foosbotWidth         = Configuration.Attributes.GetValue <int>(Configuration.Names.FOOSBOT_AXE_X_SIZE);

            _rodXCoordinate = actualRodXCoordinate * foosbotWidth / tableWidth;

            //Calculate Rod Minimal Sector
            int actualRodsDist = Configuration.Attributes.GetValue <int>(Configuration.Names.TABLE_RODS_DIST);

            _minSectorWidth = actualRodsDist * foosbotWidth / tableWidth;

            //Set sector factor to calculate dynamic sector based ball velocity
            _sectorFactor = Configuration.Attributes.GetValue <double>(Configuration.Names.SECTOR_FACTOR);
        }
Exemple #10
0
 /// <summary>
 /// Parsing sector line marks by selected rod type
 /// </summary>
 /// <param name="type"></param>
 /// <param name="lineA"></param>
 /// <param name="lineB"></param>
 protected void TryParseToSectorLineMarks(eRod type, out eMarks lineA, out eMarks lineB)
 {
     lineA = eMarks.NA;
     lineB = eMarks.NA;
     switch (type)
     {
         case eRod.GoalKeeper:
             lineA = eMarks.GoalKeeperSector1;
             lineB = eMarks.GoalKeeperSector2;
             break;
         case eRod.Defence:
             lineA = eMarks.DefenceSector1;
             lineB = eMarks.DefenceSector2;
             break;
         case eRod.Midfield:
             lineA = eMarks.MidfieldSector1;
             lineB = eMarks.MidfieldSector2;
             break;
         case eRod.Attack:
             lineA = eMarks.AttackSector1;
             lineB = eMarks.AttackSector2;
             break;
     }
 }
Exemple #11
0
        /// <summary>
        /// Draw a rod by a given eMark sign , moving the rod on the linear and rotational axes
        /// </summary>
        /// <param name="rod">eMark of the wanted rod : GoalKeeper, Defense , Midfield, Attack</param>
        /// <param name="linearMoveDestination">Destination of a stopper in MM (Real World)</param>
        /// <param name="rotationalMove">eRotationalMove of the rod : DEFENCE, RISE, ATTACK</param>
        public void DrawRodPlayers(eRod rod, int linearMoveDestination, eRotationalMove rotationalMove)
        {
            //Get all player centers in a real world in current rod
            int x = Data.GetRod(rod).XCoordinate;
            int playersCount = Data.GetRod(rod).PlayersCount;
            int firstPlayerOffset = Data.GetRod(rod).FirstPlayerOffsetY;
            int playersDistance = Data.GetRod(rod).PlayersYDistance;
            
            for (int i = 0; i<playersCount; i++)
            {
                eMarks playerMark = _state.RodTypeToMarkOfFirstPlayerType(rod) + i;
                int y = firstPlayerOffset + i * playersDistance + linearMoveDestination;

                Point center = new Point(x, y);
                center = Data.TableToDeviceCoordinates(center);

                DrawPlayer(playerMark, center, rotationalMove);
            }
        }
Exemple #12
0
 /// <summary>
 /// Get Player (Stopper) position of current rod
 /// </summary>
 /// <param name="type">Rod Type</param>
 /// <returns>Player (Stopper) position of current rod in Foosbot world</returns>
 public Point PlayerPosition(eRod type)
 {
     return _state.Get(type);
 }
Exemple #13
0
 /// <summary>
 /// Returns Rod Data per specified rod type
 /// </summary>
 /// <param name="type">Rod Type</param>
 /// <returns>Rod Data</returns>
 public static RodData GetRod(eRod type)
 {
     RodData rod = _rods.FirstOrDefault(x => x.RodType.Equals(type));
     if (rod == default(RodData))
     {
         rod = new RodData(type);
         _rods.Add(rod);
     }
     return rod;
 }
Exemple #14
0
 /// <summary>
 /// Updates real time servo position
 /// This method is used as delegate in Communication Layer
 /// </summary>
 /// <param name="rodType">Current Rod Type</param>
 /// <param name="servoState">Current Servo Position</param>
 public void UpdateRealTimeState(eRod rodType, eRotationalMove servoState)
 {
     IInitializableRod rod = _controlledRods.First(x => x.RodType.Equals(rodType));
     rod.State.ServoPosition = servoState;
 }
Exemple #15
0
 /// <summary>
 /// Get Distance (Y) of first player to border of a table for current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Offset in (mm)</returns>
 public static int GetPlayersOffsetYPerRod(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(
                String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_OFFSET_Y)));
 }
Exemple #16
0
 /// <summary>
 /// Get player rod first player position by rod type
 /// </summary>
 /// <param name="type">Rod Type</param>
 /// <param name="position">Point - position of first player of rod in Frame dimensions</param>
 public void Set(eRod type, Point position)
 {
     _playerPositions[type] = position;
 }
Exemple #17
0
 /// <summary>
 /// Draw a rod by a given eMark sign , moving the rod on the linear and rotational axes
 /// </summary>
 /// <param name="rod">eMark of the wanted rod : GoalKeeper, Defense , Midfield, Attack</param>
 /// <param name="linearMoveDestination">The change on the linear movement in Real World (MM)</param>
 /// <param name="rotationalMove">eRotationalMove of the rod : DEFENCE, RISE, ATTACK</param>
 public static void DrawRodPlayers(eRod rod, int linearMoveDestination, eRotationalMove rotationalMove)
 {
     try
     {
         Instance.DrawRodPlayers(rod, linearMoveDestination, rotationalMove);
     }
     catch (Exception ex)
     {
         Log.Print("Unable to draw rods players mark.", ex, LogTag.COMMON);
     }
 }
Exemple #18
0
 /// <summary>
 /// Get distance between stoppers on current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance between stoppers</returns>
 public static int GetRodDistanceBetweenStoppers(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(
                String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_STOPPER_DIST)));
 }
Exemple #19
0
 /// <summary>
 /// Convert rod type to first player on rod mark
 /// </summary>
 /// <param name="rodType">Rod Type</param>
 /// <returns>First player on rod mark</returns>
 public eMarks RodTypeToMarkOfFirstPlayerType(eRod rodType)
 {
     switch (rodType)
     {
         case eRod.GoalKeeper:
             return eMarks.GoalKeeperPlayer;
         case eRod.Defence:
             return eMarks.DefencePlayer1;
         case eRod.Midfield:
             return eMarks.MidfieldPlayer1;
         case eRod.Attack:
             return eMarks.AttackPlayer1;
         default:
             throw new NotSupportedException(String.Format(
         "Provided rod type {0} is not supported, and cannot be converted to eMark type of first player.", rodType));
     }
 }
Exemple #20
0
 /// <summary>
 /// Get First Player Y coordinate for Best Effort linear move
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>First Player Y coordinate for Best Effort</returns>
 public static int GetFirstPlayerBestEffort(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(
                String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_BEST_EFFORT)));
 }
Exemple #21
0
 /// <summary>
 /// Get X Coordinate of current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance from X min to current rod</returns>
 public static int GetRodXCoordinate(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(rodType.ToString()));
 }
Exemple #22
0
 /// <summary>
 /// Get Distance between players for current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance between players</returns>
 public static int GetPlayersDistancePerRod(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(
                String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_DISTANCE)));
 }
 /// <summary>
 /// Get Number of ticks per rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Rod Type</param>
 /// <returns>Number of ticks per rod</returns>
 public static int GetTicksPerRod(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_TICKS));
 }
Exemple #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">Current rod type</param>
 public RodData(eRod type)
 {
     RodType = type;
 }
Exemple #25
0
 /// <summary>
 /// Draw the given rod dynamic sector
 /// </summary>
 /// <param name="rod">The rod for sector calculation</param>
 /// <param name="dynamicSectorWidth">Width of dynamic sector of the rod in Real World (MM)</param>
 /// <param name="thickness">Optional thickness of the sector line [default : 2]</param>
 public static void DrawSector(eRod rod, int dynamicSectorWidth, int thickness = 2)
 {
     try
     {
         Instance.DrawSector(rod, dynamicSectorWidth, thickness);
     }
     catch (Exception ex)
     {
         Log.Print("Unable to draw rod dynamic sector marks.", ex, LogTag.COMMON);
     }
 }
 /// <summary>
 /// Start communication with Arduino unit on provided rod
 /// </summary>
 /// <param name="rodType">Rod type</param>
 private void Start(eRod rodType)
 {
     if (_allArduinos[rodType] != null)
         _allArduinos[rodType].Start();
 }
Exemple #27
0
 /// <summary>
 /// Get current first player position of selected rod
 /// In Frame Dimensions - used for Demo
 /// </summary>
 /// <param name="type">Rod Type</param>
 /// <returns>Selected rod first player position point (In Frame Dimensions)</returns>
 public static Point PlayerPosition(eRod type)
 {
     return Instance.PlayerPosition(type);
 }
Exemple #28
0
        /// <summary>
        /// If Arduino is connected per current rod and it has feedbacks on servo state
        /// this method should return false about the rod.
        /// If we are in demo mode without arduino state should be set in the tree
        /// because no one else will update it
        /// </summary>
        /// <returns>[True] If servo state should be set by decision try for current rod, [False] otherwise</returns>
        public bool ShouldSetServoStateFromTree(eRod rodType)
        {
            bool hasArduinoWithFeedback = _hasArduinoOnRod.ContainsKey(rodType) ?
                _hasArduinoOnRod[rodType] : Configuration.Attributes.IsServoExistsWithFeedback(rodType);

            bool isArduinoInUse = _isArduinoInUse ?? Configuration.Attributes.GetValue<bool>(Configuration.Names.KEY_IS_ARDUINOS_CONNECTED);
            bool isDemoMode = _isDemoMode ?? Configuration.Attributes.GetValue<bool>(Configuration.Names.KEY_IS_DEMO_MODE);

            return !(!isDemoMode && isArduinoInUse && hasArduinoWithFeedback);
        }
Exemple #29
0
 /// <summary>
 /// Get Number of ticks per rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Rod Type</param>
 /// <returns>Number of ticks per rod</returns>
 public static int GetTicksPerRod(this Configuration configuration, eRod rodType)
 {
     return(Configuration.Attributes.GetValue <int>(
                String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_TICKS)));
 }
Exemple #30
0
 public RodAction(eRod type, eRotationalMove rotation, eLinearMove linear)
 {
     Type     = type;
     Rotation = rotation;
     Linear   = linear;
 }
Exemple #31
0
 /// <summary>
 /// Get player rod first player position by rod type
 /// </summary>
 /// <param name="type">RodType</param>
 /// <returns>Point - position of first player of rod in Frame dimensions</returns>
 public Point Get(eRod type)
 {
     return _playerPositions[type];
 }
Exemple #32
0
        /// <summary>
        /// Control Rod Constructor
        /// </summary>
        /// <param name="rodType">Rod Type to construct</param>
        /// <param name="surveyor">Used in for range check vector intersection calculation</param>
        /// <param name="ricochetCalc">Used for ricochet in vector intersection calculation</param>
        /// <param name="tableHeight">Foosbot table height - rod length (Y) in mm</param>
        /// <param name="rodStopperMin">Minimal point can be reached by stopper (Y) in mm</param>
        /// <param name="rodState">Rod state will be created in initialization method if passed null</param>
        public ControlRod(eRod rodType, ISurveyor surveyor, IInitializableRicochet ricochetCalc, 
            int tableHeight = -1, int rodStopperMin = -1, IRodState rodState = null)
        {
            _rodType = rodType;
            _surveyor = surveyor;
            _vectorUtils = ricochetCalc;
            State = rodState;

            TABLE_HEIGHT = (tableHeight > 0) ? tableHeight
                : Configuration.Attributes.GetValue<int>(Configuration.Names.TABLE_HEIGHT);
            ROD_STOPPER_MIN = (rodStopperMin > 0) ? rodStopperMin
                : Configuration.Attributes.GetValue<int>(Configuration.Names.KEY_ROD_START_Y);
        }
 /// <summary>
 /// Get Number of ticks per rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Rod Type</param>
 /// <returns>[True] Servo feedback should be taken from arduino, [False] it should be taken from decision</returns>
 public static bool IsServoExistsWithFeedback(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<bool>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_SERVO_FEEDBACK));
 }
 /// <summary>
 /// Get Arduino Serial Port Per Rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Rod Type</param>
 /// <returns>Arduino Serial Port Name Per Rod as string</returns>
 public static string GetArduinoSerialPortPerRod(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<string>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_COM_PORT));
 }
 /// <summary>
 /// Provides decision if new action must be ignored based on in-sector timers
 /// </summary>
 /// <param name="rodType">Current rod type</param>
 /// <returns>[True] if operation should be ignored, [False] otherwise</returns>
 private bool IgnoreDecision(eRod rodType)
 {
     if(_sectorWatch[rodType]!=null)
     {
         return _sectorWatch[rodType].Elapsed < ACTION_DELAY;
     }
     else
     {
         return false;
     }
 }
 /// <summary>
 /// Get Distance (Y) of first player to border of a table for current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Offset in (mm)</returns>
 public static int GetPlayersOffsetYPerRod(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_OFFSET_Y));
 }
 /// <summary>
 /// Create Communication Port for Arduino on rod if defined
 /// </summary>
 /// <param name="rodType">Rod Type</param>
 /// <param name="publisher">Publisher for arduino actions</param>
 /// <param name="onServoChangeState">Method to call on arduino servo state changed</param>
 private void Create(eRod rodType, RodActionPublisher publisher, Action<eRod, eRotationalMove> onServoChangeState)
 {
     CommunicationUnit unit = null;
     if (Configuration.Attributes.IsServoExistsWithFeedback(rodType))
     {
         unit = new CommunicationUnit(publisher, rodType, ARDUINO_PORT[rodType], onServoChangeState);
         unit.InitializeRod();
         _allArduinos.Add(rodType, unit);
     }
 }
 /// <summary>
 /// Get Distance between players for current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance between players</returns>
 public static int GetPlayersDistancePerRod(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_DISTANCE));
 }
 public void RodType_Negative_NotInitialized()
 {
     eRod result = _testAsset.RodType;
 }
 /// <summary>
 /// Get X Coordinate of current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance from X min to current rod</returns>
 public static int GetRodXCoordinate(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(rodType.ToString());
 }
Exemple #41
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rodType">Current rod type</param>
 public ArduinoConverter(eRod rodType)
 {
     RodType = rodType;
 }
 /// <summary>
 /// Get First Player Y coordinate for Best Effort linear move
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>First Player Y coordinate for Best Effort</returns>
 public static int GetFirstPlayerBestEffort(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_BEST_EFFORT));
 }
Exemple #43
0
        /// <summary>
        /// Draw the given rod dynamic sector
        /// </summary>
        /// <param name="rod">The rod for sector calculation</param>
        /// <param name="dynamicSectorWidth">The dynamic sector of the rod</param>
        /// <param name="thickness">Optional thickness of the sector line [default : 2]</param>
        /// <param name="isLocation">Optional isLocation [default : true]</param>
        public static void DrawSector(eRod rod, int dynamicSectorWidth, int thickness = 2, bool isLocation = true)
        {
            try
            {
                Brush  color = null;
                eMarks mark;
                Enum.TryParse <eMarks>(rod.ToString(), out mark);

                int key = (int)mark * 10;
                int x   = XTableToDeviceCoordinates(_rods[mark]);

                int sectorStart       = Convert.ToInt32(x - dynamicSectorWidth / 2.0);
                int sectorStartTop    = sectorStart;
                int sectorStartButtom = sectorStart;

                int sectorEnd       = Convert.ToInt32(x + dynamicSectorWidth / 2.0);
                int sectorEndTop    = sectorEnd;
                int sectorEndButtom = sectorEnd;

                int yTop    = 0;
                int yButtom = ((int)DEVICE_MAX_Y);

                _dispatcher.Invoke(new ThreadStart(delegate
                {
                    switch (mark)
                    {
                    case eMarks.GoalKeeper: color = Brushes.Yellow; break;

                    case eMarks.Defence: color = Brushes.Pink; break;

                    case eMarks.Midfield: color = Brushes.Red; break;

                    case eMarks.Attack: color = Brushes.DarkRed; break;

                    default: break;
                    }

                    if (isLocation)
                    {
                        int yButtomTemp = yButtom;
                        int yTopTemp    = yTop;
                        ConvertToLocation(ref sectorStartTop, ref yTop);
                        ConvertToLocation(ref sectorStartButtom, ref yButtom);
                        ConvertToLocation(ref sectorEndTop, ref yTopTemp);
                        ConvertToLocation(ref sectorEndButtom, ref yButtomTemp);
                    }

                    (_markups[key] as Shape).StrokeThickness = thickness;
                    (_markups[key] as Shape).Stroke          = color;
                    (_markups[key] as Line).X1 = sectorStartTop * _actualWidthRate;
                    (_markups[key] as Line).Y1 = yTop * _actualHeightRate;
                    (_markups[key] as Line).X2 = sectorStartButtom * _actualWidthRate;
                    (_markups[key] as Line).Y2 = yButtom * _actualHeightRate;

                    (_markups[key + 1] as Shape).StrokeThickness = thickness;
                    (_markups[key + 1] as Shape).Stroke          = color;
                    (_markups[key + 1] as Line).X1 = sectorEndTop * _actualWidthRate;
                    (_markups[key + 1] as Line).Y1 = yTop * _actualHeightRate;
                    (_markups[key + 1] as Line).X2 = sectorEndButtom * _actualWidthRate;
                    (_markups[key + 1] as Line).Y2 = yButtom * _actualHeightRate;

                    Canvas.SetLeft(_markups[key], 0);
                    Canvas.SetTop(_markups[key], 0);
                    Canvas.SetLeft(_markups[key + 1], 0);
                    Canvas.SetTop(_markups[key + 1], 0);
                }));
            }
            catch (Exception e)
            {
                Log.Print(String.Format("Failed to draw rod dynamic sector marks. Reason: {0}", e.Message), eCategory.Error, LogTag.COMMON);
            }
        }
 /// <summary>
 /// Get distance between stoppers on current rod
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="rodType">Current Rod Type</param>
 /// <returns>Distance between stoppers</returns>
 public static int GetRodDistanceBetweenStoppers(this Configuration configuration, eRod rodType)
 {
     return Configuration.Attributes.GetValue<int>(
         String.Format("{0}{1}", rodType.ToString(), Configuration.Names.SUBKEY_STOPPER_DIST));
 }
Exemple #45
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="rodType">Current rod type</param>
 public RodActionConverter(eRod rodType)
 {
     RodType = rodType;
 }
Exemple #46
0
        /// <summary>
        /// Draw sector of selected rod
        /// </summary>
        /// <param name="type">Rod type to draw sector for</param>
        /// <param name="dynamicSectorWidth">Sector width in MM (Real World coordinates)</param>
        /// <param name="thickness">Line thickness [Default is 2]</param>
        public void DrawSector(eRod type, int dynamicSectorWidth, int thickness = 2)
        {
            //Get sector line points in a real world
            Point lineAButtom = new Point(Data.GetRod(type).XCoordinate + dynamicSectorWidth / 2.0, Data.TableMaxY);
            Point lineATop = new Point(Data.GetRod(type).XCoordinate + dynamicSectorWidth / 2.0, 0);
            Point lineBButtom = new Point(Data.GetRod(type).XCoordinate - dynamicSectorWidth / 2.0, Data.TableMaxY);
            Point lineBTop = new Point(Data.GetRod(type).XCoordinate - dynamicSectorWidth / 2.0, 0);

            //Get sector line point coordiantes as Screen coordinates
            lineAButtom = ConvertPointFromRealWorldToScreen(lineAButtom);
            lineATop = ConvertPointFromRealWorldToScreen(lineATop);
            lineBButtom = ConvertPointFromRealWorldToScreen(lineBButtom);
            lineBTop = ConvertPointFromRealWorldToScreen(lineBTop);

            //Select color for current sector lines
            Brush color = Brushes.Yellow;
            switch (type)
            {
                case eRod.Defence: color = Brushes.Pink; break;
                case eRod.Midfield: color = Brushes.Red; break;
                case eRod.Attack: color = Brushes.DarkRed; break;
            }

            //get sector line marks for current rod
            eMarks markA, markB;
            TryParseToSectorLineMarks(type, out markA, out markB);

            _dispatcher.Invoke(() =>
            {
                //draw line A
                _screen.Element<Line>(markA).StrokeThickness = thickness;
                _screen.Element<Line>(markA).Stroke = color;
                _screen.Element<Line>(markA).X1 = lineATop.X;
                _screen.Element<Line>(markA).Y1 = lineATop.Y;
                _screen.Element<Line>(markA).X2 = lineAButtom.X;
                _screen.Element<Line>(markA).Y2 = lineAButtom.Y;
                _screen.Draw(markA, 0, 0, eCoordinatesType.Screen);

                //draw line B
                _screen.Element<Line>(markB).StrokeThickness = thickness;
                _screen.Element<Line>(markB).Stroke = color;
                _screen.Element<Line>(markB).X1 = lineBTop.X;
                _screen.Element<Line>(markB).Y1 = lineBTop.Y;
                _screen.Element<Line>(markB).X2 = lineBButtom.X;
                _screen.Element<Line>(markB).Y2 = lineBButtom.Y;
                _screen.Draw(markB, 0, 0, eCoordinatesType.Screen);
            });
        }