/// <summary>
        /// Will make a quick station record in station table, from a given xy position.
        /// XY will be used to create a quick location first
        /// </summary>
        /// <param name="inPosition"></param>
        /// <returns>A detail report class</returns>
        public FieldNotes QuickStation(FieldLocation inPosition)
        {
            //Create a quick location first
            string quickLocID = QuickLocation(inPosition);

            //Calculate air and traverse #
            FillAirPhotoNo_TraverseNo();

            //Save the new station
            StationModel.StationID        = _stationid;                         //Prime key
            StationModel.LocationID       = quickLocID;                         //Foreign key
            StationModel.StationAlias     = _alias;
            StationModel.StationVisitDate = _dateDate = CalculateStationDate(); //Calculate new value
            StationModel.StationVisitTime = _dateTime = CalculateStationTime(); //Calculate new value
            StationModel.StationAirNo     = _airno;
            if (_stationTravNo != string.Empty)
            {
                StationModel.StationTravNo = Convert.ToInt32(_stationTravNo);
            }


            accessData.SaveFromSQLTableObject(StationModel, false);

            FieldNotes outputStationReport = new FieldNotes();

            outputStationReport.ParentID         = quickLocID;
            outputStationReport.GenericID        = _stationid;
            outputStationReport.GenericAliasName = _alias;
            outputStationReport.GenericTableName = Dictionaries.DatabaseLiterals.TableStation;
            outputStationReport.station          = StationModel;

            return(outputStationReport);
        }
        /// <summary>
        /// Will make quick location record in location table, from a given xy position
        /// </summary>
        /// <param name="inLocation"></param>
        /// <returns>Location ID</returns>
        public string QuickLocation(FieldLocation inLocation)
        {
            //Set location
            if (inLocation != null)
            {
                //SetCurrentLocationInUI(inLocation);
                Location.LocationElevMethod        = inLocation.LocationElevMethod;
                Location.LocationEntryType         = inLocation.LocationEntryType;
                Location.LocationErrorMeasure      = inLocation.LocationErrorMeasure;
                Location.LocationErrorMeasureType  = inLocation.LocationErrorMeasureType;
                Location.LocationElevationAccuracy = inLocation.LocationElevationAccuracy;
                Location.LocationPDOP  = inLocation.LocationPDOP;
                Location.LocationLat   = inLocation.LocationLat;
                Location.LocationLong  = inLocation.LocationLong;
                Location.LocationElev  = inLocation.LocationElev;
                Location.LocationDatum = Dictionaries.DatabaseLiterals.KeywordEPSGDefault;
            }
            else
            {
                //Init location
                Location.LocationLat  = _latitude;
                Location.LocationLong = _longitude;
                Location.LocationElev = _elevation;
            }

            Location.LocationID    = _locationid = idCalculator.CalculateLocationID();                                       //Calculate new value
            Location.LocationAlias = _locationAlias = idCalculator.CalculateLocationAlias(_alias);                           //Calculate new value
            Location.MetaID        = localSetting.GetSettingValue(Dictionaries.DatabaseLiterals.FieldUserInfoID).ToString(); //Foreign key


            accessData.SaveFromSQLTableObject(Location, false);

            return(Location.LocationID);
        }
        public void FieldLocation_CheckEncodeDecode()
        {
            ByteList bytes = new ByteList();

            FieldLocation loc1 = new FieldLocation {
                X = 100, Y = 200
            };

            loc1.Encode(bytes);
            Assert.AreEqual(9, bytes.Length);
            Assert.AreEqual(3, bytes[0]);
            Assert.AreEqual(238, bytes[1]);
            Assert.AreEqual(0, bytes[2]);
            Assert.AreEqual(5, bytes[3]);
            Assert.AreEqual(0, bytes[4]);
            Assert.AreEqual(100, bytes[5]);
            Assert.AreEqual(0, bytes[6]);
            Assert.AreEqual(200, bytes[7]);
            Assert.AreEqual(0, bytes[8]);

            FieldLocation loc2 = FieldLocation.Create(bytes);

            Assert.AreEqual(loc1.X, loc2.X);
            Assert.AreEqual(loc1.Y, loc2.Y);
            Assert.AreEqual(false, loc2.Immutable);
        }
Exemple #4
0
        public override List <FieldLocation> GetFieldsICanMoveTo()
        {
            var attackingFields = new List <FieldLocation>();

            var rowMod = Side == GameSide.White ? 1 : -1;

            attackingFields.Add(new FieldLocation(Location.Row + rowMod, Location.Column - 1));
            attackingFields.Add(new FieldLocation(Location.Row + rowMod, Location.Column + 1));

            var moveField = new FieldLocation(Location.Row + rowMod, Location.Column);

            var validFields = new List <FieldLocation>();

            if (Board.GetFigureOnLocation(moveField) == null)
            {
                validFields.Add(moveField);
                if ((Location.Row == 2 && Side == GameSide.White) || (Location.Row == 7 && Side == GameSide.Black))
                {
                    var moveTwoField = new FieldLocation(Location.Row + 2 * rowMod, Location.Column);
                    if (Board.GetFigureOnLocation(moveTwoField) == null)
                    {
                        validFields.Add(moveTwoField);
                    }
                }
            }

            validFields.AddRange(attackingFields.Where(x =>
            {
                var figure = Board.GetFigureOnLocation(x);
                return(figure != null && figure.Side != Side);
            }));
            return(validFields);
        }
Exemple #5
0
        public override List<FieldLocation> GetFieldsICanMoveTo()
        {
            var attackingFields = new List<FieldLocation>();

            var rowMod = Side == GameSide.White ? 1 : -1;

            attackingFields.Add(new FieldLocation(Location.Row + rowMod, Location.Column - 1));
            attackingFields.Add(new FieldLocation(Location.Row + rowMod, Location.Column + 1));

            var moveField = new FieldLocation(Location.Row + rowMod, Location.Column);

            var validFields = new List<FieldLocation>();
            if (Board.GetFigureOnLocation(moveField) == null)
            {
                validFields.Add(moveField);
                if ((Location.Row == 2 && Side == GameSide.White) || (Location.Row == 7 && Side == GameSide.Black))
                {
                    var moveTwoField = new FieldLocation(Location.Row + 2*rowMod, Location.Column);
                    if (Board.GetFigureOnLocation(moveTwoField) == null)
                        validFields.Add(moveTwoField);
                }
            }

            validFields.AddRange(attackingFields.Where(x =>
            {
                var figure = Board.GetFigureOnLocation(x);
                return figure != null && figure.Side != Side;
            }));
            return validFields;
        }
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public Move(Int16 componentId, FieldLocation toSquare, Tick tick)
     : base(PossibleTypes.Move)
 {
     ComponentId  = componentId;
     ToSquare     = toSquare;
     EnablingTick = tick;
 }
 public void SetCurrentLocationInUI(FieldLocation inPosition)
 {
     _location  = inPosition;
     _latitude  = inPosition.LocationLat;
     _longitude = inPosition.LocationLong;
     _elevation = inPosition.LocationElev;
 }
Exemple #8
0
 /// <summary>
 /// Constructor used by senders of a message
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 public ThrowBomb(Int16 bsId, Bomb bomb, FieldLocation towardsSquare, Tick tick)
     : base(PossibleTypes.Move)
 {
     ThrowingBrilliantStudentId = bsId;
     Bomb          = bomb;
     TowardsSquare = towardsSquare;
     EnablingTick  = tick;
 }
        public void FieldLocation_CheckProperties()
        {
            FieldLocation loc = new FieldLocation();

            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(false, loc.Immutable);

            loc.X = 100;
            Assert.AreEqual(100, loc.X);
            loc.X = -200;
            Assert.AreEqual(-200, loc.X);
            loc.X = 0;
            Assert.AreEqual(0, loc.X);


            loc.Y = 100;
            Assert.AreEqual(100, loc.Y);
            loc.Y = -200;
            Assert.AreEqual(-200, loc.Y);
            loc.Y = 0;
            Assert.AreEqual(0, loc.Y);

            loc = new ImmutableFieldLocation {
                X = 10, Y = 20
            };
            Assert.AreEqual(10, loc.X);
            Assert.AreEqual(20, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc.X = 100;
            Assert.AreEqual(10, loc.X);
            loc.X = -200;
            Assert.AreEqual(10, loc.X);
            loc.X = 0;
            Assert.AreEqual(10, loc.X);

            loc.Y = 100;
            Assert.AreEqual(20, loc.Y);
            loc.Y = -200;
            Assert.AreEqual(20, loc.Y);
            loc.Y = 0;
            Assert.AreEqual(20, loc.Y);
        }
        private ICronField ParseField(FieldLocation location, string field)
        {
            switch (location)
            {
            case FieldLocation.Minute:
                return(MinuteFactory.Parse(field));

            case FieldLocation.Hour:
                return(HourFactory.Parse(field));

            case FieldLocation.DayOfMonth:
                return(DayOfMonthFactory.Parse(field));

            case FieldLocation.Month:
                return(MonthFactory.Parse(field));

            case FieldLocation.DayOfWeek:
                return(DayOfWeekFactory.Parse(field));

            default:
                throw new InvalidOperationException($"Unsupported field {location}");
            }
        }
        public void FieldLocation_CheckDistance()
        {
            FieldLocation loc1 = new FieldLocation {
                X = 100, Y = 100
            };
            FieldLocation loc2 = new FieldLocation {
                X = 103, Y = 104
            };

            Assert.AreEqual(5, FieldLocation.Distance(loc1, loc2));
            Assert.AreEqual(5, FieldLocation.Distance(loc2, loc1));
            Assert.AreEqual(float.PositiveInfinity, FieldLocation.Distance(null, loc2));
            Assert.AreEqual(float.PositiveInfinity, FieldLocation.Distance(loc1, null));
            Assert.AreEqual(float.PositiveInfinity, FieldLocation.Distance(null, null));

            loc1 = new FieldLocation {
                X = 0, Y = 0
            };
            loc2 = new FieldLocation {
                X = 5, Y = 12
            };
            Assert.AreEqual(13, FieldLocation.Distance(loc1, loc2));
            Assert.AreEqual(13, FieldLocation.Distance(loc2, loc1));
        }
Exemple #12
0
 public bool CanMoveToLocation(FieldLocation to)
 {
     return GetFieldsICanMoveTo().Contains(to);
 }
Exemple #13
0
        public void AgentInfo_CheckProperties()
        {
            EndPoint  ep   = new EndPoint("129.123.7.24:1345");
            AgentInfo info = new AgentInfo(20, AgentInfo.PossibleAgentType.WhiningSpinner, ep)
            {
                ANumber   = "A00001",
                FirstName = "Joe",
                LastName  = "Jones",
                Location  = new FieldLocation(10, 20, false),
                Strength  = 1200.5,
                Speed     = 1500.0,
                Points    = 3332.42
            };

            Assert.AreEqual(20, info.Id);
            Assert.AreEqual(AgentInfo.PossibleAgentType.WhiningSpinner, info.AgentType);
            Assert.AreEqual("A00001", info.ANumber);
            Assert.AreEqual("Joe", info.FirstName);
            Assert.AreEqual("Jones", info.LastName);
            Assert.AreEqual(1200.5, info.Strength);
            Assert.AreEqual(1500.0, info.Speed);
            Assert.AreEqual(3332.42, info.Points);
            Assert.AreEqual(10, info.Location.X);
            Assert.AreEqual(20, info.Location.Y);
            Assert.AreSame(ep, info.CommunicationEndPoint);

            info.Changed += ChangedEventHandler;

            // Id Property
            recentStateChange = null;
            info.Id           = 1002;
            Assert.AreEqual(1002, info.Id);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            recentStateChange = null;
            info.Id           = 0;
            Assert.AreEqual(0, info.Id);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            info.Id = Int16.MaxValue;
            Assert.AreEqual(Int16.MaxValue, info.Id);
            info.Id = 10;
            Assert.AreEqual(10, info.Id);

            // AgentType
            recentStateChange = null;
            info.AgentType    = AgentInfo.PossibleAgentType.BrilliantStudent;
            Assert.AreEqual(AgentInfo.PossibleAgentType.BrilliantStudent, info.AgentType);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            // Status
            info.AgentStatus = AgentInfo.PossibleAgentStatus.InGame;
            Assert.AreEqual(AgentInfo.PossibleAgentStatus.InGame, info.AgentStatus);
            info.AgentStatus = AgentInfo.PossibleAgentStatus.TryingToJoin;
            Assert.AreEqual(AgentInfo.PossibleAgentStatus.TryingToJoin, info.AgentStatus);
            info.AgentStatus = AgentInfo.PossibleAgentStatus.WonGame;
            Assert.AreEqual(AgentInfo.PossibleAgentStatus.WonGame, info.AgentStatus);

            // ANumber
            recentStateChange = null;
            info.ANumber      = "A000234";
            Assert.AreEqual("A000234", info.ANumber);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            info.ANumber = null;
            Assert.IsNull(info.ANumber);
            info.ANumber = "A012345";
            Assert.AreEqual("A012345", info.ANumber);

            // FirstName
            recentStateChange = null;
            info.FirstName    = "Henry";
            Assert.AreEqual("Henry", info.FirstName);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            info.FirstName = null;
            Assert.IsNull(info.FirstName);
            info.FirstName = "John";
            Assert.AreEqual("John", info.FirstName);

            // LastName
            recentStateChange = null;
            info.LastName     = "Franks";
            Assert.AreEqual("Franks", info.LastName);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            info.LastName = null;
            Assert.IsNull(info.LastName);
            info.LastName = "Jones";
            Assert.AreEqual("Jones", info.LastName);

            // Strength
            recentStateChange = null;
            info.Strength     = 123.45;
            Assert.AreEqual(123.45, info.Strength);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            // Speed
            recentStateChange = null;
            info.Speed        = 23.456;
            Assert.AreEqual(23.456, info.Speed);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            // Speed
            recentStateChange = null;
            info.Points       = 53.6;
            Assert.AreEqual(53.6, info.Points);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            // Location
            recentStateChange = null;
            FieldLocation f = new FieldLocation(10, 20);

            info.Location = f;
            Assert.AreSame(f, info.Location);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);

            // CommunicationEndPoint
            recentStateChange = null;
            EndPoint ep1 = new EndPoint(3242, 1000);

            info.CommunicationEndPoint = ep1;
            Assert.AreSame(ep1, info.CommunicationEndPoint);
            Assert.IsNotNull(recentStateChange);
            Assert.AreEqual(recentStateChange.Type, StateChange.ChangeType.UPDATE);
            Assert.AreSame(info, recentStateChange.Subject);
        }
Exemple #14
0
 public Move(int rowFrom, int colFrom, int rowTo, int colTo, GameSide gameSide)
 {
     Side = gameSide;
     From = new FieldLocation(rowFrom, colFrom);
     To = new FieldLocation(rowTo, colTo);
 }
Exemple #15
0
 protected Figure(GameSide side, int row, int col)
 {
     Side = side;
     Location = new FieldLocation(row, col);
 }
Exemple #16
0
 protected Figure(GameSide side, int row, int col)
 {
     Side     = side;
     Location = new FieldLocation(row, col);
 }
Exemple #17
0
 public Move(FieldLocation from, FieldLocation to, GameSide gameSide)
 {
     From = new FieldLocation(from.Row, from.Column);
     To = new FieldLocation(to.Row, to.Column);
     Side = gameSide;
 }
Exemple #18
0
 public bool CanMoveToLocation(FieldLocation to)
 {
     return(GetFieldsICanMoveTo().Contains(to));
 }
Exemple #19
0
 public Figure GetFigureOnLocation(FieldLocation fieldLocation)
 {
     return Figures.FirstOrDefault(x => x.Location.Row == fieldLocation.Row && x.Location.Column == fieldLocation.Column);
 }
Exemple #20
0
 public override int GetHashCode()
 {
     return(FieldLocation.GetHashCode());
 }
        public void FieldLocation_CheckContructors()
        {
            FieldLocation loc = new FieldLocation();

            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(false, loc.Immutable);

            loc = new FieldLocation(10, 20);
            Assert.AreEqual(10, loc.X);
            Assert.AreEqual(20, loc.Y);
            Assert.AreEqual(false, loc.Immutable);

            loc = new FieldLocation(-20, -30, true);
            Assert.AreEqual(-20, loc.X);
            Assert.AreEqual(-30, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc = new FieldLocation(false);
            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(false, loc.Immutable);

            loc = new FieldLocation(true);
            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc = new FieldLocation {
                X = 10, Y = 30
            };
            Assert.AreEqual(10, loc.X);
            Assert.AreEqual(30, loc.Y);
            Assert.AreEqual(false, loc.Immutable);

            loc = new ImmutableFieldLocation();
            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc = new ImmutableFieldLocation {
                X = 0, Y = 0
            };
            Assert.AreEqual(0, loc.X);
            Assert.AreEqual(0, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc = new ImmutableFieldLocation {
                X = 100, Y = 200
            };
            Assert.AreEqual(100, loc.X);
            Assert.AreEqual(200, loc.Y);
            Assert.AreEqual(true, loc.Immutable);

            loc = new ImmutableFieldLocation {
                X = -200, Y = -300
            };
            Assert.AreEqual(-200, loc.X);
            Assert.AreEqual(-300, loc.Y);
            Assert.AreEqual(true, loc.Immutable);
        }
Exemple #22
0
 private bool IsInBoard(FieldLocation location)
 {
     return location.Column >= 1 && location.Row >= 1 && location.Column <= 8 && location.Row <= 8;
 }