Exemple #1
0
        private void ChangingUsername(ref Player player, GeneralistProto proto)
        {
            string lastname = player.Name;

            player.Name = proto.Lobbycmd.Value;
            PlayerSession.BeginSend(ref player, "You succesfully change your name!!");
            Broadcast(lastname + " change his/her name to " + player.Name, ref player);
        }
Exemple #2
0
 public void Hand(GeneralistProto proto, ref Player player)
 {
     PlayerSession.BeginSend(ref player, "In your hand:");
     foreach (Card card in player.hand)
     {
         PlayerSession.BeginSend(ref player, Card._names[(int)card.face] + " " + Card._colors[(int)card.color] + " ");
     }
 }
 private void LobbiesListing(ref Player player)
 {
     PlayerSession.BeginSend(ref player, "Actual lobbies are :");
     foreach (var lobby in lobbies)
     {
         PlayerSession.BeginSend(ref player, "Lobby: " + lobby.name);
     }
 }
Exemple #4
0
        private void Broadcast(string msg)
        {
            var list = players.ToArray();

            for (int i = 0; i < list.Length; ++i)
            {
                PlayerSession.BeginSend(ref list[i], msg + '\n');
            }
        }
 private void Auth(ref Player player, GeneralistProto proto)
 {
     player.Name = proto.Auth.Name;
     player.Team = Team.None;
     players.Add(player);
     PlayerSession.BeginSend(ref player,
                             "#LIST - List all the available lobbies\n" +
                             "#JOIN [ChanName] - Join a channel\n" +
                             "#CREATE [ChanName] - Create a channel\n" +
                             "#USERNAME [NewName] - Change your username(in lobby)");
 }
        private void FindLobbyAndTreat(ref Player player, GeneralistProto proto)
        {
            Lobby lobby = FindLobby(ref player);

            if (lobby == null)
            {
                PlayerSession.BeginSend(ref player, "You can't sent that type of cmd till now");
                return;
            }
            lobby.Treat(proto, ref player);
        }
Exemple #7
0
        public void Broadcast(String msg, ref Player player)
        {
            var list = players.ToArray();

            for (int i = 0; i < list.Length; ++i)
            {
                if (!list[i].Equals(player))
                {
                    PlayerSession.BeginSend(ref list[i], player.Name + " said: " + msg);
                }
            }
        }
 private void LobbyJoinning(ref Player player, GeneralistProto proto)
 {
     foreach (var lobby in lobbies)
     {
         if (lobby.name.Equals(proto.Servercmd.Value))
         {
             if (lobby.AddPlayer(ref player))
             {
                 players.Remove(player);
             }
             return;
         }
     }
     PlayerSession.BeginSend(ref player, "The lobby you tried to join doesn't exist, type the command #LIST to see all the lobby");
 }
        private void LobbyCreating(ref Player player, GeneralistProto proto)
        {
            foreach (var lobby in lobbies)
            {
                if (lobby.name.Equals(proto.Servercmd.Value))
                {
                    PlayerSession.BeginSend(ref player, "A lobby already exist with this name");
                    return;
                }
            }
            Lobby newlobby = new Lobby(proto.Servercmd.Value);

            PlayerSession.BeginSend(ref player, "You successfully great your lobby");
            lobbies.Add(newlobby);
            newlobby.AddPlayer(ref player);
        }
Exemple #10
0
 public bool AddPlayer(ref Player player)
 {
     if (players.Count == 4)
     {
         PlayerSession.BeginSend(ref player, "The lobby you try to join is already full.");
         return(false);
     }
     if (players.Contains(player))
     {
         PlayerSession.BeginSend(ref player, "You already are in this lobby dumbass.");
         return(false);
     }
     players.Add(player);
     PlayerSession.BeginSend(ref player, "You successfully join this lobby");
     return(true);
 }
Exemple #11
0
        public void givenCard(int number, ref Player player)
        {
            string str;
            int    ret;
            Random rnd = new Random();


            str = "You recieved ";
            for (int i = 0; i < number; i++)
            {
                ret = rnd.Next(0, deck.Count);
                player.hand.Add(deck.ElementAt(ret));
                str += Card._names[(int)this.deck.ElementAt(ret).face] + " " + Card._colors[(int)this.deck.ElementAt(ret).color] + " ";
                this.deck.RemoveAt(ret);
            }
            PlayerSession.BeginSend(ref player, str);
        }
Exemple #12
0
 private void Run()
 {
     DistribCard();
     for (int i = 0; i < 4; ++i)
     {
         turn.Add(new PlayedCard());
     }
     turn.ElementAt(0).player    = blue.player1;
     turn.ElementAt(0).orderPlay = 0;
     turn.ElementAt(1).player    = red.player1;
     turn.ElementAt(1).orderPlay = 1;
     turn.ElementAt(2).player    = blue.player2;
     turn.ElementAt(2).orderPlay = 2;
     turn.ElementAt(3).player    = red.player2;
     turn.ElementAt(3).orderPlay = 3;
     PlayerSession.BeginSend(ref blue.player1, "You are the first to play, it's your turn to put a contract on.");
 }
Exemple #13
0
        private void NextTurn()
        {
            deck.AddRange(blue.stack);
            deck.AddRange(red.stack);
            deck.AddRange(blue.player1.hand);
            deck.AddRange(blue.player2.hand);
            deck.AddRange(red.player1.hand);
            deck.AddRange(red.player2.hand);
            blue.stack.Clear();
            red.stack.Clear();
            blue.player1.hand.Clear();
            blue.player2.hand.Clear();
            red.player1.hand.Clear();
            red.player2.hand.Clear();
            DistribCard();
            TurnStarter();
            Player p = GetToPlay();

            PlayerSession.BeginSend(ref p, "You are the first to play, it's your turn to put a contract on.");
        }
Exemple #14
0
        private void JoinningTeam(ref Player player, GeneralistProto proto)
        {
            if (player.Team == proto.Lobbycmd.Team)
            {
                PlayerSession.BeginSend(ref player, "You can't join a team, you are already in");
                return;
            }
            if (TeamFull(proto))
            {
                PlayerSession.BeginSend(ref player, "The time you are trying to joi is already full.");
                return;
            }
            player.Team = proto.Lobbycmd.Team;
            PlayerSession.BeginSend(ref player, "You join the team you wanted");

            if (IsGameLaunchable())
            {
                game = new Game(ref players);
            }
        }
Exemple #15
0
        private void GameStatus()
        {
            if (game == null)
            {
                return;
            }
            if (game.isOver == false)
            {
                return;
            }
            game = null;
            foreach (Player player in players)
            {
                player.Team = Team.None;
            }
            var list = players.ToArray();

            for (int i = 0; i < list.Length; ++i)
            {
                PlayerSession.BeginSend(ref list[i], "The game has been supressed, your team reset you can now do a revanche");
            }
        }
Exemple #16
0
        public void Treat(GeneralistProto proto, ref Player player)
        {
            GameStatus();
            switch (proto.Type)
            {
            case CmdTarget.Chat:
                Broadcast(proto.Chat.Msg, ref player);
                break;

            case CmdTarget.Lobbycmd:
                LobbyCmd(ref player, proto);
                break;

            case CmdTarget.Gamecmd:
                if (this.game == null)
                {
                    PlayerSession.BeginSend(ref player, "You can't send game order, because the game is not running atm");
                    return;
                }
                game.Treat(proto, ref player);
                break;
            }
        }
Exemple #17
0
        public void PlayCard(GeneralistProto proto, ref Player player)
        {
            Card card;

            if (this.isWaited != CGame.Types.Cmd.Card)
            {
                PlayerSession.BeginSend(ref player, "It's not the time to put a contract up.");
                return;
            }
            if (!HisTurn(ref player))
            {
                PlayerSession.BeginSend(ref player, "Please wait your turn to do a contract.");
                return;
            }

            try {
                card = GetCard(proto, ref player);
            } catch (Exception e) {
                PlayerSession.BeginSend(ref player, e.Message);
                return;
            }

            foreach (PlayedCard toplay in turn)
            {
                if (player.Name.Equals(toplay.player.Name))
                {
                    toplay.card = card;
                }
            }

            Broadcast(player.Name + " played: " + Card._names[(int)card.face] + " " + Card._colors[(int)card.color]);
            player.hand.Remove(card);

            Player tmp;

            if (hasToPlay < 3)
            {
                hasToPlay += 1;
                tmp        = GetToPlay();
                PlayerSession.BeginSend(ref tmp, "It's your turn to play a card.");
            }
            else
            {
                hasToPlay = 0;
                ConcludeTurn();
                if (blue.player1.hand.Count == 0)
                {
                    Broadcast("This hand is over, a new one will begin soon");
                    Reset();
                    if (IsOver())
                    {
                        return;
                    }
                    Broadcast("Your card has been redistribute");
                    isWaited = CGame.Types.Cmd.Contract;
                    return;
                }
                tmp = GetToPlay();
                PlayerSession.BeginSend(ref tmp, "It's your turn to play a card");
            }
        }
Exemple #18
0
        public void Contract(GeneralistProto proto, ref Player player)
        {
            if (this.isWaited != CGame.Types.Cmd.Contract)
            {
                PlayerSession.BeginSend(ref player, "It's not the time to put a contract up.");
                return;
            }
            if (!HisTurn(ref player))
            {
                PlayerSession.BeginSend(ref player, "Please wait your turn to do a contract.");
                return;
            }
            PlayerSession.BeginSend(ref player, "We are taking into count your contract");
            try {
                Contract contract = getFromCmd(ref player, proto);
                try {
                    NewContract(ref player, ref contract);
                    Broadcast(player.Name + " has put a contract on " + _contracts[(int)contract.type] + " of value " + contract.scale);
                } catch (Exception e) {
                    PlayerSession.BeginSend(ref player, e.Message);
                    return;
                }
            } catch (Exception e) {
                System.Console.Error.WriteLine(e.Message);
                if (proto.Gamecmd.Value.Split(' ')[0].Equals("Coinche"))
                {
                    if (_contract == null)
                    {
                        PlayerSession.BeginSend(ref player, "You can't put a coinche, if there is not existing contract");
                        return;
                    }
                    if (_contract.team == player.Team && _contract.coinche != 2)
                    {
                        PlayerSession.BeginSend(ref player, "You can't put a coinche on your team contract");
                        return;
                    }
                    _contract.coinche *= 2;
                    Broadcast(player.Name + " has put a coinche on the actual contract");
                }
                else if (proto.Gamecmd.Value.Split(' ')[0].Equals("Pass"))
                {
                    Broadcast(player.Name + " has pass this turn");
                }
                else
                {
                    PlayerSession.BeginSend(ref player, "Unrecognized contract");
                    return;
                }
            }
            Player tmp;


            if (hasToPlay < 3)
            {
                hasToPlay += 1;
                tmp        = GetToPlay();
                PlayerSession.BeginSend(ref tmp, "It's your turn to put a contract.");
            }
            else
            {
                if (_contract == null)
                {
                    NextTurn();
                    return;
                }
                hasToPlay = 0;
                Broadcast("The contract turn is now over, first turn of game can start");
                tmp = GetToPlay();
                PlayerSession.BeginSend(ref tmp, "It's your turn to play a card");
                isWaited = CGame.Types.Cmd.Card;
            }
        }
Exemple #19
0
 public void Send(string msg, Player player)
 {
     PlayerSession.BeginSend(ref player, msg);
 }