예제 #1
0
        public void exitTable(PlayerObserver player)
        {
            lock (joinLock)
            {
                if (m_players.ContainsKey(player.ThisPlayer.PlayerID))
                {
                    int playerScore = m_players[player.ThisPlayer.PlayerID].Score;
                    m_players.Remove(player.ThisPlayer.PlayerID);
                    player.PlayerTableChatSendEvent -= player_PlayerTableChatSendEvent;
                    player.PlayerUpdateTableCellEvent -= player_PlayerUpdateTableCellEvent;

                    if (m_gameStarted && m_tableNumPlayer > 1)
                    {
                        player.updatePlayerScore(playerScore);

                        //Si joueur unique, quitter la table (assuré par le manager)

                        if (m_players.Count == 1)
                        {
                            //Si 2 joueurs, declarer l'autre comme gagnant
                            m_gameEnded = true;

                            //Enregistrer les nouveaux scores
                            foreach (var item in m_players) // Normalement il y a un seul joueur
                            {
                                sendToAllTablePlayer(new PDGameFinish(TableID, item.Value.Player.ThisPlayer.PlayerID));
                                item.Value.Player.updatePlayerScore(item.Value.Score);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public void createTable(PlayerObserver player, GameLevel difficulty, uint numberPlayer)
        {
            lock (tableLock)
            {
                uint playerID = player.ThisPlayer.PlayerID;
                foreach (var item in m_tables)
                {
                    if (item.Value.isPlayerJoinedThisTable(playerID))
                    {
                        // informer le joueur qu'il ne peut joindre 2 table en même temps
                        player.SocketClient.sendPacket(new PDError(0, "Impossible de joindre 2 table en même temps"));
                        return;
                    }
                }

                SudokuTable st = new SudokuTable(difficulty, numberPlayer);
                m_tables.Add(st.TableID, st);
                st.jointTable(player);
                TableInserted(st);
            }
        }
예제 #3
0
 public void newPlayerConnected(TcpClient sockClient)
 {
     //Nouveau client on crée un nouveau thread qui va le prendre en charge
     PlayerObserver client = new PlayerObserver();
     m_newClient.Add(client);
     client.PlayerConectedEvent += new PlayerConectedEventHandler(client_PlayerConectedEvent);
     client.waitForLogin(sockClient);
 }
예제 #4
0
 public void sendAllTableToPlayer(PlayerObserver player)
 {
 }
예제 #5
0
        public void joinTable(PlayerObserver player, GameLevel difficulty, uint numberPlayer)
        {
            lock (tableLock)
            {
                uint playerID = player.ThisPlayer.PlayerID;
                foreach (var item in m_tables)
                {
                    if (item.Value.isPlayerJoinedThisTable(playerID))
                    {
                        //informer le joueur qu'il ne peut joindre 2 table en même temps
                        player.SocketClient.sendPacket(new PDError(0, "Impossible de joindre 2 table en même temps"));
                        return;
                    }
                }

                //On cherche une table avec les mêmes critère
                foreach (var item in m_tables)
                {
                    if (!item.Value.isFullTable() && item.Value.TableNumPlayer == numberPlayer && item.Value.DifficultyLevel == difficulty)
                    {
                        item.Value.jointTable(player);

                        TableUpdated(item.Value);
                        return;
                    }
                }
            }

            //Normalement aucune table n'est diponible on crée une nouvelle
            createTable(player, difficulty, numberPlayer);
        }
예제 #6
0
        public void exitTable(PlayerObserver player, uint tableID)
        {
            lock (tableLock)
            {

                if (m_tables.ContainsKey(tableID) )
                {
                    SudokuTable st = m_tables[tableID];
                    st.exitTable(player);
                    if (st.isEmptyTable)//Si table vide la supprimer
                    {
                        m_tables.Remove(tableID);
                        TableDeleted(st);
                    }
                    else
                    {
                        TableUpdated(st);
                    }
                }
            }
        }
예제 #7
0
        public void exitAllTable(PlayerObserver player)
        {
            var lstTmpr = new List<SudokuTable>();
            foreach (var e in m_tables)
            {
                lstTmpr.Add(e.Value);
            }

            //Comme on peut pas supprimer un élément de la collection m_tables qui fait objet d'un parcours et
            //exitTable peut supprimer des element de m_tables, pour cela il faut passer par une liste tmpr
            foreach (var item in lstTmpr)
            {
                if (item.isPlayerJoinedThisTable(player.ThisPlayer.PlayerID))
                {
                    exitTable(player, item.TableID);
                }
            }
        }
예제 #8
0
        public void jointTable(PlayerObserver player)
        {
            lock(joinLock){
                //Verifier si la table n'est pas pleine
                //Le joueur n'a pas join déjà la table
                //Si table complete envoyer la grille
                if (m_players.ContainsKey(player.ThisPlayer.PlayerID))
                {
                    //\todo le joueur a déjà rejoin la table
                    return;
                }
                else if (m_players.Count >= m_tableNumPlayer)
                {
                    //il y a plus de place
                    player.SocketClient.sendPacket(new PDError(0, "Désolé il n y a plus de place dans cette table"));
                }
                else
                {
                    PlayerTable pt = new PlayerTable();
                    if ((pt.Number = findFreeNumberPlayer()) != 0)
                    {
                        pt.Player = player;
                        pt.Score = 0;
                        m_players.Add(player.ThisPlayer.PlayerID, pt);

                        player.PlayerTableChatSendEvent += player_PlayerTableChatSendEvent;
                        player.PlayerUpdateTableCellEvent += player_PlayerUpdateTableCellEvent;

                        uint[] playersID = new uint[m_players.Count];
                        int i = 0;
                        foreach (var item in m_players)
                        {
                            playersID[i] = item.Value.Player.ThisPlayer.PlayerID;
                            i++;
                        }
                        PDJoinTableResponse pdres = new PDJoinTableResponse(TableID, (byte)DifficultyLevel, (byte)m_tableNumPlayer);
                        player.SocketClient.sendPacket(pdres);
                        System.Threading.Thread.Sleep(0);

                        if(!startGameIfPossible())
                        {
                            PDUpdateTableState pd = new PDUpdateTableState(TableID, playersID);
                            sendToAllTablePlayer(pd);
                            System.Threading.Thread.Sleep(0);
                        }
                    }
                    else
                    {
                        //\todo impossible mais erreur
                    }
                }
            }
        }