public Round StartRoundOrGetExisting(int userId)
        {
            GameEntity  gameEntity  = StartNewGameOrGetExisting(userId);
            RoundEntity roundEntity = _roundRepository.GetCurrentOpenRound(gameEntity.Id);

            if (null != roundEntity)
            {
                // Unfinished round
                return(RoundEntityFactory.Create(roundEntity, ROUNDS_PER_GAME, RoundsPlayedInGame(gameEntity.Id)));
            }
            roundEntity = RoundEntityFactory.Create(gameEntity.Id);

            // Determine the correct one
            var randomImages = _imageRepository.GetRandomImages(IMAGES_PER_ROUND, _userRepository.Get(userId).FullName);
            int indexOfCorrectImageInList = (new Random()).Next(IMAGES_PER_ROUND);
            var correctImage = randomImages.ElementAt(indexOfCorrectImageInList);

            Round round = RoundFactory.Create(new List <Image>(), RoundsPlayedInGame(gameEntity.Id), ROUNDS_PER_GAME, correctImage.Name);

            roundEntity.CorrectImageId = correctImage.Id;
            _roundRepository.Create(roundEntity);

            foreach (ImageEntity imageEntity in randomImages)
            {
                ImageInRoundEntity imageInRoundEntity = ImageInRoundEntityFactory.Create(imageEntity.Id, roundEntity.Id);
                _imageInRoundRepository.Create(imageInRoundEntity);
                round.Images.Add(ImageFactory.Create(imageEntity.Url, imageEntity.Id));
            }

            return(round);
        }
Ejemplo n.º 2
0
        public async Task StartAsync()
        {
            for (int i = 1; i <= Settings.MaxRounds; i++)
            {
                Round = RoundFactory.Create(i);
                OnRoundStarting();
                await Round.StartAsync();

                UpdateScores();
                OnRoundFinished();
                await WaitForNextRoundAsync();
            }
        }
Ejemplo n.º 3
0
 public override void SetUp()
 {
     base.SetUp();
     Round = RoundFactory.Create(1);
 }
Ejemplo n.º 4
0
        public static void Demo()
        {
            List <Figure> figures = new List <Figure>();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Console graphical editor.");
                Console.WriteLine("Select option.");
                Console.WriteLine("1. Add Line.");
                Console.WriteLine("2. Add Circle.");
                Console.WriteLine("3. Add Rectangle.");
                Console.WriteLine("4. Add Round.");
                Console.WriteLine("5. Add Ring.");
                Console.WriteLine("6. Add Ring (aggregation).");
                Console.WriteLine("7. Show figures.");
                Console.WriteLine("0. Exit.");

                int select;
                while (!int.TryParse(Console.ReadLine(), out select))
                {
                    Console.WriteLine("Wrong input. Try again.");
                }

                switch (select)
                {
                case 1:
                    figures.Add(LineFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Line added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 2:
                    figures.Add(CircleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Circle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 3:
                    figures.Add(RectangleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Rectangle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 4:
                    figures.Add(RoundFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Round added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 5:
                    figures.Add(RingFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 6:
                    figures.Add(RingAggregationFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring (aggregation) added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 7:
                    Console.Clear();
                    foreach (Figure figure in figures)
                    {
                        figure.ShowInfo();
                        Console.WriteLine();
                    }
                    Console.ReadLine();
                    break;

                case 0:
                    Console.WriteLine("Good luck!");
                    Console.ReadLine();
                    return;

                default:
                    Console.WriteLine("Wrong option. Try again.");
                    break;
                }
            }
        }