public async Task Unload()
        {
            await gameLoader.Unload();

            currentGame           = null;
            gameModeSwitchHandler = null;
        }
示例#2
0
        public MainWindow(IGameType gameType, NumberOfPlayers players)
        {
            var viewAndViewModel = gameType.CreateViewAndViewModel(players);

            this.Resources.Add("GameView", viewAndViewModel.Item1);
            this.Resources.Add("ViewModel", viewAndViewModel.Item2);

            InitializeComponent();

            mScoreLabel.SetBinding(Label.ContentProperty,
                                   new Binding()
            {
                Path      = new PropertyPath("BoardValue"),
                Converter = gameType.CreateBoardValueConverter()
            }
                                   );

            mPlayerLabel.SetBinding(Label.ContentProperty,
                                    new Binding()
            {
                Path      = new PropertyPath("CurrentPlayer"),
                Converter = gameType.CreateCurrentPlayerConverter()
            }
                                    );
            viewAndViewModel.Item2.GameFinished += ViewModel_GameFinished;
        }
        public GameChoiceWindow()
        {
            InitializeComponent();
            //create directory for dll files
            //C:/Users/Stephanie/Desktop/New folder/Project3/Project3/src/Cecs475.BoardGames.WpfApplication/bin/Debug/lib
            //C:/Users/samue/Documents/CECS 475/Project3/Project3/src/Cecs475.BoardGames.WpfApplication/bin/Debug/lib
            string          dir        = "C:/Users/samue/Documents/CECS 475/Project3/Project3/src/Cecs475.BoardGames.WpfApplication/bin/Debug/lib";
            Type            IGameType  = typeof(IGameType);
            List <Assembly> GameSearch = new List <Assembly>();

            foreach (var dll in Directory.GetFiles(dir, "*.dll"))
            {
                var y = Assembly.LoadFrom(dll);
                GameSearch.Add(y);
            }
            //filters the assemblies with goodes that are assignable and are classes
            var gameTypes             = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).Where(t => IGameType.IsAssignableFrom(t) && t.IsClass);
            List <IGameType> GameList = new List <IGameType>();

            foreach (var GameTypes in gameTypes)
            {
                var       x        = GameTypes.GetConstructor(Type.EmptyTypes); // empty type are constructors that have no parameters
                IGameType instance = (IGameType)x.Invoke(null);
                GameList.Add(instance);
            }
            //add the list to the resource
            this.Resources.Add("GameTypes", GameList);
        }
        /// <summary>
        /// Initializes the model.
        /// </summary>
        /// <param name="gameType">Type of the game.</param>
        /// <param name="gameSettings">The game settings.</param>
        /// <param name="selectedGame">The selected game.</param>
        /// <returns>IGame.</returns>
        protected virtual IGame InitModel(IGameType gameType, IGameSettings gameSettings, string selectedGame)
        {
            var game = GetModelInstance <IGame>();

            game.Type                      = gameType.Name;
            game.Name                      = gameType.Name;
            game.IsSelected                = selectedGame == gameType.Name;
            game.UserDirectory             = gameType.UserDirectory;
            game.SteamAppId                = gameType.SteamAppId;
            game.WorkshopDirectory         = gameType.WorkshopDirectory;
            game.LogLocation               = gameType.LogLocation;
            game.ChecksumFolders           = gameType.ChecksumFolders;
            game.GameFolders               = gameType.GameFolders ?? new List <string>();
            game.BaseGameDirectory         = gameType.BaseGameDirectory;
            game.AdvancedFeaturesSupported = gameType.AdvancedFeaturesSupported;
            game.LauncherSettingsFileName  = gameType.LauncherSettingsFileName;
            game.LauncherSettingsPrefix    = gameType.LauncherSettingsPrefix;
            game.RemoteSteamUserDirectory  = gameType.RemoteSteamUserDirectory;
            game.CloseAppAfterGameLaunch   = true;
            var setExeLocation     = true;
            var setUserDirLocation = true;

            if (gameSettings != null)
            {
                game.CloseAppAfterGameLaunch = gameSettings.CloseAppAfterGameLaunch.GetValueOrDefault(true);
                game.RefreshDescriptors      = gameSettings.RefreshDescriptors;
                if (!string.IsNullOrWhiteSpace(gameSettings.LaunchArguments))
                {
                    game.LaunchArguments = gameSettings.LaunchArguments;
                }
                if (!string.IsNullOrWhiteSpace(gameSettings.ExecutableLocation))
                {
                    setExeLocation          = false;
                    game.ExecutableLocation = gameSettings.ExecutableLocation;
                }
                if (!string.IsNullOrWhiteSpace(gameSettings.UserDirectory))
                {
                    setUserDirLocation = false;
                    game.UserDirectory = gameSettings.UserDirectory;
                }
            }
            if (setExeLocation || setUserDirLocation)
            {
                var settings = GetDefaultGameSettings(game);
                if (setExeLocation)
                {
                    game.ExecutableLocation = settings.ExecutableLocation ?? string.Empty;
                    game.LaunchArguments    = settings.LaunchArguments ?? string.Empty;
                }
                if (setUserDirLocation)
                {
                    game.UserDirectory = settings.UserDirectory;
                }
            }
            if (string.IsNullOrWhiteSpace(game.UserDirectory))
            {
                game.UserDirectory = gameType.UserDirectory;
            }
            return(game);
        }
示例#5
0
 /// <summary>
 /// Registers the game.
 /// </summary>
 /// <param name="gameType">Type of the game.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 /// <exception cref="InvalidOperationException"></exception>
 public virtual bool RegisterGame(IGameType gameType)
 {
     lock (dbLock)
     {
         if (gameType == null || Database.Games.Any(s => s.Name.Equals(gameType.Name, StringComparison.OrdinalIgnoreCase)))
         {
             throw new InvalidOperationException($"{gameType?.Name} game is already registered or invalid registration.");
         }
         var game = DIResolver.Get <IGameType>();
         game.Name                      = gameType.Name;
         game.UserDirectory             = gameType.UserDirectory ?? string.Empty;
         game.SteamAppId                = gameType.SteamAppId;
         game.WorkshopDirectory         = gameType.WorkshopDirectory ?? new List <string>();
         game.LogLocation               = gameType.LogLocation;
         game.ChecksumFolders           = gameType.ChecksumFolders ?? new List <string>();
         game.GameFolders               = gameType.GameFolders ?? new List <string>();
         game.BaseSteamGameDirectory    = gameType.BaseSteamGameDirectory ?? string.Empty;
         game.ExecutablePath            = gameType.ExecutablePath ?? string.Empty;
         game.ExecutableArgs            = gameType.ExecutableArgs ?? string.Empty;
         game.LauncherSettingsFileName  = gameType.LauncherSettingsFileName ?? string.Empty;
         game.LauncherSettingsPrefix    = gameType.LauncherSettingsPrefix ?? string.Empty;
         game.AdvancedFeaturesSupported = gameType.AdvancedFeaturesSupported;
         game.RemoteSteamUserDirectory  = gameType.RemoteSteamUserDirectory ?? new List <string>();
         game.Abrv                      = gameType.Abrv ?? string.Empty;
         Database.Games.Add(game);
         return(true);
     }
 }
 public static void AddGameMode(string code, IGameType gameTypeInfo)
 {
     if (GameTypes.ContainsKey(code))
     {
         throw new Exception("Unable to assign " + code + " to GameType " + gameTypeInfo.Name);
     }
     GameTypes.Add(code, gameTypeInfo);
 }
        public async Task Unload()
        {
            gameType.UnlockCamera();
            currentGame       = null;
            currentGameResult = null;
            gameType          = null;

            await gameLoader.Unload();
        }
示例#8
0
 /// <summary>
 /// Maps the executable settings.
 /// </summary>
 /// <param name="gameType">Type of the game.</param>
 /// <param name="settings">The settings.</param>
 private void MapGameSettings(IGameType gameType, GameSettings settings)
 {
     if (settings != null && gameType != null)
     {
         gameType.ExecutablePath = settings.ExecutablePath;
         gameType.ExecutableArgs = settings.ExecutableArgs;
         if (Directory.Exists(settings.UserDir))
         {
             gameType.UserDirectory = settings.UserDir;
         }
     }
 }
示例#9
0
    public IGameType GetGameType(int gameType)
    {
        IGameType currentGameType = null;

        switch (gameType)
        {
        case 0:
            currentGameType = new GameType0();
            break;
            // Additional cases...
        }
        return(currentGameType);
    }
        public async Task Load()
        {
            var loadingView = (ILoadingView)(await windowNavigation.Show <ILoadingView>(CancellationToken.None));

            loadingView.UpdateProgress(null);

            resourcesData = await resourcesDataProvider.GetData();

            player.InitResources(resourcesData);

            currentGame = await gameLoader.LoadGame(1, CancellationToken.None);

            _ = windowNavigation.Hide <ILoadingView>(CancellationToken.None);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button    b          = sender as Button;
            IGameType gameType   = b.DataContext as IGameType;
            var       gameWindow = new MainWindow(gameType)
            {
                Title = gameType.GameName
            };

            gameWindow.Closed += GameWindow_Closed;
            gameWindow.Show();

            this.Hide();
        }
示例#12
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button    b          = sender as Button;
            IGameType gameType   = b.DataContext as IGameType;
            var       gameWindow = new MainWindow(gameType,
                                                  mHumanBtn.IsChecked.Value ? NumberOfPlayers.Two : NumberOfPlayers.One)
            {
                Title = gameType.GameName
            };

            gameWindow.Closed += GameWindow_Closed;

            gameWindow.Show();
            this.Hide();
        }
示例#13
0
        public GameChoiceWindow()
        {
            InitializeComponent();

            Type gameType = typeof(IGameType);
            var  files    = Directory.GetFiles("lib");

            foreach (var f in Directory.GetFiles("lib"))
            {
                Console.WriteLine(f);
                string file = f.Substring(4);
                file = file.Substring(0, file.Length - 4);
                Assembly.Load($"{file}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=68e71c13048d452a");
                //Assembly.Load($"{f.Substring(0,f.Length-4)}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=68e71c13048d452a");
            }
            List <object> l          = new List <object>();
            var           boardTypes = AppDomain.CurrentDomain.GetAssemblies()
                                       .SelectMany(a => a.GetTypes())
                                       .Where(t => gameType.IsAssignableFrom(t) && t.IsClass);

            foreach (var val  in boardTypes)
            {
                //Console.WriteLine("1");
                IGameType v = (IGameType)val.GetConstructor(Type.EmptyTypes).Invoke(null);
                l.Add(v);
            }

            /*foreach(var assemble in AppDomain.CurrentDomain.GetAssemblies())
             * {
             *  foreach(var t in assemble.GetTypes())
             *  {
             *      if (gameType.IsAssignableFrom(t) && t != gameType)
             *      {
             *
             *          //var construct = gameType.GetConstructors(BindingFlags.Public);
             *          //Type x = t.ReflectedType;
             *          var obj = Activator.CreateInstance(t);
             *          //var obj = construct[0].Invoke(new object[] { });
             *          l.Add(obj);
             *      }
             *  }
             * }*/
            Application.Current.Resources["GameTypes"] = l;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            // Retrieve the game type bound to the button
            IGameType gameType = b.DataContext as IGameType;
            // Get a View control for the game type
            Control viewControl = gameType.GetViewControl();
            // Construct a GameWindow to play the game.
            var gameWindow = new GameWindow(viewControl)
            {
                Title = gameType.GameName
            };

            // When the GameWindow closes, we want to show this window again.
            gameWindow.Closed += GameWindow_Closed;

            // Show the GameWindow, hide the Choice window.
            gameWindow.Show();
            this.Hide();
        }
示例#15
0
        public async Task Load(Game game)
        {
            currentGame = game;
            gameType    = await gameLoader.LoadGame((int)currentGame.GameType);

            gameType.GridAdapter.Init(game.Width, game.Height);
            gameType.SetupCamera();


            currentGameResult = new GameResult()
            {
                Score        = 0,
                Stars        = 0,
                WavesAlive   = 0,
                WavesResults = new WaveResult[currentGame.Waves.Length],
            };

            for (int i = 0; i < currentGameResult.WavesResults.Length; i++)
            {
                currentGameResult.WavesResults[i] = CreateSkippedResult();
            }
        }
示例#16
0
    private static void Initialize()
    {
        GameType = new WaveGameType();

        GameType.Initialize();
    }
示例#17
0
 public void Setup(int selectedGameType)
 {
     RunningGame          = GetGameType(selectedGameType);
     EventManager.Killed += RunningGame.CheckGameOver;
 }
示例#18
0
 public GameTypeModel(string name, IGameType gameType)
 {
     Name = name;
     Player1 = gameType.Player1.ToString();
     Player2 = gameType.Player2.ToString();
 }
示例#19
0
        public async Task <WaveResult> PlayWave(IGameType gameType, Wave currentWave, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(CreateSkippedResult());
            }

            void onTouch(Vector pos)
            {
                var(gridCoords, cell) = gameType.GridAdapter.WorldPositionToGridCoordinates(pos);
                if (!cell.Available)
                {
                    return;
                }

                var cardsUI = gameUIadapter.CardsUIAdapter;

                void onCardSelected(Weapon weapon)
                {
                    cardsUI.OnCardSelected      -= onCardSelected;
                    player.PlayerMPGenerator.MP -= weapon.Cost;

                    var loadedWeapon = weaponLoader.LoadWeapon(weapon.WeaponType);

                    loadedWeapon.Position = gridCoords;

                    _ = cardsUI.Hide(cancellationToken);
                }

                cardsUI.OnCardSelected += onCardSelected;
                _ = cardsUI.Show(cancellationToken);
            }

            inputService.Setup();
            inputService.OnTouch += onTouch;

            player.PlayerMPGenerator.Init();

            int enemiesKilled = 0;

            var enemies = new IEnemy[currentWave.Enemies.Length];

            for (int i = 0; i < currentWave.Enemies.Length && !cancellationToken.IsCancellationRequested && player.Alive; i++)
            {
                //await timeAdapter.Delay(1000, cancellationToken);
                var currentEnemy = currentWave.Enemies[i];
                var enemy        = enemyLoader.LoadEnemy(currentEnemy.Type);
                enemy.Animator.Walk();
                enemy.Movement.Position = new Vector(currentEnemy.Cell, 0, gameType.GridAdapter.Grid.Width * 3);
                enemies[i] = enemy;
                enemy.Init();

                await enemy.WaitForCompletion(cancellationToken);

                enemiesKilled = i;
            }
            inputService.OnTouch -= onTouch;
            inputService.Dispose();

            player.PlayerMPGenerator.Stop();
            return(new WaveResult()
            {
                Alive = player.Alive,
                VegansKilled = enemiesKilled,
            });
        }
示例#20
0
    private static void Initialize(IGameType gameType)
    {
        GameType = gameType;

        GameType.Initialize();
    }
示例#21
0
 public void TearDown()
 {
     EventManager.Killed -= RunningGame.CheckGameOver;
     RunningGame          = null;
 }