예제 #1
0
 public PersonUserControl(Person p, Control parent)
 {
     InitializeComponent();
     this.p = p;
        // this.Visible = true;
     this.Parent = parent;
     parent.Controls.SetChildIndex(this,0);
 }
예제 #2
0
파일: GameItems.cs 프로젝트: jamafyna/park
 public bool TryQueuesPerson(Person p)
 {
     queueAddRWLock.EnterReadLock();
     try {
         if (this.status == Status.outOfService || isRunningOut) return false;
         queue.Enqueue(p);
         return true;
     }
     finally { queueAddRWLock.ExitReadLock(); }
 }
예제 #3
0
파일: GameItems.cs 프로젝트: jamafyna/park
        public void DeletePersonFromQueue(Person p)
        {
            queueAddRWLock.EnterWriteLock();
            try {
                lock (queueDeleteLock) {
                    ConcurrentQueue<Person> newQueue = new ConcurrentQueue<Person>();
                    Person q;

                    while (!queue.IsEmpty) {
                        if (queue.TryDequeue(out q) && q != p) newQueue.Enqueue(q);
                    }
                    queue = newQueue;
                }
            }
            finally { queueAddRWLock.ExitWriteLock(); }
        }
예제 #4
0
 private void DrawPerson(Graphics gr, Person p)
 {
     sbr.Color = p.color;
     Point point = p.GetRealCoordinatesUnsynchronized();
     Size size = p.GetRealSize();
     gr.FillRectangle(sbr, new Rectangle(point, size));
     sbr.Color = Color.LightSalmon;
     gr.FillEllipse(sbr, point.X, point.Y - size.Width, size.Width, size.Width);
 }
예제 #5
0
파일: Model.cs 프로젝트: jamafyna/park
        /// <summary>
        /// a method which should be called only from the class Person
        /// </summary>
        /// <param name="p">the person which will be removed</param>
        public void Remove(Person p) {
            lock (peopleLock) {
                int internId = internChangablePeopleId[p.id];
                internChangablePeopleId[p.id] = -1;

#if (DEBUG)
                if (internId == -1) throw new MyDebugException("PeopleList.Remove - id=-1, tj. p nebyla nejspis v seznamu");
                if (people[internId] != p) throw new MyDebugException("PeopleList.Remove - person[id]!=p: p.id: " + p.id.ToString() + ", p: " + p.ToString());

#else
                if (internId == -1) return;
#endif
                if (internId == currPeopleCount - 1) { // p is the last item
                    people[internId] = null; //due to GC
                    currPeopleCount--;
                }
                else {
                    Person q;
                    q = people[currPeopleCount - 1]; // last item
                    people[internId] = q;
                    internChangablePeopleId[q.id] = internId;
                    people[currPeopleCount - 1] = null; // due to GC
                    currPeopleCount--;
                }
            }





        }
예제 #6
0
파일: Model.cs 프로젝트: jamafyna/park
        public void Add(Person p)//ts
        {

            lock (peopleLock) {
                if (currPeopleCount == people.Length)
#if (DEBUG) 
                    throw new MyDebugException("More people than a determined value");
#else
                    return;
#endif
                if (internChangablePeopleId[p.id] != -1) { // very unlikely situation - a person p survived more people then maxUniquePeople; and must be locked - more it is called Remove(p) and Add(q) where p.id=q.id in the same time

#if (DEBUG)
                    throw new MyDebugException("PersList.Add - Is the total number of visitors really bigger then chosen const?");
#else
                    Remove(p);
                    p.DestructWithoutListRemove(); // only p.Destruct cannot be called, it could remove from this new added person
#endif
                }

                // lock is necessary (adding to the array must be done before or in the same time increment countOfPeople

                //  int internId = Interlocked.Increment(ref currPeopleCount); zbytecne, kdyz mam zamceno
                int internId = currPeopleCount++; // e.d. for sure: + 1 is done after setting
                people[internId] = p;
                internChangablePeopleId[p.id] = internId;
            }

        }
예제 #7
0
파일: Amusements.cs 프로젝트: jamafyna/park
        public override void Action()
        {
            switch (status) {

                case Status.running: {
                        #region
                        Person p;
                        // deleting people from the park
                        while (queue.TryDequeue(out p))
                            p.Destruct();
                        // a new person can be created
                        int a = (exit.coord.x + 1) * MainForm.sizeOfSquare;
                        int b = exit.coord.y * MainForm.sizeOfSquare;
                        if (!model.maps.IsPath(a, b)) break;
                        if (peopleGeneration.ShouldCreateNewPerson()) {
                            p = new Person(model, a + 1, b + MainForm.sizeOfSquare / 2);
                            model.MoneyAdd(this.entranceFee);
                        }
                        model.MoneyAdd(-workingPrize);
                        #endregion
                    }
                    break;
                case Status.outOfService: //nothing
                    break;
                case Status.runningOut: {
                        // deleting people from the park
                    Person p;
                    while (queue.TryDequeue(out p)) p.Destruct();
                    if (model.CurrPeopleCount == 0) {
                        status = Status.outOfService;
                        model.parkClosed = true;
                    }
                    model.MoneyAdd(-workingPrize);
                }
                    break;
                case Status.disposing: //nothing
                    break;
                default: status = Status.running;
                    break;
            }
        }