Esempio n. 1
0
        public void InitGameOverRoom(EasyRoom room)
        {
            Controls.Clear();
            ClientSize = new Size(800, 600);
            Text       = "Dice Game. " + room.Name + " - Game over";

            int k = 0;
            List <EasyPlayer> players = room.Players.OrderByDescending(u => u.Score).ToList();

            EList <Label> PlayersList = new EList <Label>();

            Label title = new Label {
                Parent = this, Location = new Point(10, 10), Width = 780, Text = "Игра окончена. Итоги: ", Font = new Font(Font.FontFamily, 14)
            };

            foreach (EasyPlayer player in players)
            {
                k++;
                PlayersList.Add(new Label {
                    Parent = this, Location = new Point(10, 60 + k * 40), Width = 780, Text = player.Name + ": " + player.Score, Font = new Font(Font.FontFamily, 14)
                });
            }

            Button BackToLobby = new Button()
            {
                Parent = this, Location = new Point(ClientRectangle.Width / 2 - 150, PlayersList.Last().Location.Y + 60), Size = new Size(300, 40), Text = "Вернуться в лобби", Font = new Font(Font.FontFamily, 14)
            };

            BackToLobby.Click += (object sender, EventArgs e) => {
                LocalServer.SendFrame(new Frame(room.Id, Name, MessageType.Disconnect, GameMessageType.Undefined));
                InLobby = true;
                RoomId  = -1;
                InitMain();
            };
        }
Esempio n. 2
0
        public NotesView(EList <EasyRoom> notes) : base()
        {
            Width      = 780;
            AutoScroll = true;
            Notes      = notes;

            Rows = new EList <GameNoteView>();

            GameNoteView row;

            for (int i = 0; i < notes.Count; i++)
            {
                GameNoteView temp;
                if (i > 0)
                {
                    temp = new GameNoteView(notes[i])
                    {
                        Parent = this, Location = new Point(0, Rows.Last().Location.Y + 60)
                    };
                }
                else
                {
                    temp = new GameNoteView(notes[i])
                    {
                        Parent = this, Location = new Point(0, 0)
                    };
                }
                temp.ConnectEvent += (r) => {
                    ConnectEvent?.Invoke(r, notes[i]);
                };
                temp.WatchEvent += (r) => {
                    WatchEvent?.Invoke(r, notes[i]);
                };
                Rows.Add(temp);
            }

            // обновление списка лобби при добвление новых записей
            Notes.AfterAddEvent += (item) => {
                if (Rows.Count > 0)
                {
                    row = new GameNoteView()
                    {
                        Parent = this, Location = new Point(0, Rows.Last().Location.Y + 60)
                    };
                    if (row.InvokeRequired)
                    {
                        row.Invoke(new Action <EasyRoom>((s) => row.SetSource(s)), item);
                    }
                    else
                    {
                        row.SetSource(item);
                    }
                }
                else
                {
                    row = new GameNoteView()
                    {
                        Parent = this, Location = new Point(0, 0)
                    };

                    if (row.InvokeRequired)
                    {
                        row.Invoke(new Action <EasyRoom>((s) => row.SetSource(s)), item);
                    }
                    else
                    {
                        row.SetSource(item);
                    }
                }
                row.ConnectEvent += (r) => {
                    ConnectEvent?.Invoke(r, item);
                };
                row.WatchEvent += (r) => {
                    WatchEvent?.Invoke(r, item);
                };
                Rows.Add(row);
            };

            // обновляем список лобби при удалении записи (при отключении сервера / завершении игры на сервере)
            Notes.BeforeRemoveEvent += (item) => {
                row = new GameNoteView(item);
                for (int i = Rows.Count - 1; i > Rows.IndexOf(row); i--)
                {
                    if (Rows[i].Equals(row) == false)
                    {
                        Rows[i].Location = Rows[i - 1].Location;
                    }
                }
                Rows.Remove(row);
            };
        }
Esempio n. 3
0
        public GameView(EasyRoom room, string localPlayer, bool IsWatcher) : base()
        {
            Width      = 780;
            AutoScroll = true;
            Notes      = room.Players;
            lam s = () => { return(false); };

            Playerrows = new EList <PlayerNoteView>();

            for (int i = 0; i < room.Players.Count; i++)
            {
                s = () => { if (room.Players[i].Name == room.ActivePlayer)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            } };
                PlayerNoteView pl;
                if (i > 0)
                {
                    pl = new PlayerNoteView(room.Players[i], s())
                    {
                        Parent = this, Location = new Point(0, Playerrows.Last().Location.Y + 60)
                    };
                }
                else
                {
                    pl = new PlayerNoteView(room.Players[i], s())
                    {
                        Parent = this, Location = new Point(0, 0)
                    };
                }

                Playerrows.Add(pl);
            }

            /*foreach (EasyPlayer player in Notes)
             * {
             *  s = ()=> { if (player.Name == room.ActivePlayer) return true; else return false; };
             *  PlayerNoteView pl;
             *  if (player.Id > 1)
             *  {
             *      pl = new PlayerNoteView(player, s()) { Parent = this, Location = new Point(0, Playerrows.Last().Location.Y + 60) };
             *  }
             *  else
             *  {
             *      pl = new PlayerNoteView(player, s()) { Parent = this, Location = new Point(0, 0) };
             *  }
             *
             *  Playerrows.Add(pl);
             * }*/

            s = () => { if (room.ActivePlayer == localPlayer)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        } };

            RollButton = new Button()
            {
                Parent = this, Location = new Point(10, Playerrows.Last().Location.Y + 80), Size = new Size(200, 40), Text = "Roll", Enabled = s(), Visible = !IsWatcher
            };
            StopButton = new Button()
            {
                Parent = this, Location = new Point(220, Playerrows.Last().Location.Y + 80), Size = new Size(200, 40), Text = "Штап", Enabled = s(), Visible = !IsWatcher
            };

            RollButton.Click += (object sender, EventArgs e) => {
                ClickRoll?.Invoke();
            };

            StopButton.Click += (object sender, EventArgs e) => {
                ClickStop?.Invoke();
            };
        }