示例#1
0
文件: Tile.cs 项目: pprintz/p2
 public double DistanceTo(Tile other)
 {
     //Diagonaldistance
     // Every floor has 15 steps on the staircase in between them.
     return Math.Abs(Math.Sqrt(Math.Pow(other.X - X, 2) + Math.Pow(other.Y - Y, 2)) + Math.Abs(Z-other.Z)*15); 
     
 }
示例#2
0
 public MovementStep(Person person, Tile sourceTile, Tile destinationTile)
 {
     Person = person;
     SourceTile = sourceTile;
     DestinationTile = destinationTile;
     Distance = sourceTile.DistanceTo(destinationTile);
     DistanceInMeters = Distance * GlobalVariables.BlockWidthInMeters;
     Person.PersonInteractionStats.DistanceTraveled += DistanceInMeters;
 }
示例#3
0
文件: TileTests.cs 项目: pprintz/p2
 public void TileConstructorTest()
 {
     Tile tile = new Tile(0, 0);
     Assert.AreEqual(0, tile.X);
     Assert.AreEqual(0, tile.Y);
     Assert.AreEqual(0, tile.Z);
     Tile newtile = new Tile(Int32.MaxValue, Int32.MinValue);
     Assert.AreEqual(Int32.MaxValue, newtile.X);
     Assert.AreEqual(Int32.MinValue, newtile.Y);
     Assert.AreEqual(Tile.Types.Free, tile.Type);
 }
示例#4
0
        private void ColorizeBuildingBlock(Rectangle buildingBlockRepresentation, Tile.Types type)
        {
            Color newColor;
            switch (type)
            {
                case Tile.Types.Free:
                    newColor = Colors.White;
                    break;
                case Tile.Types.Occupied:
                    newColor = Colors.Green;
                    break;
                case Tile.Types.Furniture:
                    newColor = Colors.Gray;
                    break;
                case Tile.Types.Wall:
                    newColor = Colors.Black;
                    break;
                case Tile.Types.Door:
                    newColor = Colors.Pink;
                    break;
                case Tile.Types.Exit:
                    newColor = Colors.Blue;
                    break;
                case Tile.Types.Person:
                    newColor = Colors.BlueViolet;
                    break;
                case Tile.Types.Stair:
                    newColor = Colors.Thistle;
                    break;
                default:
                    newColor = Colors.BlanchedAlmond;
                    break;
            }

            ColorRectangle(buildingBlockRepresentation, newColor);
        }
示例#5
0
        private void DrawLine(BuildingBlock block, Tile.Types targetType)
        {
            if (block.X == previousBlock.X && block.Y == previousBlock.Y)
            {
                // The same block has been pressed twice.
                return;
            }
            int deltaX = block.X - previousBlock.X; 
            int deltaY = block.Y - previousBlock.Y;

            // deltaTilt is the tilt of the line per pixel
            double deltaTilt = Math.Min(Math.Abs((double)deltaY / (double)deltaX), Math.Abs((double)deltaY)) * Math.Sign((double)deltaY / (double)deltaX);
            double tilt = 0;

            int i = 0;
            // Iterates through each line in X
            do
            {
                int j = 0;
                // Iterates though each pixel in the current X line, until j is bigger or equal to deltaTilt
                do
                {
                    int x = i + previousBlock.X;
                    int y = (int)(tilt) + previousBlock.Y + j;

                    SetBlockType((BuildingBlock)LocalFloorPlan.Tiles[Coordinate(x, y, block.Z)], targetType);

                    j += Math.Sign(deltaY);
                } while (Math.Abs(j) < Math.Abs(deltaTilt));

                tilt += deltaTilt * Math.Sign(deltaX);
                i += Math.Sign(deltaX);
            } while (Math.Abs(i) < Math.Abs(deltaX));
        }
示例#6
0
 private void SetBlockType(BuildingBlock block, Tile.Types targetType)
 {
     if (targetType != Tile.Types.Person)
     {
         UserInterface.BuildingHasBeenChanged = true;
     }
     block.Type = targetType;
     block.OriginalType = targetType;
     ColorizeBuildingBlock(block.Figure, targetType);
 }
示例#7
0
文件: Person.cs 项目: pprintz/p2
 public void ConditionalMove()
 { // Person should be removed from event thingy when evacuated
     if (UpdateTickCondition)
     {
         double percentageStepDone = AmountOfTicksSpent / (double)_ticksToWaitBeforeNextMove;
         ResetTickConditions();
         AmountOfTicksSpent = (int)(_ticksToWaitBeforeNextMove * percentageStepDone);
         UpdateTickCondition = false;
     }
     AmountOfTicksSpent++;
     if (_firstRun)
     {
         _target = PathList[StepsTaken + 1];
         ResetTickConditions();
         _firstRun = false;
     }
     if (_ticksSpentWaiting == _ticksToWaitBeforeNextMove)
     {
         Move();
         ResetTickConditions();
     }
     else
     {
         _ticksSpentWaiting++;
     }
 }
示例#8
0
文件: Person.cs 项目: pprintz/p2
 private void Move()
 {
     // Clear old Tile and increment heatMapCounter
     ((BuildingBlock)Position).HeatmapCounter++;
     if (StepsTaken + 1 < PathList.Count)
     {
         _target = PathList[StepsTaken + 1];
     }
     if (_target.Type != Tile.Types.Person || _target.OriginalType == Tile.Types.Stair)
     {
         // Move to new tile and check if evacuated. If not, keep going. Update the persons statistics..
         if (StepsTaken + 1 < PathList.Count)
         {
             PersonInteractionStats.MovementSteps.Add(new MovementStep(this, PathList[StepsTaken],
                 PathList[StepsTaken + 1])
             { TicksAtArrival = AmountOfTicksSpent });
             StepsTaken++;
         }
         Position = _target;
         if (Position.Type == Tile.Types.Exit)
         {
             Evacuated = true;
         }
         _roundsWaitedBecauseOfBlock = 0;
         OnPersonMoved?.Invoke(this);
     }
     else
     {
         // Counts up the heatmapcounter for every "round" the person needs to wait before moving.
         ((BuildingBlock)Position).HeatmapCounter++;
         PersonInteractionStats.CountTicksBeingBlocked(_ticksSpentWaiting);
         _roundsWaitedBecauseOfBlock++;
         if (_roundsWaitedBecauseOfBlock >= 5 && _target.Type == Tile.Types.Person)
         {
             //Gets a new path for the person and sets the new target tile
             OnExtendedPathRequest?.Invoke(this);
             _target = PathList[StepsTaken + 1];
             //Executes the step
             if (PathList.Count > StepsTaken + 1 && _target.Type != Tile.Types.Person)
             {
                 PersonInteractionStats.MovementSteps.Add(new MovementStep(this, PathList[StepsTaken],
               PathList[StepsTaken + 1])
                 { TicksAtArrival = AmountOfTicksSpent });
                 StepsTaken++;
                 Position = PathList[StepsTaken + 1];
                 _roundsWaitedBecauseOfBlock = 0;
                 OnPersonMoved?.Invoke(this);
             }
         }
     }
 }
示例#9
0
文件: Settings.cs 项目: pprintz/p2
 /// <summary>
 /// Converts the given tile's X, Y and Z coordinates, to a string in the form of CoordinateKeyFormat.
 /// </summary>
 /// <param name="tile">The tile to get coordinates from</param>
 /// <returns></returns>
 public static string Coordinate(Tile tile) {
     return string.Format(CoordinateKeyFormat, tile.X, tile.Y, tile.Z);
 }