Example #1
0
        // Dessa 3 metoder hanterar listan
        public void AddHumanPlayer(string playerName)
        {
            HumanPlayerAmount++;
            PlayerModel humanPlayer = new PlayerModel();

            humanPlayer.PlayerName = playerName;
            CurrentPlayers.Add(humanPlayer);
        }
Example #2
0
        public void AddComPlayer()
        {
            ComPlayerAmount++;
            PlayerModel newComPlayer = new PlayerModel();

            newComPlayer.PlayerName = "Dator" + ComPlayerAmount.ToString();
            CurrentPlayers.Add(newComPlayer);
        }
Example #3
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);
        }