示例#1
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);
            }
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Initialization Using Configuration file
        /// </summary>
        public void Initialize()
        {
            if (!IsInitialized)
            {
                _rodXCoordinate              = Configuration.Attributes.GetValue <int>(_rodType.ToString());
                _minSectorWidth              = Configuration.Attributes.GetValue <int>(Configuration.Names.TABLE_RODS_DIST);
                _sectorFactor                = Configuration.Attributes.GetValue <double>(Configuration.Names.SECTOR_FACTOR);
                _playerDistance              = Configuration.Attributes.GetPlayersDistancePerRod(_rodType);
                _playerCount                 = Configuration.Attributes.GetPlayersCountPerRod(_rodType);
                _offsetY                     = Configuration.Attributes.GetPlayersOffsetYPerRod(_rodType);
                _stopperDistance             = Configuration.Attributes.GetRodDistanceBetweenStoppers(_rodType);
                _bestEffort                  = Configuration.Attributes.GetFirstPlayerBestEffort(_rodType);
                _predictIntersectionTimespan = Configuration.Attributes.GetValue <int>(Configuration.Names.KEY_ROD_INTERSECTION_MAX_TIMESPAN_SEC);

                MinimumPossibleStartStopperY = ROD_STOPPER_MIN;
                MaximumPossibleStartStopperY = TABLE_HEIGHT - ROD_STOPPER_MIN - _stopperDistance;

                if (State == null)
                {
                    State = new RodState(MinimumPossibleStartStopperY, MaximumPossibleStartStopperY);
                }

                DynamicSector = _minSectorWidth;
                IsInitialized = true;
            }
        }
 /// <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));
 }
 /// <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));
 }
 /// <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));
 }
 /// <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());
 }
示例#8
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 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));
 }
示例#10
0
 /// <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));
 }
示例#11
0
 /// <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));
 }
示例#12
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)));
 }
示例#13
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)));
 }
示例#14
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)));
 }
示例#15
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()));
 }
示例#16
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);
            }
        }
示例#17
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));
 }
示例#18
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)));
 }