示例#1
0
 public IActionResult Playcard(string player, int index, int playerindex)
 {
     try
     {
         //var player = StaticClass.players.Where(p => p.Id != playerId).FirstOrDefault();
         //player.PlayerHealth.HealthCount -= damage;
         //_healthHubContext.Clients.All.SendAsync("SendHealth",
         //    new
         //    {
         //        playerId = player.Id,
         //        health = player.PlayerHealth
         //    });
         if (playerindex == 1)
         {
             var game = GamesSingleton.GetInstance().games.Where(g => g.player1.id.ToString() == player).FirstOrDefault();
             game.PlayCardFromHand(player, index);
             _gameHub.SendGame(game);
         }
         if (playerindex == 2)
         {
             var game = GamesSingleton.GetInstance().games.Where(g => g.player2.id.ToString() == player).FirstOrDefault();
             game.PlayCardFromHand(player, index);
             _gameHub.SendGame(game);
         }
         return(Ok());
     }
     catch
     {
         return(BadRequest());
     }
 }
示例#2
0
        public void Attack(Guid gameId, Guid playerId, Guid cardId)
        {
            var game = GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault();

            if (game.player1.id == playerId)
            {
                var card = game.field1.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();
                if (game.field2.monsterfield.Where(p => p != null).Count() > 0)
                {
                    card.attackPhase = CardAttackPhase.Attacking;
                }
                else
                {
                    card.attackPhase = CardAttackPhase.Attacked;
                    game.player2.playerHealth.healthCount -= card.attack;
                }
            }
            else if (game.player2.id == playerId)
            {
                var card = game.field2.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();
                if (game.field1.monsterfield.Where(p => p != null).Count() > 0)
                {
                    card.attackPhase = CardAttackPhase.Attacking;
                }
                else
                {
                    card.attackPhase = CardAttackPhase.Attacked;
                    game.player1.playerHealth.healthCount -= card.attack;
                }
            }
            game.turn.attackPhase = AttackPhases.Targeting;
            _gameHub.SendGame(game);
        }
示例#3
0
        public IActionResult TurnPhase(TurnPhases phase, Guid playerId, Guid gameId)
        {
            try
            {
                switch (phase)
                {
                case TurnPhases.AttackPhase:
                    var game = GamesSingleton.GetInstance().games.Where(g => g.id == gameId).FirstOrDefault();



                    if (game.gameType == GameTypes.AutoAttack)
                    {
                        if (game.player1.id == playerId)
                        {
                            var enemyid = game.player2.id;
                            var player  = game.player1;
                            var enemy   = game.player2;
                            strategy.decideStrategy(game, player, enemy);
                        }
                        else if (game.player2.id == playerId)
                        {
                            var enemyid = game.player1.id;
                            var player  = game.player2;
                            var enemy   = game.player1;
                            strategy.decideStrategy(game, player, enemy);
                        }
                        _turnLogic.UpdateView(game);
                    }
                    else
                    {
                        _turnLogic.Attack(gameId, playerId);
                    }

                    break;

                case TurnPhases.SecondPhase:
                    _turnLogic.Second(gameId, playerId);
                    break;

                case TurnPhases.EndTurn:
                    drawcardcontroller.DrawCard(gameId, playerId, 1);
                    _turnLogic.EndTurn(gameId, playerId);
                    break;

                default:
                    throw new NotImplementedException();
                }

                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
 public IActionResult DrawCard(Guid gameId, Guid playerId, int amount)
 {
     try
     {
         var game = GamesSingleton.GetInstance().games.Where(g => g.id == gameId).FirstOrDefault();
         game.PlayerDrawCardsIntoHand(playerId, amount);
         return(Ok());
     }
     catch
     {
         return(BadRequest());
     }
 }
        public LoginResponse Login(string loginName, string decktype)
        {
            var response = new LoginResponse();

            if (GamesSingleton.GetInstance().games.Count == 0)
            {
                var newGame = new Game();
                newGame.id                 = response.gameId = Guid.NewGuid();
                newGame.player1            = new Player();
                newGame.field1             = new Field();
                newGame.player1.id         = response.playerId = Guid.NewGuid();
                newGame.player1.playerName = loginName;
                newGame.player1.decktype   = decktype;
                newGame.player1.createDeck(decktype, 1);
                //newGame.player1.drawCardsFromDeck(3);
                newGame.PlayerDrawCardsIntoHand(newGame.player1.id, 5);
                GamesSingleton.GetInstance().games.Add(newGame);
            }
            else
            {
                if (GamesSingleton.GetInstance().games.Last().player2 != null)
                {
                    var newGame = new Game();
                    newGame.id                 = response.gameId = Guid.NewGuid();
                    newGame.player1            = new Player();
                    newGame.field1             = new Field();
                    newGame.player1.id         = response.playerId = Guid.NewGuid();
                    newGame.player1.playerName = loginName;
                    newGame.player1.decktype   = decktype;
                    newGame.player1.createDeck(decktype, 1);
                    //var cards = newGame.player1.drawCardsFromDeck(3);
                    newGame.PlayerDrawCardsIntoHand(newGame.player1.id, 5);
                    GamesSingleton.GetInstance().games.Add(newGame);
                }
                else
                {
                    var game = GamesSingleton.GetInstance().games.Last();
                    game.player2            = new Player();
                    game.field2             = new Field();
                    game.player2.id         = response.playerId = Guid.NewGuid();
                    game.player2.playerName = loginName;
                    game.player2.decktype   = decktype;
                    game.player2.createDeck(decktype, 2);
                    response.gameId = game.id;
                    game.PlayerDrawCardsIntoHand(game.player2.id, 5);
                    _gameLogic.StartGame(game);
                    _gameHub.SendGame(game);
                }
            }
            return(response);
        }
        public Game GetGame(Guid gameId)
        {
            Game game = null;

            if (GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault().player2 != null)
            {
                game = _realSubject.GetGame(gameId);
            }
            else
            {
                game = new Game(GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault());
            }

            return(game);
        }
示例#7
0
        public void Cancel(Guid gameId, Guid playerId, Guid cardId)
        {
            var game = GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault();

            if (game.player1.id == playerId)
            {
                var card = game.field1.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();
                card.attackPhase = CardAttackPhase.Waiting;
            }
            else if (game.player2.id == playerId)
            {
                var card = game.field2.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();
                card.attackPhase = CardAttackPhase.Waiting;
            }
            game.turn.attackPhase = AttackPhases.Attacking;
            _gameHub.SendGame(game);
        }
示例#8
0
        public void EndTurn(Guid gameId, Guid playerId)
        {
            ICommand command = new EndTurnPhaseCommand(_gameHub);

            command.ChangeTurnState(GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault(), playerId);
        }
示例#9
0
 public Game GetGame(Guid gameId)
 {
     return(GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault());
 }
示例#10
0
        public void Target(Guid gameId, Guid playerId, Guid cardId)
        {
            var game = GamesSingleton.GetInstance().games.Where(p => p.id == gameId).FirstOrDefault();

            if (game.player1.id == playerId)
            {
                var attackingCard = game.field1.monsterfield.Where(p => p != null && p.attackPhase == CardAttackPhase.Attacking).FirstOrDefault();
                var targetCard    = game.field2.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();

                if (attackingCard.attack > targetCard.defense)
                {
                    for (int i = 0; i < game.field2.monsterfield.Length; i++)
                    {
                        if (game.field2.monsterfield[i] != null && targetCard.id == game.field2.monsterfield[i].id)
                        {
                            game.field2.monsterfield[i] = null;
                        }
                    }
                    attackingCard.attackPhase = CardAttackPhase.Attacked;
                    attackingCard.attacked    = true;
                }
                else if (attackingCard.attack < targetCard.defense)
                {
                    for (int i = 0; i < game.field1.monsterfield.Length; i++)
                    {
                        if (game.field1.monsterfield[i] != null && attackingCard.id == game.field1.monsterfield[i].id)
                        {
                            game.field1.monsterfield[i] = null;
                        }
                    }
                }
                else if (attackingCard.attack == targetCard.defense)
                {
                    for (int i = 0; i < game.field2.monsterfield.Length; i++)
                    {
                        if (game.field2.monsterfield[i] != null && targetCard.id == game.field2.monsterfield[i].id)
                        {
                            game.field2.monsterfield[i] = null;
                        }
                    }
                    for (int i = 0; i < game.field1.monsterfield.Length; i++)
                    {
                        if (game.field1.monsterfield[i] != null && attackingCard.id == game.field1.monsterfield[i].id)
                        {
                            game.field1.monsterfield[i] = null;
                        }
                    }
                }
            }
            else if (game.player2.id == playerId)
            {
                var attackingCard = game.field2.monsterfield.Where(p => p != null && p.attackPhase == CardAttackPhase.Attacking).FirstOrDefault();
                var targetCard    = game.field1.monsterfield.Where(p => p != null && p.id == cardId).FirstOrDefault();

                if (attackingCard.attack > targetCard.defense)
                {
                    for (int i = 0; i < game.field1.monsterfield.Length; i++)
                    {
                        if (game.field1.monsterfield[i] != null && targetCard.id == game.field1.monsterfield[i].id)
                        {
                            game.field1.monsterfield[i] = null;
                        }
                    }
                    attackingCard.attackPhase = CardAttackPhase.Attacked;
                    attackingCard.attacked    = true;
                }
                else if (attackingCard.attack < targetCard.defense)
                {
                    for (int i = 0; i < game.field2.monsterfield.Length; i++)
                    {
                        if (game.field2.monsterfield[i] != null && attackingCard.id == game.field2.monsterfield[i].id)
                        {
                            game.field2.monsterfield[i] = null;
                        }
                    }
                }
                else if (attackingCard.attack == targetCard.defense)
                {
                    for (int i = 0; i < game.field2.monsterfield.Length; i++)
                    {
                        if (game.field2.monsterfield[i] != null && targetCard.id == game.field2.monsterfield[i].id)
                        {
                            game.field2.monsterfield[i] = null;
                        }
                    }
                    for (int i = 0; i < game.field1.monsterfield.Length; i++)
                    {
                        if (game.field1.monsterfield[i] != null && attackingCard.id == game.field1.monsterfield[i].id)
                        {
                            game.field1.monsterfield[i] = null;
                        }
                    }
                }
            }
            game.turn.attackPhase = AttackPhases.Attacking;
            _gameHub.SendGame(game);
        }