示例#1
0
        public static PD createPd(byte[] data)
        {
            int pdType = 0x000000FF & (int)data[0];

            E_PD_TYPE pdTypeEnum = (E_PD_TYPE)pdType;
            PD pd = null;

            MemoryStream ms = new MemoryStream(data);
            BinaryReader br = new BinaryReader(ms);

            switch (pdTypeEnum)
            {
                case E_PD_TYPE.AUTHENTIFICATION_RESP:
                    pd = new PDAuthentificationResp();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.AUTHENTIFICATION:
                    pd = new PDAuthentification();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.DELETEPLAYER:
                    pd = new PDDeletePlayer();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.DELETETABLE:
                    pd = new PDDeleteTable();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.INSERTPLAYER:
                    pd = new PDInsertPlayer();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.INSERTTABLE:
                    pd = new PDInsertTable();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.UPDATEPPLAYERSTATE:
                    pd = new PDUpdatePlayerState();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.UPDATETABLESTATE:
                    pd = new PDUpdateTableState();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.UPDATECELL:
                    pd = new PDUpdateCell();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.UPDATECELLREQUEST:
                    pd = new PDUpdateCellRequest();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.UPDATEPPLAYERTABLESTATE:
                    pd = new PDUpdatePlayerTableState();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.PUBLICCHAT:
                    pd = new PDPublicChat();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.PRIVATECHAT:
                    pd = new PDPrivateChat();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.NEWTABLE:
                    pd = new PDNewTable();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.JOINTABLE:
                    pd = new PDJoinTable();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.JOINTABLERESPONSE:
                    pd = new PDJoinTableResponse();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.EXITTABLE:
                    pd = new PDExitTable();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.STARTTABLEGAME:
                    pd = new PDStartTableGame();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.GAMEFINISH:
                    pd = new PDGameFinish();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.LISTOFPLAYERREQUEST:
                    pd = new PDListOfPlayerRequest();
                    pd.unmarshal(br);
                    break;
                case E_PD_TYPE.LISTOFTABLEREQUEST:
                    pd = new PDListOfPlayerRequest();
                    pd.unmarshal(br);
                    break;

                case E_PD_TYPE.ERROR:
                    pd = new PDError();
                    pd.unmarshal(br);
                    break;
            }
            br.Close();
            return pd;
        }
示例#2
0
        void player_PlayerUpdateTableCellEvent(object sender, UpdateTableCellEventArgs arg)
        {
            lock(updateLock)
            {
                if (m_gameStarted && !m_gameEnded && arg.TableID == m_tableID)
                {
                    if (m_players.ContainsKey(arg.ThisPlayer.PlayerID))
                    {
                        int line = arg.CellNum / 9;
                        int col = arg.CellNum % 9;

                        lock (updateLock)
                        {
                            if (m_sudokuGrid.IsCanUpdate(line, col))
                            {
                                if (m_sudokuGrid.IsValidUpdate(line, col, arg.CellValue))
                                {
                                    m_sudokuGrid.Update(line, col, arg.CellValue);

                                    m_players[arg.ThisPlayer.PlayerID].Score++;

                                    //On transmet la modif à tout les joueurs
                                    PDUpdateCell pd = new PDUpdateCell(TableID, arg.ThisPlayer.PlayerID, m_players[arg.ThisPlayer.PlayerID].Score, arg.CellNum, arg.CellValue);
                                    sendToAllTablePlayer(pd);
                                }
                                else
                                {
                                    m_players[arg.ThisPlayer.PlayerID].Score--;

                                    //On transmet le nouveau score à tout les joueurs
                                    PDUpdatePlayerTableState pd = new PDUpdatePlayerTableState(TableID, arg.ThisPlayer.PlayerID, m_players[arg.ThisPlayer.PlayerID].Score);
                                    sendToAllTablePlayer(pd);
                                }

                                VerifyIfGameFinished();
                            }
                        }
                    }
                }
            }
        }