Esempio n. 1
0
        private void LoadResults()
        {
            var font = ResourceManager.Instance["fonts/bebas_neue"] as Font;
            List<string> lines = null;

            if (File.Exists(Game.BestResultsFileName))
            {
                lines = File.ReadAllLines(Game.BestResultsFileName, Encoding.UTF8).ToList();
                lines.RemoveAll(string.IsNullOrEmpty);
            }

            float yPos = 0;

            if (lines == null || lines.Count == 0)
            {
                _bestResults.Add(
                    CreateTextItem("Brak wyników!", font, 70, Game.Instance.Width / 2, Game.Instance.Height / 2));
                yPos = Game.Instance.Height / 2 + _bestResults.Last().GetGlobalBounds().Height + 60f;
            }
            else
            {
                _bestResults.Add(CreateTextItem("Nick - Czas", font, 40, Game.Instance.Width / 2, yPos));

                yPos = Game.Instance.Height / 2
                       - (lines.Count + 2) * (_bestResults.Last().GetGlobalBounds().Height + 20f) / 2;
                _bestResults.Last().Position = new Vector2f(Game.Instance.Width / 2, yPos);

                yPos += _bestResults.Last().GetGlobalBounds().Height + 45f;

                var count = 1;
                foreach (var line in lines)
                {
                    var splited = line.Split(':');

                    var time = string.Empty;
                    var timeSpan = TimeSpan.FromMilliseconds(Convert.ToDouble(splited[1]));

                    var minutes = (int)timeSpan.TotalMinutes;
                    var seconds = timeSpan.Seconds;

                    if (minutes != 0)
                    {
                        time += minutes + " minut" + GetOdmiana(minutes) + " ";
                    }

                    if (seconds != 0)
                    {
                        time += seconds + " sekund" + GetOdmiana(seconds);
                    }

                    time = time.Trim();

                    _bestResults.Add(
                        CreateTextItem(
                            count++ + ". " + splited[0] + " - " + time,
                            font,
                            40,
                            Game.Instance.Width / 2,
                            yPos));
                    yPos += _bestResults.Last().GetGlobalBounds().Height + 20f;
                }
            }

            _buttonBack = new Button("Wróć", font, 40, new Vector2f(Game.Instance.Width / 2, yPos + 45), 0.9f);
            _buttonBack.OnClick += (sender, args) => Game.Instance.StateMachine.PushState(new GameStateMenu());
        }
Esempio n. 2
0
        public void UpdateServers()
        {
            _showLoadingAnimation = true;
            _lobbies.ForEach(t => t.Dispose());
            _lobbies.Clear();
            SelectedLobbyId = -1;

            Game.Instance.Lobbies = GameClient.Instance.UpdateLobbyList();

            var startY = _shape.Position.Y - _shape.GetLocalBounds().Height / 2 + 50;
            var startX = _shape.Position.X - _shape.GetLocalBounds().Width / 2 + 40;

            foreach (var lobby in Game.Instance.Lobbies.Values)
            {
                var button =
                    new Button(
                        lobby.Name + " - " + lobby.CurrentNumberOfPlayers + "/" + lobby.MaxiumNumberOfPlayers,
                        ResourceManager.Instance["fonts/bebas_neue"] as Font,
                        30,
                        new Vector2f(startX, startY));
                button.Origin = new Vector2f(0, button.Origin.Y);
                button.IsAnimated = false;
                button.Data = lobby;

                button.OnClick += (sender, args) =>
                    {
                        SelectedLobbyId = ((sender as Button).Data as Lobby).Id;
                        _arrow.Position = new Vector2f(
                            _shape.Position.X - _shape.GetLocalBounds().Width / 2 + 10,
                            (sender as Button).Position.Y - (sender as Button).GetLocalBounds().Height / 2);
                    };

                startY += button.GetLocalBounds().Top + button.GetLocalBounds().Height + 5;
                _lobbies.Add(button);
            }

            _showLoadingAnimation = false;
        }