void StateMachineEnter_LoadSavedGame(Enum state, GeneralOptions options = null)
    {
        Debug.Log("StateMachineEnter_LoadSavedGame");

        level        = Settings.Level;
        gameStrategy = StrategyFactory.CreateInstance(GetGameStrategy(level));
        score        = Settings.Score;
        remainTime   = Settings.RemainTime;
        SearchNum    = Settings.SearchNum;
        ShuffeNum    = Settings.ShuffeNum;
        pairNum      = Settings.PairNum;
        TimeNum      = Settings.TimeNum;

        int[] tempMatrix = Settings.Matrix;
        Debug.LogWarning("length: " + tempMatrix.Length);
        matrix = new int[row, col];
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < col; j++)
            {
                Debug.LogWarning("i: " + i + " j: " + j + " value: " + matrix[i, j]);
                matrix[i, j] = tempMatrix[col * i + j];
            }
        }
        mapUI.Initialize(matrix, this, (GameStrategy)level);
        currentPairCellIds = CoreGame.GetAvailablePair(matrix);
        StateMachineChange(GameState.EnterLevel);
    }
        public bool LaunchStrategy()
        {
            ctx = GameContext.Instance;

            //Introspection later...
            if (!ctx.IsOver)
            {
                if (!ctx.IsPaused)
                {
                    currentStrategy = new GameRunStrategy();
                }
                else
                {
                    currentStrategy = new GamePausedStrategy();
                }
            }
            else
            {
                if (ctx.HasHitTheWall)
                {
                    currentStrategy = new GameOverHitWallStrategy();
                }
                else
                {
                    currentStrategy = new GameOverHitSelfStrategy();
                }
            }

            return(currentStrategy.Run());
        }
 public void SetPlayer02DmgEvent(IGameStrategy Character)
 {
     Character.OnPlayerTakeDmg += (life, sender) =>
     {
         Player02Image.rectTransform.sizeDelta = new Vector3(Width * (life / 100f), Height, 1f);
         Debug.Log("Life p2 size: " + (life / 100f));
     };
 }
Esempio n. 4
0
 public Player(Guid id, string name, IGameStrategy strategy)
 {
     this.Id            = id;
     this.Name          = name;
     this.Strategy      = strategy;
     this.WinCount      = 0;
     this.BoardLocation = 0;
 }
Esempio n. 5
0
        public void InitTable()
        {
            var gameName = ChooseGame();

            _gameStrategy = GameStrategyFactory.Get(gameName);

            _gameStrategy.RenderWindow();
        }
Esempio n. 6
0
 public Game(String gameName, IGameStrategy strategy, BattleShipServer.Server.Server server)
 {
     this.gameName = gameName;
     this.strategy = strategy;
     this.server = server;
     subscribers = new Dictionary<UserAccount, IGameCallback>();
     userPlacements = new Dictionary<UserAccount,UserSession>();
 }
 public void Play(IGameStrategy strategy)
 {
     strategy.InitGame();
     while (!strategy.IsGameOver())
     {
         strategy.NextTurn();
     }
     Console.Write($"Игра окончена со счетом: {strategy.GetTotalResult()}");
 }
Esempio n. 8
0
        public Game(IList <Player> players, IDice dice, Board board, IGameStrategy gameStrategy)
        {
            _dice         = dice;
            _players      = new CircularLinkedList <Player>(players);
            _gameStrategy = gameStrategy;

            Board   = board;
            Players = players;
        }
 private void SubscribeDeathEvent(IGameStrategy Character)
 {
     Character.OnPlayerDeath += (sender, args) =>
     {
         winner.text = $"Last winner: {args.Sender.Name}";
         winner.gameObject.SetActive(true);
         menuCanvas.SetActive(true);
         gameCanvas.SetActive(false);
     };
 }
 protected virtual void NewGame()
 {
     pairNum     = (row - 2) * (col - 2) / 2;
     this.matrix = CoreGame.CreateMatrix(row, col);
     if (CoreGame.GetAvailablePair(this.matrix).Count == 0)
     {
         ResetMap();
     }
     gameStrategy = StrategyFactory.CreateInstance(GetGameStrategy(level));
     mapUI.Initialize(matrix, this, (GameStrategy)level);
     remainTime = matchTime;
 }
        public ComputerAdversary(IGameStrategy[] availableStrategies)
        {
            Require.NotNull(availableStrategies);

            if (availableStrategies.Length < 1)
            {
                throw new ArgumentException("No available game strategies for computer adversary", nameof(availableStrategies));
            }

            _availableStrategies = availableStrategies;
            _currentStrategy     = availableStrategies[0];
        }
Esempio n. 12
0
    public void TakeDmg(float dmg, IGameStrategy sender)
    {
        if (Life - dmg <= 0)
        {
            Life = 0;
            OnPlayerTakeDmg?.Invoke(Life, this);
            OnPlayerDeath?.Invoke(this, new DeathArgs(sender));
            return;
        }

        Life -= dmg;
        OnPlayerTakeDmg?.Invoke(Life, this);
    }
    public static IGameStrategy CreateInstance(GameStrategy strategy)
    {
        IGameStrategy gameStrategy = null;

        switch (strategy)
        {
        case GameStrategy.Normal:
            gameStrategy = new NormalStrategy();
            break;

        case GameStrategy.Bottom:
            gameStrategy = new BottomStrategy();
            break;

        case GameStrategy.Top:
            gameStrategy = new TopStrategy();
            break;

        case GameStrategy.Left:
            gameStrategy = new LeftStrategy();
            break;

        case GameStrategy.Right:
            gameStrategy = new RightStrategy();
            break;

        case GameStrategy.LeftAndRight:
            gameStrategy = new LeftAndRightStrategy();
            break;

        case GameStrategy.TopAndBottom:
            gameStrategy = new TopAndBottomStrategy();
            break;

        case GameStrategy.XCenter:
            gameStrategy = new XCenterStrategy();
            break;

        case GameStrategy.YCenter:
            gameStrategy = new YCenterStrategy();
            break;
        }
        return(gameStrategy);
    }
Esempio n. 14
0
        public bool createGame(string gameName, IGameStrategy strategy)
        {
            if (games.Keys.Contains(gameName))
            {
                return false;
            }

            BattleShipServer.WCFConnection.Server.Game game
                = new BattleShipServer.WCFConnection.Server.Game(gameName,strategy, this);
            games.Add(gameName, game);

            ServiceHost sh = serviceFactory.createGame(IP, game, gameName);
            sh.Open();
            gameSHs.Add(gameName, sh);

            lobby.sendMessage("Server > Game: \"" + gameName + "\" was created!");

            return true;
        }
Esempio n. 15
0
 public DeathArgs(IGameStrategy sender)
 {
     Sender = sender;
 }
 public void TakeDmg(float dmg, IGameStrategy sender) => StrategyFighter.TakeDmg(dmg, sender);
 protected GameStrategy()
 {
     currentStrategy = new GameRunStrategy();
 }
Esempio n. 18
0
 /// <summary>
 /// Constructor that sets the strategy of the game
 /// </summary>
 /// <param name="strategy">a chosen strategy for poker.</param>
 private void SetStrategy(IGameStrategy strategy)
 {
     _strategy = strategy;
 }
Esempio n. 19
0
 public IGameStrategy SetStrategy(IGameStrategy strategy)
 {
     _strategy = strategy;
     return(strategy);
 }
Esempio n. 20
0
 public PlayerCollectionBuilder Add(string playerName, IGameStrategy strategy)
 {
     _players.Add(new Player(playerName, strategy));
     return(this);
 }
 // Constructor injection
 public Game(IGameStrategy strategy)
 {
     _strategy = strategy;
 }
Esempio n. 22
0
 public Player(string name, IGameStrategy strategy)
     : this(Guid.NewGuid(), name, strategy)
 {
 }
    private IGameStrategy strategy;     // hold a reference to strategy

    public Actor(IGameStrategy strategy)
    {
        this.strategy = strategy;
    }
 public void SetPlayerDeathEvent(IGameStrategy Character1, IGameStrategy Character2)
 {
     SubscribeDeathEvent(Character1);
     SubscribeDeathEvent(Character2);
 }
 public override void SetStrategy(GameStrategyType strategy)
 {
     _currentStrategy = _availableStrategies.First(s => s.StrategyType == strategy);
 }
 public SimulationCollectionBuilder AddPlayer(string playerName, IGameStrategy gameStrategy)
 {
     _playerBuilder.Add(playerName, gameStrategy);
     return(this);
 }
Esempio n. 27
0
 public void GiveCards(IGameStrategy game)
 {
     _ItemGame  = game;
     _ItemCount = game.DeployCardGame();
 }