コード例 #1
0
ファイル: PersonUserControl.cs プロジェクト: jamafyna/park
 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
ファイル: mapCustomControl.cs プロジェクト: jamafyna/park
 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;
            }
        }