Esempio n. 1
0
        public void AddPlayer(Player sender)
        {
            MainForm.GetInstance().MainThreadDispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new System.Windows.Forms.MethodInvoker(delegate()
                    {
                        try
                        {
                            if (!MainForm.GetInstance().m_players.ContainsKey(sender.Id))
                            {
                                MainForm.GetInstance().m_players.Add(sender.Id, sender);

                                MainForm instance = MainForm.GetInstance();
                                //instance.startPanel.listOfPlayer.Clear();
                                ListView list = instance.startPanel.listOfPlayer;

                                //list.Columns.Add("ID");
                                //list.Columns.Add("Login");
                                //list.Columns.Add("Score");

                                string[] p = new string[3];
                                p[0] = sender.Id.ToString();
                                p[1] = sender.Login;
                                p[2] = sender.Score.ToString();

                                ListViewItem listItem = new ListViewItem(p);
                                ListViewItem added = list.Items.Add(listItem);

                                playerViewMap.Add(sender.Id, added);

                            }else{
                                UpdatePlayer(sender);
                            }

                        }
                        catch (Exception)
                        {

                            ;
                        }

                    }));
        }
Esempio n. 2
0
 public void RemovePlayer(Player player)
 {
 }
Esempio n. 3
0
 public void AddPlayer(Player player)
 {
 }
Esempio n. 4
0
        private void PacketRecu(WaitForPDProgressChangedEventArgs args)
        {
            lock (packetTraitementLock)
            {
                Console.WriteLine("{0} : client recu", args.ThePD);
                MainForm mainform = MainForm.GetInstance();
                PD pd = args.ThePD;
                switch (pd.PDType)
                {
                    case E_PD_TYPE.PUBLICCHAT:
                        // if(((PDPublicChat)pd).IdPlayer!=MainForm.GetInstance().LocalPlayer.Id)
                        mainform.startPanel.chatTextBox.AppendText(((PDPublicChat)pd).Name + ": " + ((PDPublicChat)pd).Msg + "\n");
                        break;
                    case E_PD_TYPE.PRIVATECHAT:
                        {
                            PDPrivateChat thePd = pd as PDPrivateChat;
                            mainform.gamePanel.chatTextBox.AppendText(thePd.Name + ": " + thePd.Msg + "\n");
                            break;
                        }
                    case E_PD_TYPE.JOINTABLERESPONSE:
                        {
                            PDJoinTableResponse thePd = pd as PDJoinTableResponse;
                            Table theTable = MainForm.GetInstance().gamePanel.currentTable;
                            theTable.TableID = thePd.TableID;
                            theTable.DifficultyLevel = (GameLevel)thePd.DifficultyLevel;
                            theTable.TableNumPlayer = (uint)thePd.NumPlayer;
                            mainform.gamePanel.sudokuPanel1.viewMessage("Attente", "Chargement de la table cours");

                            mainform.startPanel.chatTextBox.Clear();
                            mainform.gamePanel.currentTable.scores.Clear();
                            mainform.gamePanel.currentTable.colors.Clear();
                            MainForm.GetInstance().gamePanel.playerListOnTheTable.clearPlayers();

                            mainform.Phase = MainFormPhase.GAMING;
                            break;
                        }
                    case E_PD_TYPE.GAMEFINISH:
                        {
                            PDGameFinish thePd = pd as PDGameFinish;
                            // MainForm.GetInstance().MainThreadDispatcher.Invoke(
                            //System.Windows.Threading.DispatcherPriority.Normal,
                            //new System.Windows.Forms.MethodInvoker(delegate()
                            //{
                            //    MainForm.GetInstance().SudokuClient.sendPacket(new PDExitTable((uint)MainForm.GetInstance().gamePanel.currentTable.TableID, (uint)MainForm.GetInstance().LocalPlayer.Id));
                            //    MainForm.GetInstance().Phase = MainFormPhase.Starting;

                            //    MainForm.GetInstance().gamePanel.currentTable.players.Clear();

                            //}));
                            string name = MainForm.GetInstance().m_players[(int)thePd.WinerPlayerID].Login;
                            mainform.gamePanel.sudokuPanel1.viewMessage("Partie terminée", "Le joueur '" + name + "' a gagné");

                            break;
                        }
                    case E_PD_TYPE.STARTTABLEGAME:
                        {

                            PDStartTableGame thePd = pd as PDStartTableGame;
                            mainform.gamePanel.sudokuPanel1.Model = new Sudoku(thePd.Sudoku);

                            Table theTable = MainForm.GetInstance().gamePanel.currentTable;
                            theTable.TableID = thePd.TableID;
                            theTable.DifficultyLevel = (GameLevel)thePd.DifficultyLevel;
                            theTable.TableNumPlayer = (uint)thePd.PlayersID.Length;

                            loadTableFromArray(thePd.PlayersID);

                            mainform.gamePanel.currentTable.scores.Clear();
                            mainform.gamePanel.currentTable.colors.Clear();
                            MainForm.GetInstance().gamePanel.playerListOnTheTable.clearPlayers();
                            int i = 0;
                            foreach (var item in mainform.gamePanel.currentTable.players)
                            {
                                if (i >= mainform.gamePanel.currentTable.TableNumPlayer)
                                {
                                    break;
                                }
                                mainform.gamePanel.currentTable.scores.Add(item.Key, 0);
                                mainform.gamePanel.currentTable.colors.Add(item.Key, colors[i]);

                                string name = MainForm.GetInstance().m_players[(int)item.Key].Login;
                                MainForm.GetInstance().gamePanel.playerListOnTheTable.addPlayer(item.Key, name, 0, colors[i]);
                                i++;
                            }
                            mainform.gamePanel.sudokuPanel1.viewStart();
                            //MainForm.GetInstance().gamePanel.playerListOnTheTable.Model = mainform.gamePanel.currentTable.scores;

                            break;
                        }
                    case E_PD_TYPE.INSERTPLAYER:
                        Player thePlayer = new Player();
                        thePlayer.Login = ((PDInsertPlayer)pd).Name;
                        thePlayer.Id = (int)((PDInsertPlayer)pd).PlayerID;
                        thePlayer.Score = ((PDInsertPlayer)pd).Score;
                        AddPlayer(thePlayer);

                        break;
                    case E_PD_TYPE.EXITTABLE:

                        break;
                    case E_PD_TYPE.UPDATEPPLAYERSTATE:
                        Player thePlayer1 = new Player();
                        thePlayer1.Id = (int)((PDUpdatePlayerState)pd).PlayerID;
                        thePlayer1.Score = ((PDUpdatePlayerState)pd).Score;
                        UpdatePlayer(thePlayer1);
                        break;
                    case E_PD_TYPE.DELETEPLAYER:
                        Player thePlayer2 = new Player();
                        thePlayer2.Id = (int)((PDDeletePlayer)pd).PlayerID;
                        RemovePlayer(thePlayer2);
                        break;
                    case E_PD_TYPE.UPDATETABLESTATE:
                        {
                            PDUpdateTableState tableState = pd as PDUpdateTableState;
                            loadTableFromArray(tableState.PlayersID);

                            mainform.gamePanel.currentTable.scores.Clear();
                            mainform.gamePanel.currentTable.colors.Clear();
                            mainform.gamePanel.playerListOnTheTable.clearPlayers();
                            int i = 0;
                            foreach (var item in mainform.gamePanel.currentTable.players)
                            {
                                if (i >= mainform.gamePanel.currentTable.TableNumPlayer)
                                {
                                    break;
                                }
                                mainform.gamePanel.currentTable.scores.Add(item.Key, 0);
                                mainform.gamePanel.currentTable.colors.Add(item.Key, colors[i]);

                                string name = MainForm.GetInstance().m_players[(int)item.Key].Login;
                                MainForm.GetInstance().gamePanel.playerListOnTheTable.addPlayer(item.Key, name, 0, colors[i]);
                                i++;
                            }
                            break;
                        }
                    case E_PD_TYPE.UPDATECELL:
                        PDUpdateCell cell = pd as PDUpdateCell;

                        Color color;

                        MainForm.GetInstance().gamePanel.currentTable.colors.TryGetValue(cell.PlayerID, out color);

                        MainForm.GetInstance().gamePanel.sudokuPanel1.DoMove(cell.CellNum / 9, cell.CellNum % 9, cell.CellValue, color);
                        Player modifiedPlayer;
                        MainForm.GetInstance().m_players.TryGetValue((int)cell.PlayerID, out modifiedPlayer);

                        mainform = MainForm.GetInstance();

                        if (mainform.gamePanel.currentTable.scores.ContainsKey(cell.PlayerID))
                        {
                            mainform.gamePanel.currentTable.scores.Remove(cell.PlayerID);
                            mainform.gamePanel.currentTable.scores.Add(cell.PlayerID, cell.m_score);
                        }

                        MainForm.GetInstance().gamePanel.playerListOnTheTable.updatePlayerScore(cell.PlayerID, cell.m_score);

                        break;
                    case E_PD_TYPE.UPDATEPPLAYERTABLESTATE:
                        PDUpdatePlayerTableState state = pd as PDUpdatePlayerTableState;
                        Player modifiedPlayer2;
                        MainForm.GetInstance().m_players.TryGetValue((int)state.PlayerID, out modifiedPlayer2);

                        int currentScore;
                        MainForm.GetInstance().gamePanel.currentTable.scores.TryGetValue((uint)state.PlayerID, out currentScore);

                        MainForm.GetInstance().gamePanel.currentTable.scores.Remove((uint)modifiedPlayer2.Id);
                        MainForm.GetInstance().gamePanel.currentTable.scores.Add((uint)modifiedPlayer2.Id, state.Score);
                        MainForm.GetInstance().gamePanel.playerListOnTheTable.updatePlayerScore(state.PlayerID, state.Score);
                        break;

                }
            }
        }
Esempio n. 5
0
        public void UpdatePlayer(Player sender)
        {
            MainForm.GetInstance().MainThreadDispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new System.Windows.Forms.MethodInvoker(delegate()
                    {
                        try
                        {
                            if (MainForm.GetInstance().m_players.ContainsKey(sender.Id))
                            {
                                ListViewItem listItem;
                                playerViewMap.TryGetValue(sender.Id, out listItem);

                                Player real;
                                MainForm.GetInstance().m_players.TryGetValue(sender.Id, out real);

                                real.Score = sender.Score;

                                MainForm.GetInstance().startPanel.listOfPlayer.Items.Remove(listItem);
                                playerViewMap.Remove(sender.Id);

                                string[] p = new string[3];
                                p[0] = real.Id.ToString();
                                p[1] = real.Login;
                                p[2] = sender.Score.ToString();

                                listItem = new ListViewItem(p);

                                ListViewItem listItem2= MainForm.GetInstance().startPanel.listOfPlayer.Items.Add(listItem);
                                playerViewMap.Add(sender.Id, listItem2);

                            }
                        }
                        catch (System.Exception ex)
                        {

                        }
                    }));
        }
Esempio n. 6
0
        public void RemovePlayer(Player sender)
        {
            MainForm.GetInstance().MainThreadDispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new System.Windows.Forms.MethodInvoker(delegate()
                    {
                        if (MainForm.GetInstance().m_players.ContainsKey(sender.Id))
                        {
                            Player real;
                            MainForm.GetInstance().m_players.TryGetValue(sender.Id, out real);
                            MainForm.GetInstance().m_players.Remove(sender.Id);

                            ListViewItem listItem;
                            playerViewMap.TryGetValue(sender.Id, out listItem);

                            MainForm.GetInstance().startPanel.listOfPlayer.Items.Remove(listItem);
                            playerViewMap.Remove(sender.Id);
                        }

                    }));
        }