public void StartGame()
        {
            drawService.ProjectionClear();
            drawService.PointsHistoryBoxClear();

            detectionService.PrepareCamsAndTryCapture();
            detectionService.RunDetection();

            var selectedGameType = Converter.NewGameControlsToGameType(mainWindow.NewGameControls);
            var legs             = Converter.ComboBoxSelectedContentToInt(mainWindow.NewGameLegsComboBox);
            var sets             = Converter.ComboBoxSelectedContentToInt(mainWindow.NewGameSetsComboBox);
            var legPoints        = Converter.ComboBoxSelectedContentToString(mainWindow.NewGamePointsComboBox);

            GameType = selectedGameType;

            var selectedPlayer1 = mainWindow.NewGamePlayer1ComboBox.SelectedItem as Player;
            var selectedPlayer2 = mainWindow.NewGamePlayer2ComboBox.SelectedItem as Player;

            var players = new List <Player>();

            if (selectedPlayer1 != null)
            {
                players.Add(selectedPlayer1);
            }

            if (selectedPlayer2 != null)
            {
                players.Add(selectedPlayer2);
            }

            Game = new Game(selectedGameType);

            dbService.GameSaveNew(Game, players);

            switch (selectedGameType)
            {
            case GameType.FreeThrowsSingle:
                switch (legPoints)
                {
                case "Free":
                    GameProcessor = new FreeThrowsSingleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Free throws");
                    break;

                case "301":
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 301", 301);
                    break;

                case "501":
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 501", 501);
                    break;

                case "701":
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 701", 701);
                    break;

                case "1001":
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 1001", 1001);
                    break;
                }

                break;

            case GameType.FreeThrowsDouble:
                switch (legPoints)
                {
                case "Free":
                    GameProcessor = new FreeThrowsDoubleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Free throws");
                    break;

                case "301":
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 301", 301);
                    break;

                case "501":
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 501", 501);
                    break;

                case "701":
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 701", 701);
                    break;

                case "1001":
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, "Write off 1001", 1001);
                    break;
                }

                break;

            case GameType.Classic:
                switch (legPoints)
                {
                case "301":
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 301, legs, sets);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, $"First to {sets}", 301);
                    break;

                case "501":
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 501, legs, sets);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, $"First to {sets}", 501);
                    break;

                case "701":
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 701, legs, sets);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, $"First to {sets}", 701);
                    break;

                case "1001":
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 1001, legs, sets);
                    scoreBoardService.OpenScoreBoard(selectedGameType, players, $"First to {sets}", 1001);
                    break;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Task.Run(() =>
            {
                IsGameRun = true;
                detectionService.OnThrowDetected += OnAnotherThrow;
                detectionService.OnStatusChanged += OnDetectionServiceStatusChanged;
                GameProcessor.OnMatchEnd         += OnMatchEnd;
                while (IsGameRun)
                {
                }

                detectionService.OnThrowDetected -= OnAnotherThrow;
                detectionService.OnStatusChanged -= OnDetectionServiceStatusChanged;
                GameProcessor.OnMatchEnd         -= OnMatchEnd;
            });
        }
        public void StartGame(List <Player> players,
                              GameType gameType,
                              GamePoints gamePoints,
                              int gameSets,
                              int gameLegs)
        {
            Game = new Domain.Game(gameType, players, gameLegs, gameSets, gamePoints);

            scoreBoardService.OpenScoreBoard(Game);

            switch (gameType) // todo ugly-spaghetti
            {
            case GameType.FreeThrowsSingle:
                switch (gamePoints)
                {
                case GamePoints.Free:
                    GameProcessor = new FreeThrowsSingleFreePointsProcessor(Game, scoreBoardService);
                    break;

                case GamePoints._301:
                case GamePoints._501:
                case GamePoints._701:
                case GamePoints._1001:
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, scoreBoardService);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(gamePoints), gamePoints, null);
                }

                break;

            case GameType.FreeThrowsDouble:
                switch (gamePoints)
                {
                case GamePoints.Free:
                    GameProcessor = new FreeThrowsDoubleFreePointsProcessor(Game, scoreBoardService);
                    break;

                case GamePoints._301:
                case GamePoints._501:
                case GamePoints._701:
                case GamePoints._1001:
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, scoreBoardService);
                    break;
                }

                break;

            case GameType.Classic:
                GameProcessor = new ClassicDoubleProcessor(Game, scoreBoardService);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            detectionService.OnThrowDetected             += OnAnotherThrow;
            detectionService.OnStatusChanged             += OnDetectionServiceStatusChanged;
            GameProcessor.OnMatchEnd                     += OnMatchEnd;
            scoreBoardService.OnUndoThrowButtonPressed   += OnThrowUndo;
            scoreBoardService.OnManualThrowButtonPressed += OnManualThrow;
        }
Exemplo n.º 3
0
        public void StartGame()
        {
            drawService.ProjectionClear();
            drawService.PointsHistoryBoxClear();

            detectionService.PrepareAndTryCapture();
            detectionService.RunDetection();

            var selectedGameTypeUi = Converter.NewGameControlsToGameTypeUi(mainWindow.NewGameControls);
            var selectedGameType   = Converter.NewGameControlsToGameTypeGameService(mainWindow.NewGameControls);

            GameType = selectedGameType;

            var selectedPlayer1 = mainWindow.NewGamePlayer1ComboBox.SelectedItem as Player;
            var selectedPlayer2 = mainWindow.NewGamePlayer2ComboBox.SelectedItem as Player;

            var players = new List <Player>();

            if (selectedPlayer1 != null)
            {
                players.Add(selectedPlayer1);
            }

            if (selectedPlayer2 != null)
            {
                players.Add(selectedPlayer2);
            }

            Game = new Game(selectedGameType);

            dbService.GameSaveNew(Game, players);

            switch (selectedGameType)
            {
            case GameType.FreeThrowsSingleFreePoints:
                GameProcessor = new FreeThrowsSingleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Free throws");
                break;

            case GameType.FreeThrowsSingle301Points:
                GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 301", 301);
                break;

            case GameType.FreeThrowsSingle501Points:
                GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 501", 501);
                break;

            case GameType.FreeThrowsSingle701Points:
                GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 701", 701);
                break;

            case GameType.FreeThrowsSingle1001Points:
                GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 1001", 1001);
                break;

            case GameType.FreeThrowsDoubleFreePoints:
                GameProcessor = new FreeThrowsDoubleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Free throws");
                break;

            case GameType.FreeThrowsDouble301Points:
                GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 301", 301);
                break;

            case GameType.FreeThrowsDouble501Points:
                GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 501", 501);
                break;

            case GameType.FreeThrowsDouble701Points:
                GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 701", 701);
                break;

            case GameType.FreeThrowsDouble1001Points:
                GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                scoreBoardService.OpenScoreBoard(selectedGameTypeUi, players, "Write off 1001", 1001);
                break;

            case GameType.Classic301Points:
                break;

            case GameType.Classic501Points:
                break;

            case GameType.Classic701Points:
                break;

            case GameType.Classic1001Points:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Task.Run(() =>
            {
                IsGameRun = true;
                detectionService.OnThrowDetected += OnAnotherThrow;
                detectionService.OnStatusChanged += OnDetectionServiceStatusChanged;
                while (IsGameRun)
                {
                }

                detectionService.OnThrowDetected -= OnAnotherThrow;
                detectionService.OnStatusChanged -= OnDetectionServiceStatusChanged;
            });
        }
Exemplo n.º 4
0
        public void StartGame(Player player1,
                              Player player2,
                              GameType gameType,
                              GamePoints gamePoints,
                              int gameSets,
                              int gameLegs)
        {
            var players = new List <Player>();

            players.AddIfNotNull(player1);
            players.AddIfNotNull(player2);

            Game = new Domain.Game(gameType);

            dbService.GameSaveNew(Game, players);

            switch (gameType)
            {
            case GameType.FreeThrowsSingle:
                switch (gamePoints)
                {
                case GamePoints.Free:
                    GameProcessor = new FreeThrowsSingleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Free throws");
                    break;

                case GamePoints._301:
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 301", 301);
                    break;

                case GamePoints._501:
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 501", 501);
                    break;

                case GamePoints._701:
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 701", 701);
                    break;

                case GamePoints._1001:
                    GameProcessor = new FreeThrowsSingleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 1001", 1001);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(gamePoints), gamePoints, null);
                }

                break;

            case GameType.FreeThrowsDouble:
                switch (gamePoints)
                {
                case GamePoints.Free:
                    GameProcessor = new FreeThrowsDoubleFreePointsProcessor(Game, players, dbService, scoreBoardService);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Free throws");
                    break;

                case GamePoints._301:
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 301);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 301", 301);
                    break;

                case GamePoints._501:
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 501);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 501", 501);
                    break;

                case GamePoints._701:
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 701);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 701", 701);
                    break;

                case GamePoints._1001:
                    GameProcessor = new FreeThrowsDoubleWriteOffPointsProcessor(Game, players, dbService, scoreBoardService, 1001);
                    scoreBoardService.OpenScoreBoard(gameType, players, "Write off 1001", 1001);
                    break;
                }

                break;

            case GameType.Classic:
                switch (gamePoints)
                {
                case GamePoints._301:
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 301, gameLegs, gameSets);
                    scoreBoardService.OpenScoreBoard(gameType, players, $"First to {gameSets}", 301);
                    break;

                case GamePoints._501:
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 501, gameLegs, gameSets);
                    scoreBoardService.OpenScoreBoard(gameType, players, $"First to {gameSets}", 501);
                    break;

                case GamePoints._701:
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 701, gameLegs, gameSets);
                    scoreBoardService.OpenScoreBoard(gameType, players, $"First to {gameSets}", 701);
                    break;

                case GamePoints._1001:
                    GameProcessor = new ClassicDoubleProcessor(Game, players, dbService, scoreBoardService, 1001, gameLegs, gameSets);
                    scoreBoardService.OpenScoreBoard(gameType, players, $"First to {gameSets}", 1001);
                    break;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            detectionService.OnThrowDetected               += OnAnotherThrow;
            detectionService.OnStatusChanged               += OnDetectionServiceStatusChanged;
            GameProcessor.OnMatchEnd                       += OnMatchEnd;
            camsDetectionBoard.OnUndoThrowButtonPressed    += OnThrowUndo;
            camsDetectionBoard.OnCorrectThrowButtonPressed += OnThrowCorrect;
        }