Ejemplo n.º 1
0
        public string AddPlayer(string id)
        {
            string result;

            if (CurrentPlayers.Count < MaxPlayers && !CurrentPlayers.Exists(player => player.PlayerId.Equals(id)))
            {
                Player newPlayer = new Player(CurrentPlayers.Count, id, CurrentPlayers.Count * 3, 1 + CurrentPlayers.Count, Rand);
                CurrentPlayers.Add(newPlayer);
                Player p;
                switch (CurrentPlayers.Count)
                {
                case 3:
                    MaxX = 5;
                    MaxY = 4;
                    Grid = new int[MaxX, MaxY];
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 0);
                    p.X  = 0;
                    p.Y  = 0;
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 1);
                    p.X  = 2;
                    p.Y  = 3;
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 2);
                    p.X  = 4;
                    p.Y  = 0;
                    break;

                case 4:
                    MaxX = 5;
                    MaxY = 5;
                    Grid = new int[MaxX, MaxY];
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 0);
                    p.X  = 0;
                    p.Y  = 0;
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 1);
                    p.X  = 0;
                    p.Y  = 4;
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 2);
                    p.X  = 4;
                    p.Y  = 0;
                    p    = CurrentPlayers.First(d => d.PlayerNumber == 3);
                    p.X  = 4;
                    p.Y  = 4;
                    break;
                }
                result = "User Added";
            }
            else
            {
                result = "Too many players, sorry";
            }
            return(result);
        }
        public void OnGameOver(List <int> failedPlayers)
        {
            for (var i = 0; i < failedPlayers.Count; i++)
            {
                var player = CurrentPlayers.First(p => p.playerId == failedPlayers[i]);
                player.score += i;
            }

            var winner = CurrentPlayers.Where(p => !failedPlayers.Contains(p.playerId)).First();

            winner.score += failedPlayers.Count;


            //TODO: 发点通知啥的

            SceneManager.LoadSceneAsync("Scenes/PlayerRoom/Room", LoadSceneMode.Single);
        }
Ejemplo n.º 3
0
        private void ResolveAttack(int cardNumber)
        {
            //Dictionary<string, Tuple<int, List<Tuple<int,int>>>> playersAttacks = new Dictionary<string, Tuple<int, List<Tuple<int,int>>>>(); //dmg, kernel
            Dictionary <string, Tuple <int, int> > playersPositions = new Dictionary <string, Tuple <int, int> >();

            foreach (var player in CurrentPlayers)
            {
                playersPositions[player.PlayerId] = new Tuple <int, int>(player.X, player.Y);
            }
            foreach (var player in CurrentPlayers)
            {
                List <Tuple <int, int> > affectedPositions = new List <Tuple <int, int> >();
                var card = CardsList[player.ActionList[cardNumber]];
                if (card.Dmg != 0)
                {
                    player.Animation = AnimationStatus.Attack;
                    int sizePerSide = card.DmgKernel.GetLength(0) / 2;
                    for (int y = 0; y < card.DmgKernel.GetLength(0); y++)
                    {
                        for (int x = 0; x < card.DmgKernel.GetLength(0); x++)
                        {
                            if (card.DmgKernel[y, x])
                            {
                                affectedPositions.Add(new Tuple <int, int>(player.X + x - sizePerSide, player.Y + y - sizePerSide));
                            }
                        }
                    }
                    //playersAttacks[player.PlayerId] = new Tuple<int, bool[,]>(card.Dmg, card.DmgKernel);
                    //player.Animation = AnimationStatus.Attack;
                }
                foreach (var position in playersPositions)
                {
                    foreach (var pos in affectedPositions)
                    {
                        if (pos.Item1 >= 0 && pos.Item1 < MaxX && pos.Item2 >= 0 && pos.Item2 < MaxY && Grid[pos.Item1, pos.Item2] == -1)
                        {
                            Grid[pos.Item1, pos.Item2] = -2;
                        }
                    }
                    if (affectedPositions.Contains(position.Value))
                    {
                        Player currentPlayer = CurrentPlayers.First(d => d.PlayerId == position.Key);
                        currentPlayer.HP -= card.Dmg;

                        switch (currentPlayer.Animation)
                        {
                        case AnimationStatus.Idle:
                            currentPlayer.Animation = AnimationStatus.IdleHurt;
                            break;

                        case AnimationStatus.Move:
                            currentPlayer.Animation = AnimationStatus.MoveHurt;
                            break;

                        case AnimationStatus.Attack:
                            currentPlayer.Animation = AnimationStatus.AttackHurt;
                            break;

                        case AnimationStatus.Colide:
                            currentPlayer.Animation = AnimationStatus.ColideHurt;
                            break;
                        }
                        if (currentPlayer.HP <= 0)
                        {
                            int pN = currentPlayer.PlayerNumber;
                            //currentPlayer.Animation = AnimationStatus.Death;
                            for (int i = 0; i < MaxX; i++)
                            {
                                for (int j = 0; j < MaxY; j++)
                                {
                                    if (Grid[i, j] == pN)
                                    {
                                        Grid[i, j] = -2;
                                    }
                                }
                            }
                            CurrentPlayers.Remove(currentPlayer);
                            //Status = 0; //game ended (specjalna wiadomość?)
                        }
                    }
                }
            }
        }