public IHttpActionResult Put(int id, RouteCard routeCard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != routeCard.id_card)
            {
                return(BadRequest());
            }

            db.Entry(routeCard).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RouteCardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public static bool ValidateBuildingTunnelAction(RouteCard routeCard, List <RouteCard> tableRouteCards, RoleType roleType)
        {
            //Получаем координаты, куда карточку из руки хотят положить
            int x = routeCard.Coordinates.Coordinate_X;
            int y = routeCard.Coordinates.Coordinate_Y;

            //Определяем какие карточки находятся вокруг
            RouteCard topCardFromTable    = tableRouteCards.FirstOrDefault(topCard => topCard.Coordinates.Coordinate_X == x && topCard.Coordinates.Coordinate_Y == y - 1);
            RouteCard bottomCardFromTable = tableRouteCards.FirstOrDefault(bottomCard => bottomCard.Coordinates.Coordinate_X == x && bottomCard.Coordinates.Coordinate_Y == y + 1);
            RouteCard leftCardFromTable   = tableRouteCards.FirstOrDefault(leftCard => leftCard.Coordinates.Coordinate_X == x - 1 && leftCard.Coordinates.Coordinate_Y == y);
            RouteCard rightCardFromTable  = tableRouteCards.FirstOrDefault(rightCard => rightCard.Coordinates.Coordinate_X == x + 1 && rightCard.Coordinates.Coordinate_Y == y);

            //Создаем переменные валидаторы и проверяем каждое соединение
            bool validateTopJoining    = topCardFromTable == null || (routeCard.JoiningTop == topCardFromTable.JoiningBottom);
            bool validateBottomJoining = bottomCardFromTable == null || (routeCard.JoiningBottom == bottomCardFromTable.JoiningTop);
            bool validateRightJoining  = rightCardFromTable == null || (routeCard.JoiningRight == rightCardFromTable.JoiningLeft);
            bool validateLeftJoining   = leftCardFromTable == null || (routeCard.JoiningLeft == leftCardFromTable.JoiningRight);

            Logger.Write($"Validating route: top={validateTopJoining}, bottom={validateBottomJoining}, left={validateLeftJoining}, right={validateRightJoining}");

            //Вызываем метод, проверяющий возможность прохождения тунеля на данный момент
            bool canPassTunnel = IsConnectionOpen(routeCard, roleType);// ValidateCanPassTunnel(routeCard, tableRouteCards, new RouteCard(0, 2));

            //Итоговая проверка на возможность построения карточки с руки
            return(validateTopJoining && validateBottomJoining && validateRightJoining && validateLeftJoining && canPassTunnel);
            //return (canPassTunnel);
        }
Esempio n. 3
0
 public static void AddCard(RouteCard currentCard, RoleType roleType = RoleType.None)
 {
     OpenedCards.Add(currentCard);
     if (currentCard.IsTroll)
     {
         UseToken(currentCard, roleType);
     }
 }
Esempio n. 4
0
        public void RouteCard_ToString()
        {
            RouteCard routeCard;
            string    s;

            routeCard = new RouteCard("Москва", "Минеральные воды");
            s         = routeCard.ToString();

            Assert.AreEqual(s, "Москва → Минеральные воды");
        }
Esempio n. 5
0
 private void UseKey(ActionCard actionCard, RouteCard routeCard)
 {
     _client.SendMessage(new KeyMessage
     {
         CardId      = actionCard.Id,
         Coordinates = routeCard.Coordinates,
         SenderId    = CurrentPlayer.Id,
         RoleType    = CurrentPlayer.Role.Role
     });
 }
Esempio n. 6
0
 private void DestroyConnection(ActionCard actionCard, RouteCard connectionToDestroy)
 {
     _client.SendMessage(new DestroyMessage
     {
         CardId      = actionCard.Id,
         Coordinates = connectionToDestroy.Coordinates,
         SenderId    = CurrentPlayer.Id,
         RoleType    = CurrentPlayer.Role.Role
     });
 }
        public IHttpActionResult Get(int id)
        {
            RouteCard routeCard = db.RouteCards.Find(id);

            if (routeCard == null)
            {
                return(NotFound());
            }

            return(Ok(routeCard));
        }
        public IHttpActionResult Post(RouteCard routeCard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RouteCards.Add(routeCard);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = routeCard.id_card }, routeCard));
        }
Esempio n. 9
0
        private void BuildTunnel(RouteCard mapItem)
        {
            var routeCard = SelectedCard as RouteCard;

            routeCard.Coordinates = new Coordinates(mapItem.Coordinates.Coordinate_Y, mapItem.Coordinates.Coordinate_X);
            _client.SendMessage(new BuildMessage
            {
                Coordinates = routeCard.Coordinates,
                SenderId    = CurrentPlayer.Id,
                CardId      = SelectedCard.Id,
                RouteCard   = routeCard,
                RoleType    = CurrentPlayer.Role.Role
            });
        }
Esempio n. 10
0
        public IHttpActionResult Delete(int id)
        {
            RouteCard routeCard = db.RouteCards.Find(id);

            if (routeCard == null)
            {
                return(NotFound());
            }

            db.RouteCards.Remove(routeCard);
            db.SaveChanges();

            return(Ok(routeCard));
        }
Esempio n. 11
0
        /// <summary>
        /// Spawn a new card prefab at the specified location.
        /// </summary>
        public GameObject SpawnCard <TCard>(TCard card, CardSpawnLocation location)
            where TCard : ICard
        {
            GameObject parent        = this.CardSpawnParents[location];
            GameObject newCard       = Instantiate(UICardPrefab, parent.transform);
            UICardView cardComponent = newCard.GetComponent <UICardView>();

            newCard.GetComponent <AnimationEndedTrigger>().SetUIManager(this);

            PlayerCard playerCard = card as PlayerCard;

            if (playerCard != null)
            {
                cardComponent.Setup(playerCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnPlayerCardClicked;
                }
                return(newCard);
            }

            RouteCard routeCard = card as RouteCard;

            if (routeCard != null)
            {
                cardComponent.Setup(routeCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnRouteCardClicked;
                }
                return(newCard);
            }

            PursuitCard pursuitCard = card as PursuitCard;

            if (pursuitCard != null)
            {
                cardComponent.Setup(pursuitCard);
                cardComponent.OnClick += OnCardClicked;
                if (location != CardSpawnLocation.CardPicker)
                {
                    cardComponent.OnClick += OnPursuitCardClicked;
                }
                return(newCard);
            }

            throw new ArgumentException($"Don't know how to set up a UI card object for a {card.GetType().FullName}.");
        }
Esempio n. 12
0
        private static void UseToken(RouteCard card, RoleType roleType)
        {
            var token = new Token
            {
                Card = card,
                Role = roleType
            };

            Tokens.Add(token);
            card.IsTaken = true;
            card.Token   = token;

            Logger.Write($"Token for {roleType} was used. Remaining tokens: {8 - Tokens.Count}");
        }
Esempio n. 13
0
        private void ExecuteRotateGoldCommand(object o)
        {
            RouteCard card = (RouteCard)o;

            card.Rotate();
            // we should update collection view from another thread
            // https://stackoverflow.com/a/18336392/2219089
            Application.Current.Dispatcher.Invoke(delegate
            {
                Map[card.Coordinates.Coordinate_Y][card.Coordinates.Coordinate_X] = card;
            });
            Map = new ObservableCollection <ObservableCollection <RouteCard> >(Map);
            OnPropertyChanged(nameof(Map));
        }
Esempio n. 14
0
        private static bool IsConnectionOpen(RouteCard routeCard, RoleType roleType)
        {
            // bitwise operator for comparing role with connection
            bool validateTopJoining = routeCard.NeighbourTop != null &&
                                      (((int)roleType & (int)routeCard.NeighbourTop.ConnectionBottom) != 0);
            bool validateBottomJoining = routeCard.NeighbourBottom != null &&
                                         (((int)roleType & (int)routeCard.NeighbourBottom.ConnectionTop) != 0);
            bool validateRightJoining = routeCard.NeighbourRight != null &&
                                        (((int)roleType & (int)routeCard.NeighbourRight.ConnectionLeft) != 0);
            bool validateLeftJoining = routeCard.NeighbourLeft != null &&
                                       (((int)roleType & (int)routeCard.NeighbourLeft.ConnectionRight) != 0);

            Logger.Write($"Validating connection is open: " +
                         $"top={validateTopJoining}, bottom={validateBottomJoining}, left={validateLeftJoining}, right={validateRightJoining}");

            return(validateTopJoining || validateBottomJoining || validateRightJoining || validateLeftJoining);
        }
Esempio n. 15
0
        public List <RouteCard> MakeRoute(List <RouteCard> SrcCardsList)
        {
            List <RouteCard> result = null;

            if (SrcCardsList != null)
            {
                // исходная карточка маршрута
                var currentCard = SrcCardsList
                                  .Where(c => !SrcCardsList.Any(cn => c.DepPlace == cn.DestPlace))
                                  .FirstOrDefault();

                if (currentCard != null)
                {
                    // преобразуем список в словарь, предварительно задав для него требуемую емкость
                    var dict = new Dictionary <string, string>(SrcCardsList.Count);

                    foreach (var card in SrcCardsList)
                    {
                        dict.Add(card.DepPlace, card.DestPlace);
                    }

                    // помещаем исходную карточку в результирующий список
                    result = new List <RouteCard> {
                        currentCard
                    };

                    // формируем итоговый список, перебирая данные словаря
                    for (var i = 0; i < SrcCardsList.Count - 1; i++)
                    {
                        currentCard = new RouteCard
                        {
                            DepPlace  = currentCard.DestPlace,
                            DestPlace = dict[currentCard.DestPlace]
                        };

                        result.Add(currentCard);
                    }
                }
                else
                {
                    throw new ArgumentException("No primary departure place found in route cards list");
                }
            }

            return(result);
        }
Esempio n. 16
0
        private static void TestInvertedOrder(int count)
        {
            var arr = new RouteCard[count];

            for (int i = count; i > 0; i--)
            {
                arr[i - 1] = new RouteCard {
                    From = i.ToString(), To = (i - 1).ToString()
                };
            }

            var result = SortingMethods.Sort(arr);

            for (int i = count; i > 0; i--)
            {
                Assert.AreEqual(arr[count - i], result[i - 1]);
            }
        }
Esempio n. 17
0
        private static void TestDirectOrder(int count)
        {
            var arr = new RouteCard[count];

            for (int i = 0; i < count; i++)
            {
                arr[i] = new RouteCard {
                    From = i.ToString(), To = (i + 1).ToString()
                };
            }

            var result = SortingMethods.Sort(arr);

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(arr[i], result[i]);
            }
        }
Esempio n. 18
0
        public static void SetKey(RouteCard card)
        {
            if (card.PassabilityHorizontal != ConnectionType.None)
            {
                card.PassabilityHorizontal = ConnectionType.Both;
            }
            if (card.PassabilityLeft2Bottom != ConnectionType.None)
            {
                card.PassabilityLeft2Bottom = ConnectionType.Both;
            }
            if (card.PassabilityLeft2Top != ConnectionType.None)
            {
                card.PassabilityLeft2Top = ConnectionType.Both;
            }
            if (card.PassabilityRight2Bottom != ConnectionType.None)
            {
                card.PassabilityRight2Bottom = ConnectionType.Both;
            }
            if (card.PassabilityRight2Top != ConnectionType.None)
            {
                card.PassabilityRight2Top = ConnectionType.Both;
            }
            if (card.PassabilityVertical != ConnectionType.None)
            {
                card.PassabilityVertical = ConnectionType.Both;
            }

            if (card.ConnectionBottom != ConnectionType.None)
            {
                card.ConnectionBottom = ConnectionType.Both;
            }
            if (card.ConnectionLeft != ConnectionType.None)
            {
                card.ConnectionLeft = ConnectionType.Both;
            }
            if (card.ConnectionRight != ConnectionType.None)
            {
                card.ConnectionRight = ConnectionType.Both;
            }
            if (card.ConnectionTop != ConnectionType.None)
            {
                card.ConnectionTop = ConnectionType.Both;
            }
        }
Esempio n. 19
0
        public static bool CheckForGold(RouteCard routeCard, List <RouteCard> tableRouteCards, RoleType roleType)
        {
            //Получаем координаты, куда карточку из руки хотят положить
            int x = routeCard.Coordinates.Coordinate_X;
            int y = routeCard.Coordinates.Coordinate_Y;

            //Определяем какие карточки находятся вокруг
            RouteCard topCardFromTable    = tableRouteCards.FirstOrDefault(topCard => topCard.Coordinates.Coordinate_X == x && topCard.Coordinates.Coordinate_Y == y - 1);
            RouteCard bottomCardFromTable = tableRouteCards.FirstOrDefault(bottomCard => bottomCard.Coordinates.Coordinate_X == x && bottomCard.Coordinates.Coordinate_Y == y + 1);
            RouteCard leftCardFromTable   = tableRouteCards.FirstOrDefault(leftCard => leftCard.Coordinates.Coordinate_X == x - 1 && leftCard.Coordinates.Coordinate_Y == y);
            RouteCard rightCardFromTable  = tableRouteCards.FirstOrDefault(rightCard => rightCard.Coordinates.Coordinate_X == x + 1 && rightCard.Coordinates.Coordinate_Y == y);

            //Создаем переменные валидаторы и проверяем каждое соединение
            bool validateTopJoining    = topCardFromTable == null || (routeCard.JoiningTop == topCardFromTable.JoiningBottom);
            bool validateBottomJoining = bottomCardFromTable == null || (routeCard.JoiningBottom == bottomCardFromTable.JoiningTop);
            bool validateRightJoining  = rightCardFromTable == null || (routeCard.JoiningRight == rightCardFromTable.JoiningLeft);
            bool validateLeftJoining   = leftCardFromTable == null || (routeCard.JoiningLeft == leftCardFromTable.JoiningRight);

            return(validateTopJoining && validateBottomJoining && validateRightJoining && validateLeftJoining);
        }
Esempio n. 20
0
        private static void TestRandomOrder(int count)
        {
            var arr = new RouteCard[count];

            for (int i = 0; i < count; i++)
            {
                arr[i] = new RouteCard {
                    From = i.ToString(), To = (i + 1).ToString()
                };
            }
            //Для того, чтобы не нарушать условие воспроизводимости теста, зафиксируем зерно рандома
            var rand = new Random(42);

            arr = arr.OrderBy(x => rand.Next()).ToArray();

            var result = SortingMethods.Sort(arr);

            //Требуемый порядок нам не известен, поэтому проверим соответствует ли массив условиям сортировки
            for (int i = 0; i < count - 1; i++)
            {
                Assert.AreEqual(result[i].To, result[i + 1].From);
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (AutosuggestionsTableView != null)
            {
                AutosuggestionsTableView.Dispose();
                AutosuggestionsTableView = null;
            }

            if (ButtonBottomConstraint != null)
            {
                ButtonBottomConstraint.Dispose();
                ButtonBottomConstraint = null;
            }

            if (ContactCardView != null)
            {
                ContactCardView.Dispose();
                ContactCardView = null;
            }

            if (CurrentLocationButton != null)
            {
                CurrentLocationButton.Dispose();
                CurrentLocationButton = null;
            }

            if (DirectionsButton != null)
            {
                DirectionsButton.Dispose();
                DirectionsButton = null;
            }

            if (FloorPickerBottomConstraint != null)
            {
                FloorPickerBottomConstraint.Dispose();
                FloorPickerBottomConstraint = null;
            }

            if (FloorsTableView != null)
            {
                FloorsTableView.Dispose();
                FloorsTableView = null;
            }

            if (HeightConstraint != null)
            {
                HeightConstraint.Dispose();
                HeightConstraint = null;
            }

            if (HomeButton != null)
            {
                HomeButton.Dispose();
                HomeButton = null;
            }

            if (LocationSearchBar != null)
            {
                LocationSearchBar.Dispose();
                LocationSearchBar = null;
            }

            if (MainLabel != null)
            {
                MainLabel.Dispose();
                MainLabel = null;
            }

            if (MapView != null)
            {
                MapView.Dispose();
                MapView = null;
            }

            if (RouteCard != null)
            {
                RouteCard.Dispose();
                RouteCard = null;
            }

            if (RouteTableView != null)
            {
                RouteTableView.Dispose();
                RouteTableView = null;
            }

            if (SearchToolbar != null)
            {
                SearchToolbar.Dispose();
                SearchToolbar = null;
            }

            if (SecondaryLabel != null)
            {
                SecondaryLabel.Dispose();
                SecondaryLabel = null;
            }

            if (SettingsButton != null)
            {
                SettingsButton.Dispose();
                SettingsButton = null;
            }

            if (WalkTimeLabel != null)
            {
                WalkTimeLabel.Dispose();
                WalkTimeLabel = null;
            }
        }