Esempio n. 1
0
        private static void InventoryMovement(BaseClassPerson fromPerson, BaseClassPerson toPerson)
        {
            if (fromPerson.Inventory != null && fromPerson.Inventory.Count > 0)
            {
                toPerson.Inventory = fromPerson.Inventory.ToList();
                fromPerson.Inventory.Clear();

                if (fromPerson.Name == 'C' && toPerson.Name == 'T')
                {
                    PrintMessage(0, 27, "Good stolen from citizen by thief");
                }
                if (fromPerson.Name is 'T' && toPerson.Name is 'P')
                {
                    PrintMessage(0, 27, "Thief cought by police and goods siezed.");
                }

                Thread.Sleep(1000);
                PrintMessage(0, 27, new string(' ', 100));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// inventory transfer - actions to be performed on meeting person.
        /// </summary>
        /// <param name="movingPerson"></param>
        private static void ActionOnPersonMeeting(BaseClassPerson movingPerson)
        {
            IEnumerable <BaseClassPerson> people = from p in Persons
                                                   where p.XPos == movingPerson.XPos && p.YPos == movingPerson.YPos && p.Name != movingPerson.Name
                                                   select p;

            if (people != null && people.Count() > 0)
            {
                var newCharacter = people.First();

                if (newCharacter.Name == 'C')
                {
                    switch (movingPerson.Name)
                    {
                    case 'T':
                        InventoryMovement(newCharacter, movingPerson);

                        int ctz = (from c in Persons
                                   where c.Name == 'C' && c.Inventory.Count == 0
                                   select c).Count();

                        PrintMessage(0, 29, $"Total number of citizens robbed: {ctz}");
                        break;
                    // invetory of c to t

                    case 'P':
                    //nothing

                    default:
                        break;
                    }
                }

                if (newCharacter.Name == 'P')
                {
                    switch (movingPerson.Name)
                    {
                    case 'T':
                        InventoryMovement(movingPerson, newCharacter);
                        //from t to p
                        ThievesCaught.Add(movingPerson);
                        PrintMessage(0, 28, $"Total number of thieves arrested: {ThievesCaught.Count}");
                        //Persons.Remove(movingPerson);
                        break;

                    case 'C':
                    //nothing

                    default:
                        break;
                    }
                }

                if (newCharacter.Name == 'T')
                {
                    switch (movingPerson.Name)
                    {
                    case 'C':
                        InventoryMovement(movingPerson, newCharacter);
                        //inventory of c to t
                        break;

                    case 'P':
                        InventoryMovement(newCharacter, movingPerson);
                        //inventory of t to p
                        break;

                    default:
                        break;
                    }
                }
            }
        }