Beispiel #1
0
 public AmusementDetailForm(GameRecords model, Amusements a, Image im, View2 view)
 {
     InitializeComponent();
     exit_button.Parent = panel1;
     entrance_button.Parent = panel1;
     exit_button.Tag = new AmusementExitPathFactory(a);
     entrance_button.Tag = new AmusementEnterPathFactory(a);
     this.model = model;
     this.view = view;
     this.pictureBox.BackgroundImage = im;
     this.a = a;
     this.Text = a.name;
     a.isClicked = true;
     MyUpdate();
 }
Beispiel #2
0
 /* private void DrawImages(Image im, Color color, Graphics gr, Rectangle rect) {
      sbr.Color = color;
      gr.FillRectangle(sbr, rect);
      gr.DrawImage(im, rect);
  }*/
 private void DrawAmusement(Graphics gr, Amusements amus)
 {
     Size size = amus.GetRealSize();
     Point point = amus.GetRealCoordinates();
     Rectangle rect = new Rectangle(point, size);
     if (!amus.Crashed) sbr.Color = amus.color;
     else sbr.Color = Color.Black;
     gr.FillRectangle(sbr, rect);
     if (amus is RectangleAmusements && !((RectangleAmusements)amus).isHorizontalOriented) {
         Image im = (Image)(model.images[amus.internTypeID]).Clone();
         im.RotateFlip(RotateFlipType.Rotate90FlipNone);
         gr.DrawImage(im, rect);
     }
     else gr.DrawImage(model.images[amus.internTypeID], rect);
 }
Beispiel #3
0
 public AmusementEnterPathFactory(Amusements a)
     : base(prize:0, name: "")
 {
     this.a = a;
 }
Beispiel #4
0
 public AmusementEnterPath(GameRecords m, Coordinates c, Amusements a, bool tangible = true)
     : base(m, c, a, typeId: 1, tangible: tangible)
 {
     model.mustBeEnter = false;
         a.entrance = this;
 }
Beispiel #5
0
 //not call base(m,c) because dont want to add to maps
 public AmusementPath(GameRecords m, Coordinates c, Amusements a, int typeId, bool tangible = true)
     : base(m, prize: 0, typeId: typeId, tangible: tangible)
 {
     this.coord = c;
     this.amusement = a;
     model.maps.AddEntranceExit(this);
 }
Beispiel #6
0
        public void Action()
        {
            hunger = Math.Min(hunger+1,2000);
            switch (status)
            {
                case Status.walking:{
                    #region
                    if (remainingStepsCount > 0) {
                        remainingStepsCount--;
                        switch (currDirection)
                        {
                            case Direction.N: Interlocked.Decrement(ref realY);
                                break;
                            case Direction.S: Interlocked.Increment(ref realY);
                                break;
                            case Direction.W: Interlocked.Decrement(ref realX);
                                break;
                            case Direction.E: Interlocked.Increment(ref realX);
                                break;
                            case Direction.no: { status = Status.choosesAmus;}
                                break;
                            case Direction.here: {

                                lock (xyLock) {  // lock is not necessary here, only an amusement changes x and y together and the person is not in an amusement, yet.
                                    currAmus = model.maps.GetAmusement(realX, realY);
                                }
                                if (currAmus == null) {
                                    AddContentment(-10); //todo: ubrat spokojenost
                                    status = Status.choosesAmus; return;
                                }
                                if (currAmus.Id != CurrAmusId) throw new MyDebugException("Person.Action - lisi se ocekavane id");
                                if (currAmus.CurrFee > maxAcceptablePriceCoef * currAmus.originalFee){
                                    AddContentment(-25);//todo: nastavit poradne
                                    status = Status.choosesAmus;
                                }
                                else if (currAmus.CurrFee > money) {
                                    status = Status.choosesAmus;
                                }
                                else {
                                    status = Status.inAmusQueue;
                                    waitingTimeInQueue = 0;
                                    if (!currAmus.TryQueuesPerson(this)) {
                                        AddContentment(-10);
                                        status = Status.choosesAmus;
                                    }
                                }
                            }
                                break;
                        }
                    }
                    else {
                        status = Status.onCrossroad;
                    }
                    #endregion
                }
                    break;
                case Status.onCrossroad: {
                    #region
                    currDirection=model.maps.GetDirectionToAmusement(CurrAmusId,realX,realY);
                    status = Status.walking;
                    remainingStepsCount = MainForm.sizeOfSquare;
                    #endregion
                }
                    break;
                case Status.inAmusQueue:{
                    #region
                        if (waitingTimeInQueue > patience) {
                            AddContentment(-10);
                            currAmus.DeletePersonFromQueue(this);
                            status = Status.choosesAmus;
                        }
                        else waitingTimeInQueue++;
                    #endregion
                     }
                    break;
                case Status.inAmus:{
                        AddContentment(2);
                    }
                    break;
                case Status.choosesAmus: {
                    CurrAmusId = ChooseAmusement();
                    status = Status.onCrossroad;
                }
                    break;
                case Status.initialWalking:
                    {
                    #region
                    if (startingWalkingTime > 0)
                    {
                        startingWalkingTime--;

                        switch (currDirection)//doesnt matter that it is not "thread-safe", nobody else couldnt change x,y while initialWalkingTime
                        {
                            case Direction.E:
                                if (model.maps.IsPath(realX + 1, realY)) { realX++;
                                }
                                else currDirection=(Direction)rand.Next(1,5);
                                break;
                            case Direction.N:
                                if (model.maps.IsPath(realX , realY-1)) { realY--; }
                                else currDirection = (Direction)rand.Next(1, 5);
                                break;
                            case Direction.S:
                                if (model.maps.IsPath(realX , realY+1)) { realY++; }
                                else currDirection = (Direction)rand.Next(1, 5);
                                break;
                            case Direction.W:
                               if (model.maps.IsPath(realX -1, realY)) { realX--; }
                               else currDirection = (Direction)rand.Next(1, 5);
                                break;
                            default: currDirection = (Direction)rand.Next(1,5);
                                break;
                        }
                        if (rand.Next(1, 12) % 7 == 0) currDirection = (Direction)rand.Next(1, 4);
                    }
                    else status = Status.choosesAmus;
                    #endregion
                    }
                    break;
                case Status.disposing:// nothing
                    break;
                default:
                    break;
            }
        }
Beispiel #7
0
 /// <summary>
 /// Set to paths in pathMap calculated directions to the amusement. It should be used only for a particular update (for updating all amusements use UpdateDirectionToAmusement()).
 /// </summary>
 /// <param name="a">An Amusements item</param>
 private void UpdateDirectionToOnlyOneAmusement(Amusements a) {
     Queue<DirectionItem> queue = new Queue<DirectionItem>(internalWidthMap * internalHeightMap + 5);
     for (int i = 0; i < internalWidthMap; i++) {
         for (int j = 0; j < internalHeightMap; j++) {
             // here isnt a Lock, auxPathMap is not always actual -> lock here=nonsence
             if (pathMap[i][j] == null) auxPathMap[i][j] = null;
             else auxPathMap[i][j] = new DirectionItem((byte)i, (byte)j, (pathMap[i][j]).GetType());
         }
     }
     UpdateDirectionToAmusement(a, queue, auxPathMap);
 }
Beispiel #8
0
 public void MarkBackInService(Amusements a) {
     Interlocked.Increment(ref currBuildedItems[a.internTypeID]);
 }
Beispiel #9
0
        public void AddAmus(Amusements a) {
            amusRWLock.EnterWriteLock();

            try {
                foreach (var c in a.GetAllPoints()) amusementMap[c.x][c.y] = a;
            }
            finally {
                amusRWLock.ExitWriteLock();

            }

            lock (lastAddedAmusLock) {
                lastAddedAmus.Enqueue(a);
            }
            //todo:zamek s aktivnim cekanim - co dela nize uvedene??? Vypada to, ze vyhodi vyjimku - to je opravdu rychlejsi nez odplanovani vlakna???
            /*bool lockTaken = false;
            try {
                lastAddedAmusSLock.Enter(ref lockTaken);
                lastAddedAmus.Enqueue(a);
            }
            finally {
                if (lockTaken) lastAddedAmusSLock.Exit(false);
            } 
            */


        }
Beispiel #10
0
 public void RemoveAmus(Amusements a) {
     amusRWLock.EnterWriteLock();
     try {
         foreach (var c in a.GetAllPoints()) amusementMap[c.x][c.y] = null;
     }
     finally {
         amusRWLock.ExitWriteLock();
     }
 }
Beispiel #11
0
        /// <summary>
        /// Represents the current playing map, includes maps of paths and amusements, provides algorithms for navigation.
        /// </summary>
        /// <param name="width">The internal width of the map.</param>
        /// <param name="height">The internal height of the map.</param>
        /// <param name="m"></param>
        public Map(byte width, byte height, GameRecords m) {
            this.internalWidthMap = width;
            this.internalHeightMap = height;
            this.gameRec = m;


            //---initialize helpPath
            auxPathMap = new DirectionItem[width][];
            for (int i = 0; i < width; i++) {
                auxPathMap[i] = new DirectionItem[height];
            }

            //---initialize pathMap
            pathMap = new Path[width][];
            for (int i = 0; i < width; i++) pathMap[i] = new Path[height];

            //---initialize amusementMap
            amusementMap = new Amusements[width][];
            for (int i = 0; i < width; i++) amusementMap[i] = new Amusements[height];
        }
Beispiel #12
0
        public void Remove(Amusements a) {
            rwLock.EnterWriteLock();
            try {
                list.Remove(a);
                if (a is Restaurant) foodIds.Remove(a.Id);
            }
            finally {
                rwLock.ExitWriteLock();
            }

            freeId.Enqueue(a.Id);
        }
Beispiel #13
0
 public void Add(Amusements a) {
     /*if (a.id == list.Count) list.Add(a);
     else throw new MyDebugException("nesedi id a count v AmusementsList-Add()"); //todo: nemelo by se stavat, protoze by vzdy melo jit vytvorit jen jednu atrakci
    */
     try {
         rwLock.EnterWriteLock();
         list.Add(a);
         if (a is Restaurant) foodIds.Add(a.Id);
     }
     finally {
         rwLock.ExitWriteLock();
     }
 }
Beispiel #14
0
 public AmusementsList(int maxAmusCount, Gate gate) {
     this.gate = gate;
     list = new List<Amusements>();
     list.Add(gate);
     foodIds = new List<int>();
     this.maxAmusCount = maxAmusCount;
     freeId = new ConcurrentQueue<int>();
     for (int i = 1; i < maxAmusCount; i++) freeId.Enqueue(i);  //0 is not free, gate.id==0;          
 }
Beispiel #15
0
 public AmusementExitPath(GameRecords m, Coordinates c, Amusements a, bool tangible = true)
     : base(m, c, a, typeId: 2, tangible: tangible)
 {
     a.exit = this;
 }
Beispiel #16
0
        /// <summary>
        /// Set to paths in pathMap calculated directions to the amusement.
        /// </summary>
        /// <param name="a">an amusement to which directions are updated</param>
        /// <param name="queue">an empty instance of Queue</param>
        /// <param name="paths">a new auxilary array of builded paths</param>
        private void UpdateDirectionToAmusement(Amusements a, Queue<DirectionItem> queue, DirectionItem[][] paths) {
            DirectionItem item;
            AmusementPath entrance = a.entrance;
            if (entrance == null) return;
            if (!InitializeQueue(queue, entrance.coord, paths)) return;
            while (queue.Count != 0) {
                item = queue.Dequeue();
                ProcessQueueItem(item, queue, paths);
            }
            // ---set calculated directions
            pathRWLock.EnterReadLock();
            try {
                for (int i = 0; i < internalWidthMap; i++) {
                    for (int j = 0; j < internalHeightMap; j++) {
                        if ((item = paths[i][j]) != null && pathMap[i][j] != null) {
                            pathMap[i][j].signpostAmus[a.Id] = item.dir;
                        }
                    }
                }
            }
            finally {
                pathRWLock.ExitReadLock();
            }


        }
Beispiel #17
0
 public void MarkOutOfService(Amusements a) {
     Interlocked.Decrement(ref currBuildedItems[a.internTypeID]);
 }