Пример #1
0
        /// <summary>
        /// Add a new score, wich will be sort in the array
        /// </summary>
        /// <param name="score"></param>
        /// <returns>New rank</returns>
        public int AddScore(ScoreLine newScoreLine)
        {
            int rank = ScoreLines.Length + 1;

            ScoreLine[] scoresForThisLevel = ScoreLines;

            for (int scoreLineIndex = 0; scoreLineIndex < scoresForThisLevel.Length; scoreLineIndex++)
            {
                ScoreLine currentLine = scoresForThisLevel[scoreLineIndex];

                // Beat it!
                if (newScoreLine.CompareTo(currentLine) >= 0)
                {
                    rank = scoreLineIndex;

                    ScoreLine last = null;
                    ScoreLine toReplace = newScoreLine;

                    // Move down the other lines
                    for (int i = scoreLineIndex; i < scoresForThisLevel.Length ; i++)
                    {
                        last = scoresForThisLevel[i];
                        scoresForThisLevel[i] = toReplace;

                        toReplace = last;
                    }

                    break;
                }
            }

            return rank;
        }
Пример #2
0
        public void Init(bool multiline)
        {
            // Partitions measures into their appropriate score lines
            if (multiline)
            {
                foreach (var measure in alignment.measures)
                {
                    if (measure.lineNumber >= scoreLines.Count)
                    {
                        scoreLines.Add(new ScoreLine());
                    }

                    scoreLines[measure.lineNumber].measures.Add(new ScoreLine.Measure(measure));
                }
            }
            else
            {
                var scoreLine = new ScoreLine();

                foreach (var measure in alignment.measures)
                {
                    scoreLine.measures.Add(new ScoreLine.Measure(measure));
                }

                scoreLines.Add(scoreLine);
            }
        }
Пример #3
0
    public override void Open(string value)
    {
        gameObject.SetActive(true);

        _orderButtons = new List <OrderButton> {
            NameButton, ScoreTotButton, TotQuizzButton
        };

        foreach (ScoreLine sl in _lines)
        {
            Destroy(sl.gameObject);
        }

        _lines = new List <ScoreLine>();

        string historyResponse = WebUtility.Instance.Get(LEADERBOARD_REQUEST);

        StringReader             reader  = new StringReader(historyResponse);
        JsonSerializer           ser     = JsonSerializer.Create(new JsonSerializerSettings());
        List <LeaderboardResult> results = new List <LeaderboardResult>();

        results = (List <LeaderboardResult>)ser.Deserialize(reader, typeof(List <LeaderboardResult>));

        for (int i = 0; i < results.Count; i++)
        {
            ScoreLine line = Instantiate(ScoreLinePrefab, SpawnRoot);
            line.Init(results[i].name, int.Parse(results[i].score), int.Parse(results[i].quiz));
            _lines.Add(line);
        }


        SelectTab(Tab.Name);
    }
Пример #4
0
        private void OnFinalScore(object source)
        {
            //get nick of player from dialog window
            NickWindow nickWindow = new NickWindow();

            nickWindow.ShowDialog();

            //get final score
            int score = (source as ScoreCounter).Score;

            //insert new line with score hisory
            ScoreLine scoreLine = new ScoreLine(score, nickWindow.Nick);

            _sortedScoreList.Add(score, scoreLine);

            //show sorted score history
            Children.Clear();
            Children.Add(_actualScoreText);
            var scoreList = _sortedScoreList.Values;

            for (int i = scoreList.Count - 1; i >= 0; i--)
            {
                Children.Add(scoreList[i]);
            }
        }
Пример #5
0
 /// <summary>
 /// Serialize the current instance and write the result into a specified XML writer.
 /// </summary>
 /// <param name="writer">The XML writer into which to write the serialized instance.</param>
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteStartElement("YachtStep");
     writer.WriteAttributeString("PlayerIndex", PlayerIndex.ToString());
     writer.WriteAttributeString("ScoreLine", ScoreLine.ToString());
     writer.WriteAttributeString("Score", Score.ToString());
     writer.WriteAttributeString("StepNumber", StepNumber.ToString());
 }
    void AddSignal(ArcadeRanking.Hiscore data, int puesto)
    {
        ScoreLine newSignal = Instantiate(scoreLineToInstatiate);

        newSignal.Init(puesto, data.username, data.hiscore);
        newSignal.transform.SetParent(hsicoresContainer);
        newSignal.transform.localScale = Vector3.one;
    }
Пример #7
0
        public Highscores(int scoreLinesNumer)
        {
            ScoreLines = new ScoreLine[scoreLinesNumer];

            for (int i = 0; i < ScoreLines.Length; i++)
            {
                ScoreLines[i] = new ScoreLine();
            }
        }
Пример #8
0
    private void UpdateScores()
    {
        foreach (string playerName in GameManager.GetPlayerScores().Keys)
        {
            GameObject scoreLineGO = Instantiate(scoreLinePrefab);
            scoreLineGO.transform.SetParent(scoreLineListParent);
            ScoreLine sl = (ScoreLine)scoreLineGO.GetComponent <ScoreLine>();

            if (sl != null)
            {
                PlayerScore p = GameManager.GetPlayerScore(playerName);
                sl.Setup(playerName, p.GetFrags(), p.GetDeaths());
            }

            scoreLineList.Add(scoreLineGO);
        }
    }
Пример #9
0
    void LoadHiscores(string fileName)
    {
        String[] arrLines = File.ReadAllLines(fileName);
        int      num      = 1;

        foreach (string line in arrLines)
        {
            string[] lines   = line.Split("_"[0]);
            Hiscore  hiscore = new Hiscore();
            hiscore.username = lines[0];
            hiscore.hiscore  = int.Parse(lines[1]);
            hiscores.Add(hiscore);

            if (hiscore.hiscore < Data.Instance.score && !yaAgrego)
            {
                yaAgrego = true;
                puesto   = num;
                if (num < 11)
                {
                    ScoreLine newScoreLine = Instantiate(scoreLineNewHiscore);
                    newScoreLine.Init(num, "XXX", Data.Instance.score);
                    newScoreLine.transform.SetParent(container);
                    newScoreLine.transform.localScale = Vector3.one;
                    num++;
                }
            }

            if (num < 11)
            {
                ScoreLine newScoreLine = Instantiate(scoreLine);
                newScoreLine.Init(num, hiscore.username, hiscore.hiscore);
                newScoreLine.transform.SetParent(container);
                newScoreLine.transform.localScale = Vector3.one;
            }

            num++;
        }
    }
Пример #10
0
    public void OnDone(HiscoresByMissions.MissionHiscoreData data)
    {
        int id = 0;

        if (data == null || data.all.Count == 0)
        {
            return;
        }
        foreach (HiscoresByMissions.MissionHiscoreUserData m in data.all)
        {
            ScoreLine newLine = Instantiate(scoreLine);
            newLine.transform.SetParent(container);
            newLine.transform.localPosition = Vector3.zero;
            newLine.transform.localScale    = Vector3.one;
            newLine.Init(id + 1, m.username, m.score);
            newLine.SetImage(m.userID);
            if (m.userID == UserData.Instance.userID)
            {
                MyScoreLoaded(m.score);
            }
            id++;
        }
    }
Пример #11
0
 /// <summary>
 /// Add a new score to the level scoreboard
 /// </summary>
 /// <param name="scoreLine"></param>
 /// <returns>The rank of the score</returns>
 public Int32 AddScore(String map, ScoreType scoreType, ScoreLine scoreLine)
 {
     return save.AddScore(map, scoreType, scoreLine);
 }
Пример #12
0
        /// <summary>
        /// Add a new score to the level scoreboard
        /// </summary>
        /// <param name="map">map name</param>
        /// <param name="scoreType"></param>
        /// <param name="newScoreLine"></param>
        /// <returns>The rank of the score</returns>
        public Int32 AddScore(String map, ScoreType scoreType, ScoreLine newScoreLine)
        {
            int rank = ScoreLineNumber + 1;

            bool replace = false;

            ScoreLine[] scoresForThisLevel = null;

            //Access to the score for this level and this mode
            SerializableDictionary<String, ScoreLine[]> score = null;

            if (ScoresBylevel.TryGetValue(scoreType, out score))
            {
                if (score.TryGetValue(map, out scoresForThisLevel))
                {
                    for (int scoreLineIndex = 0; scoreLineIndex < scoresForThisLevel.Length; scoreLineIndex++)
                    {
                        ScoreLine currentLine = scoresForThisLevel[scoreLineIndex];

                        //Look if scores in the top ScoreLineNumber lines
                        if (newScoreLine.Score > currentLine.Score)
                        {
                            replace = true;
                        }
                        else
                        {
                            if (newScoreLine.Score == currentLine.Score)
                            {
                                if (newScoreLine.Date > currentLine.Date)
                                {
                                    replace = true;
                                }
                            }
                        }

                        if (replace)
                        {
                            rank = currentLine.Rank;

                            //HACK Avoid corrupted savegames
                            if (rank == -1) rank = 20;

                            newScoreLine.Rank = rank;

                            ScoreLine last = null;
                            ScoreLine toReplace = newScoreLine;

                            //Move down new lines
                            for (int i = scoreLineIndex; i < scoresForThisLevel.Length - 1; i++)
                            {
                                last = scoresForThisLevel[i];
                                scoresForThisLevel[i] = toReplace;

                                toReplace = last;
                                toReplace.Rank += 1;
                            }

                            break;
                        }
                    }

                }
                else
                {
                    //Create scores data for this map
                    scoresForThisLevel = new ScoreLine[ScoreLineNumber];

                    for (int i = 0; i < scoresForThisLevel.Length; i++)
                    {
                        scoresForThisLevel[i] = ScoreLine.GetDefaultScoreLine(i + 1);
                    }

                    //Player has the best score
                    scoresForThisLevel[0] = newScoreLine;

                    ScoresBylevel[scoreType].Add(map, scoresForThisLevel);
                }
            }
            return rank;
        }
        private async void HandleFullInterrupt(List <IgsLine> currentLineBatch)
        {
            if (currentLineBatch.Count > 0)
            {
                if (currentLineBatch.Any(line => line.Code == IgsCode.Status))
                {
                    var infoLine = currentLineBatch.FirstOrDefault(ln => ln.Code == IgsCode.Info);
                    if (infoLine != null)
                    {
                        ScoreLine scoreLine = IgsRegex.ParseObservedScoreLine(infoLine);
                        if (scoreLine != null)
                        {
                            IgsGame gameInfo = this.GamesYouHaveOpened.FirstOrDefault(gi => gi.Info.IgsIndex == scoreLine.GameId);
                            if (gameInfo != null)
                            {
                                ScoreGame(gameInfo, scoreLine.BlackScore, scoreLine.WhiteScore);
                            }
                        }
                    }
                }
                if (currentLineBatch.Any(line => line.PureLine.EndsWith("accepted.") && line.Code == IgsCode.Info))
                {
                    // An outgoing match request has been accepted by another player and the game can begin.
                    GameHeading heading = this.Data.LastReceivedGameHeading;
                    var         ogi     = await Commands.GetGameByIdAsync(heading.GameNumber);

                    var  builder     = GameBuilder.CreateOnlineGame(ogi).Connection(this);
                    bool youAreBlack = ogi.Black.Name == _username;
                    bool youAreWhite = ogi.White.Name == _username;
                    if (youAreBlack)
                    {
                        builder.BlackPlayer(
                            new HumanPlayerBuilder(StoneColor.Black)
                            .Name(ogi.Black.Name)
                            .Rank(ogi.Black.Rank)
                            .Clock(new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(ogi.ByoyomiPeriod)).UpdateFrom(heading.BlackTimeRemaining))
                            .Build());
                    }
                    else
                    {
                        builder.BlackPlayer(
                            new IgsPlayerBuilder(StoneColor.Black, this)
                            .Name(ogi.Black.Name)
                            .Rank(ogi.Black.Rank)
                            .Clock(new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(ogi.ByoyomiPeriod)).UpdateFrom(heading.BlackTimeRemaining))
                            .Build());
                    }
                    if (youAreWhite)
                    {
                        builder.WhitePlayer(
                            new HumanPlayerBuilder(StoneColor.White)
                            .Name(ogi.White.Name)
                            .Rank(ogi.White.Rank)
                            .Clock(new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(ogi.ByoyomiPeriod)).UpdateFrom(heading.WhiteTimeRemaining))
                            .Build());
                    }
                    else
                    {
                        builder.WhitePlayer(
                            new IgsPlayerBuilder(StoneColor.White, this)
                            .Name(ogi.White.Name)
                            .Rank(ogi.White.Rank)
                            .Clock(new CanadianTimeControl(TimeSpan.Zero, 25, TimeSpan.FromMinutes(ogi.ByoyomiPeriod)).UpdateFrom(heading.WhiteTimeRemaining))
                            .Build());
                    }
                    IgsGame newGame = builder.Build();
                    this.GamesYouHaveOpened.Add(newGame);
                    Events.OnMatchRequestAccepted(newGame);
                }

                if (currentLineBatch.Any(line => line.PureLine.Contains("Creating match") && line.Code == IgsCode.Info))
                {
                    // Make it not be an interrupt and let it be handled by the match creator.
                    foreach (IgsLine line in currentLineBatch)
                    {
                        lock (this._mutex)
                        {
                            if (this._requestInProgress != null)
                            {
                                this._requestInProgress.IncomingLines.Post(line);
                            }
                            else
                            {
                                if (this.Composure == IgsComposure.Ok)
                                {
                                    Events.OnUnhandledLine(line.EntireLine);
                                }
                            }
                        }
                    }
                }

                if (currentLineBatch.Count == 3 && currentLineBatch[0].Code == IgsCode.SayInformation &&
                    currentLineBatch[1].Code == IgsCode.Say)
                {
                    int         gameNumber   = IgsRegex.ParseGameNumberFromSayInformation(currentLineBatch[0]);
                    ChatMessage chatLine     = IgsRegex.ParseSayLine(currentLineBatch[1], this);
                    IgsGame     relevantGame = this.GamesYouHaveOpened.Find(gi => gi.Info.IgsIndex == gameNumber);
                    if (relevantGame == null)
                    {
                        // We received a chat message for a game we no longer play.
                        return;
                    }
                    if (chatLine.Text.StartsWith(gameNumber + " "))
                    {
                        chatLine.Text = chatLine.Text.Substring((gameNumber + " ").Length);
                    }

                    GetConnector(relevantGame.Info).ChatMessageFromServer(chatLine);
                }

                if (currentLineBatch[0].Code == IgsCode.Kibitz &&
                    currentLineBatch.Count >= 2)
                {
                    // 11 Kibitz ([^ ]+).*\[([0-9]+)\]
                    Tuple <string, int> firstLine = IgsRegex.ParseKibitzHeading(currentLineBatch[0]);
                    string  text         = currentLineBatch[1].PureLine.Trim();
                    IgsGame relevantGame = this.GamesYouHaveOpened.Find(gi => gi.Info.IgsIndex == firstLine.Item2);
                    GetConnector(relevantGame.Info).ChatMessageFromServer(new ChatMessage(firstLine.Item1,
                                                                                          text, DateTimeOffset.Now, firstLine.Item1 == this.Username ? ChatMessageKind.Outgoing : ChatMessageKind.Incoming));
                }

                if (currentLineBatch[0].Code == IgsCode.Tell &&
                    currentLineBatch[0].PureLine.StartsWith("*SYSTEM*") &&
                    currentLineBatch[0].PureLine.EndsWith("requests undo."))
                {
                    string requestingUser = IgsRegex.WhoRequestsUndo(currentLineBatch[0]);
                    var    games          = GetGamesIncluding(requestingUser);
                    if (games.Any())
                    {
                        foreach (var game in games)
                        {
                            Events.OnUndoRequestReceived(game.Info);
                        }
                    }
                    else
                    {
                        throw new Exception("Received an undo request for a game that's not in progress.");
                    }
                    this._ignoreNextPrompt = true;
                }
                if (currentLineBatch[0].Code == IgsCode.Undo)
                {
                    int     numberOfMovesToUndo = currentLineBatch.Count(line => line.Code == IgsCode.Undo);
                    IgsLine gameHeadingLine     = currentLineBatch.Find(line => line.Code == IgsCode.Move);
                    int     game     = IgsRegex.ParseGameNumberFromHeading(gameHeadingLine);
                    IgsGame gameInfo = this.GamesYouHaveOpened.Find(gi => gi.Info.IgsIndex == game);
                    for (int i = 0; i < numberOfMovesToUndo; i++)
                    {
                        GetConnector(gameInfo.Info).ForceMainUndo();
                    }
                }

                if (currentLineBatch[0].EntireLine.Contains("'done'"))
                {
                    IgsLine gameHeadingLine = currentLineBatch.Find(line => line.Code == IgsCode.Move);
                    int     gameIndex       = IgsRegex.ParseGameNumberFromHeading(gameHeadingLine);
                    _availableConnectors[gameIndex].SetPhaseFromServer(GamePhaseType.LifeDeathDetermination);
                }
                if (currentLineBatch.Any(ln => ln.Code == IgsCode.Score))
                {
                    ScoreLine scoreLine = IgsRegex.ParseScoreLine(currentLineBatch.Find(ln => ln.Code == IgsCode.Score));
                    IgsGame   gameInfo  = this.GamesYouHaveOpened.Find(gi =>
                                                                       gi.Info.White.Name == scoreLine.White &&
                                                                       gi.Info.Black.Name == scoreLine.Black);
                    ScoreGame(gameInfo, scoreLine.BlackScore, scoreLine.WhiteScore);
                }
            }
        }
Пример #14
0
 public EditLinePopup(ScoreLine lineToEdit)
 {
     LineToEdit = lineToEdit;
     InitializeComponent();
     BindingContext = this;
 }
Пример #15
0
        public Score GetScore()
        {
            var result = new Score
            {
                TeamName         = new Dictionary <TeamSelection, string>(),
                CurrentSource    = new Dictionary <TeamSelection, int>(),
                GuaranteedSource = new Dictionary <TeamSelection, int>(),
                Rounds           = new List <ScorePerRound>()
            };
            var players = new Dictionary <Guid, PlayerWithGameCount>();

            InitialScore(result, TeamSelection.Team1, players);
            InitialScore(result, TeamSelection.Team2, players);

            var gameFinished = true;

            if (dataFile.Games != null)
            {
                for (var roundIndex = 0; roundIndex < dataFile.Basis.RoundCount; roundIndex++)
                {
                    var round       = dataFile.Games[roundIndex];
                    var roundResult = new ScorePerRound
                    {
                        Index = roundIndex,
                        Games = new List <ScoreLine>(),
                        Score = new Dictionary <TeamSelection, int>()
                    };
                    roundResult.Score.Add(TeamSelection.Team1, 0);
                    roundResult.Score.Add(TeamSelection.Team2, 0);
                    for (var gameIndex = 0; gameIndex < dataFile.Basis.GameCount; gameIndex++)
                    {
                        var game = round[gameIndex];
                        if (!game.IsFinished)
                        {
                            gameFinished = false;
                            continue;
                        }
                        var gameResult = new ScoreLine
                        {
                            Index      = gameIndex,
                            PlayerId   = game.PlayerIds,
                            PlayerName = new Dictionary <TeamSelection, string>()
                        };
                        gameResult.PlayerName.Add(TeamSelection.Team1, GetPlayer(TeamSelection.Team1, gameResult.PlayerId[TeamSelection.Team1]).Name);
                        gameResult.PlayerName.Add(TeamSelection.Team2, GetPlayer(TeamSelection.Team2, gameResult.PlayerId[TeamSelection.Team2]).Name);
                        gameResult.Winner = game.Winner;
                        roundResult.Games.Add(gameResult);
                        players[game.PlayerIds[TeamSelection.Team1]].Played++;
                        players[game.PlayerIds[TeamSelection.Team2]].Played++;
                        if (gameResult.Winner == TeamSelection.Team1)
                        {
                            players[game.PlayerIds[TeamSelection.Team1]].Won++;
                            players[game.PlayerIds[TeamSelection.Team2]].Lost++;
                            roundResult.Score[TeamSelection.Team1]++;
                        }
                        else
                        {
                            players[game.PlayerIds[TeamSelection.Team2]].Won++;
                            players[game.PlayerIds[TeamSelection.Team1]].Lost++;
                            roundResult.Score[TeamSelection.Team2]++;
                        }
                    }
                    if (roundResult.Games.Count > 0)
                    {
                        result.Rounds.Add(roundResult);
                    }
                }
            }

            var notOrderedPlayers = new List <PlayerWithGameCount>(players.Values);

            foreach (var round in result.Rounds)
            {
                result.CurrentSource[TeamSelection.Team1] += round.Score[TeamSelection.Team1];
                result.CurrentSource[TeamSelection.Team2] += round.Score[TeamSelection.Team2];
            }
            foreach (var player in notOrderedPlayers)
            {
                if (player.MaxAttending == 0)
                {
                    continue;
                }

                var pass = player.Played - player.MaxAttending;
                if (pass > 0)
                {
                    player.PlayedAboveMaxAttending     = pass;
                    result.CurrentSource[player.Team] -= pass;
                }
            }
            result.GuaranteedSource.Add(TeamSelection.Team1, result.CurrentSource[TeamSelection.Team1]);
            result.GuaranteedSource.Add(TeamSelection.Team2, result.CurrentSource[TeamSelection.Team2]);
            foreach (var player in notOrderedPlayers)
            {
                if (player.MinAttending == 0)
                {
                    continue;
                }

                var pass = player.MinAttending - player.Played;
                if (pass > 0)
                {
                    player.PlayedBelowMinAttending        = pass;
                    result.GuaranteedSource[player.Team] -= pass;
                }
            }

            if (gameFinished)
            {
                result.CurrentSource    = result.GuaranteedSource;
                result.GuaranteedSource = null;
            }

            result.Players = notOrderedPlayers.OrderBy(i => i.Team).ThenByDescending(i => i.Played).ThenByDescending(i => i.Won).ToList();
            return(result);
        }
        /// <summary>
        /// Draw a map with points for each level, and way between them
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="Game"></param>
        public void Draw(TGPASpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            //Background
            spriteBatch.Draw(background, new Rectangle(0, 0, TGPAContext.Instance.ScreenWidth, TGPAContext.Instance.ScreenHeight), null, Color.White);

            Rectangle LastLevelDst = Rectangle.Empty;

            //Draw levels and a way between them
            for (int i = 0; i < WorldCount; i++)
            {
                //The player need to have unlocked the level to display it
                Rectangle levelDst = Rectangle.Empty;
                if ((i <= TGPAContext.Instance.Saver.SaveData.LastLevel) && (i < WorldCount))
                {
                    Vector2 loc = levelPositionOnMap[i];
                    levelDst = new Rectangle(
                        (int)loc.X - levelSrc.Width / 2,
                        (int)loc.Y - levelSrc.Height / 2,
                        levelSrc.Width,
                        levelSrc.Height
                        );

                    Color levelColor = Color.White;
                    Color blinkColor = Color.Gray * alphaColorForLevelBlinking;

                    if ((selectedIndex == i) & (!shipIsMoving))
                    {
                        levelColor = Color.Red;
                        blinkColor = Color.OrangeRed * 0.0f;
                    }
                    else if (pointedIndex == i)
                    {
                        levelColor = Color.SpringGreen;
                        blinkColor = Color.White * 0.0f;
                    }
                    else if (i == TGPAContext.Instance.Saver.SaveData.LastLevel)
                    {
                        blinkColor = Color.PaleVioletRed * alphaColorForLevelBlinking;
                    }
                    spriteBatch.Draw(buttons, levelDst, levelSrc, levelColor);
                    spriteBatch.Draw(buttons, levelDst, levelSrc, blinkColor);

                    //Draw the way
                    if (i > 0)
                    {
                        Vector2 p1             = levelPositionOnMap[i - 1];
                        Vector2 p2             = pointsBezier[i - 1][0];
                        Vector2 p3             = pointsBezier[i - 1][1];
                        Vector2 p4             = levelPositionOnMap[i];
                        int     requiredPoints = (int)(Math.Sqrt(Math.Pow(p4.X - p1.X, 2) + Math.Pow(p4.Y - p1.Y, 2)) / 50) + 2; //evaluate number of point to show depending of the distance between p1 an p4

                        Rectangle wayDst = waySrc;

                        for (int x = 1; x < requiredPoints; x++)
                        {
                            float t = (float)x / (float)(requiredPoints); //quadratic bezier equation need a parameter t, with 0<=t<=1
                            if (t <= 1)
                            {
                                wayDst.X = (int)((Math.Pow(1 - t, 3)) * p1.X + 3 * (Math.Pow(1 - t, 2)) * t * p2.X + 3 * (1 - t) * t * t * p3.X + t * t * t * p4.X) - wayDst.Width / 2;
                                wayDst.Y = (int)((Math.Pow(1 - t, 3)) * p1.Y + 3 * (Math.Pow(1 - t, 2)) * t * p2.Y + 3 * (1 - t) * t * t * p3.Y + t * t * t * p4.Y) - wayDst.Height / 2;

                                spriteBatch.Draw(buttons, wayDst, waySrc, Color.White, 0.0f, new Vector2(waySrc.Width / 2, waySrc.Height / 2), SpriteEffects.None, 1.0f);
                            }
                        }
                    }
                }
            }

            //Draw little ship
            spriteBatch.Draw(buttons, shipDst, shipSrc, Color.White, 0.0f, Vector2.Zero, shipFlip, 1.0f);

            //Draw selected world information

            Vector2 v = levelPositionOnMap[selectedIndex];

            Color whiteColor = Color.White * alphaPostIt;

            spriteBatch.Draw(buttons, postitDst, postitSrc, whiteColor);

            //Play and back Buttonfor PC
            if (TGPAContext.Instance.Player1.IsPlayingOnWindows())
            {
                //Launch game
                if (focus == LevelSelectionScreenButton.Play)
                {
                    Rectangle srcBis = arrowSrc;
                    srcBis.Y += srcBis.Height;
                    spriteBatch.Draw(buttons, playDst, srcBis, whiteColor, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 1.0f);
                }
                else
                {
                    spriteBatch.Draw(buttons, playDst, arrowSrc, whiteColor, 0.0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 1.0f);
                }

                //Back
                if (focus == LevelSelectionScreenButton.Back)
                {
                    Rectangle srcBis = arrowSrc;
                    srcBis.Y += srcBis.Height;
                    spriteBatch.Draw(buttons, backDst, srcBis, whiteColor);
                }
                else
                {
                    spriteBatch.Draw(buttons, backDst, arrowSrc, whiteColor);
                }
            }

            spriteBatch.End();

            //Play and back text for PC
            if (TGPAContext.Instance.Player1.IsPlayingOnWindows())
            {
                if (alphaPostIt > 0.8f)
                {
                    playDst.X = 290;
                    playDst.Y = 485;

                    backDst.X = 90;
                    backDst.Y = 555;

                    string playText = "Play";
                    string backText = "Back to title";

                    TGPAContext.Instance.TextPrinter.Color = Color.Navy;
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, playDst.X - (playText.Length * 12), playDst.Y + 5, playText);
                    TGPAContext.Instance.TextPrinter.Color = Color.Red;
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, backDst.X + backDst.Width, backDst.Y + 5, backText);
                    TGPAContext.Instance.TextPrinter.Color = Color.Black;
                }
            }

            TGPAContext.Instance.TextPrinter.Color = (Color.Black * alphaPostIt);

            TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 20, postitDst.Y + 100, "Level " + overview.Level);
            TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 20, postitDst.Y + 130, overview.Name);

            TGPAContext.Instance.TextPrinter.Size = 0.8f;

            for (int i = 0; i < this.levelParts.Length; i++)
            {
                TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 170 + (80 * i), LocalizedStrings.GetString("LevelSelectionScreenPart") + " " + i + " - " + LocalizedStrings.GetString("LevelSelectionScreenBestScore"));

                ScoreLine bestScore = TGPAContext.Instance.Saver.GetBestScoreForLevel(this.levelParts[i], this.scoreType);
                if (bestScore.Score > 0)
                {
                    TGPAContext.Instance.TextPrinter.Color = (Color.Blue * alphaPostIt);
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 190 + (80 * i), bestScore.ToString());
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 105, postitDst.Y + 210 + (80 * i), bestScore.GetDifficultyString());
                }
                else
                {
                    TGPAContext.Instance.TextPrinter.Color = (Color.Red * alphaPostIt);
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, postitDst.X + 25, postitDst.Y + 190 + (80 * i), LocalizedStrings.GetString("LevelSelectionScreenNoHighscore"));
                }

                TGPAContext.Instance.TextPrinter.Color = (Color.Black * alphaPostIt);
            }

            TGPAContext.Instance.TextPrinter.Color = Color.Black;
            TGPAContext.Instance.TextPrinter.Size  = 1f;


            if (launchLevel == false)
            {
                //Buttons
                //***************************************************************************
                if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false)
                {
                    TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Move", TGPAContext.Instance.Player1.Device.Type, 535, 630);
                    TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Confirm", TGPAContext.Instance.Player1.Device.Type, 535, 700);
                    TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Cancel", TGPAContext.Instance.Player1.Device.Type, 150, 630);

                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, 595, 650, LocalizedStrings.GetString("LevelSelectionScreenMove"));
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, 595, 700, LocalizedStrings.GetString("LevelSelectionScreenPressA"));
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, 205, 650, LocalizedStrings.GetString("LevelSelectionScreenPressB"));
                }

                TGPAContext.Instance.TextPrinter.Write(spriteBatch, 170, 700, LocalizedStrings.GetString(this.scoreType == ScoreType.Single ? "SwitchToScoreTypeCoop" : "SwitchToScoreTypeSingle"));
                TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Plus", TGPAContext.Instance.Player1.Device.Type, 115, 690);
            }

            if (fadeoutAlpha > 0f)
            {
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                spriteBatch.Draw(background, new Rectangle(0, 0, TGPAContext.Instance.ScreenWidth, TGPAContext.Instance.ScreenHeight), null, (Color.Black * fadeoutAlpha));
                spriteBatch.End();
            }

            if (launchLevel)
            {
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                spriteBatch.Draw(TGPAContext.Instance.HudTex, rectDst, TGPAContext.Instance.PaperRect, Color.White);
                spriteBatch.End();


                TGPAContext.Instance.TextPrinter.Write(spriteBatch, rectDst.X + 50, rectDst.Y + 60, LocalizedStrings.GetString("Difficulty"));

                difficultyListControl.Draw(spriteBatch);

                TGPAContext.Instance.TextPrinter.Size = 0.8f;
                TGPAContext.Instance.TextPrinter.Write(spriteBatch, rectDst.X + 40, rectDst.Y + 125, LocalizedStrings.GetString((Difficulty)this.difficultyListControl.FocusedElement.Value + "Desc"), 50);
                TGPAContext.Instance.TextPrinter.Size = 1f;

                TGPAContext.Instance.TextPrinter.Color = Color.White;
                TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Back", TGPAContext.Instance.Player1.Device.Type, 350, 550);
                TGPAContext.Instance.TextPrinter.Write(spriteBatch, 400, 560, LocalizedStrings.GetString("CancelLaunchLevel"));
                TGPAContext.Instance.TextPrinter.Color = Color.Black;
            }
        }
Пример #17
0
        public void Draw(TGPASpriteBatch spriteBatch)
        {
            if (playersOut)
            {
                if (fadeOut > 0f)
                {
                    Color backscreen;

                    if (victory)
                    {
                        backscreen = (Color.White * this.fadeOut);
                    }
                    else
                    {
                        backscreen = (Color.Black * this.fadeOut);
                    }
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                    spriteBatch.Draw(TGPAContext.Instance.NullTex, new Rectangle(0, 0, TGPAContext.Instance.ScreenWidth, TGPAContext.Instance.ScreenHeight), backscreen);
                    spriteBatch.End();
                }

                //Level
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                spriteBatch.Draw(TGPAContext.Instance.HudTex, levelDst, TGPAContext.Instance.PaperRect, Color.White * (this.fadeOut + 0.1f));
                spriteBatch.End();

                String toPrint = "Level : " + TGPAContext.Instance.Map.Level;
                int    w       = 20 + toPrint.Length * 11;
                TGPAContext.Instance.TextPrinter.Write(spriteBatch, levelDst.X + (levelDst.Width / 2) - w / 2, levelDst.Y + (levelDst.Height / 4), toPrint, 512);

                toPrint = TGPAContext.Instance.Map.Name;
                w       = 20 + toPrint.Length * 11;
                TGPAContext.Instance.TextPrinter.Write(spriteBatch, levelDst.X + (levelDst.Width / 2) - w / 2, levelDst.Y + (levelDst.Height / 2), TGPAContext.Instance.Map.Name, 512);

                //Score
                #region Score compute
                if (playersOut)
                {
                    scoreDst.X = TGPAContext.Instance.ScreenWidth / 2 - scoreDst.Width / 2;

                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                    spriteBatch.Draw(sprites, scoreDst, scoreSrc, Color.White);
                    spriteBatch.End();

                    double duree = (elapsedGameTime - startGameTime);
                    int    h     = (int)((duree / 1000) / 3600);
                    int    m     = (int)(((duree / 1000) / 60) % 60);
                    int    s     = (int)((duree / 1000) % 60);

                    if (!victory)
                    {
                        TGPAContext.Instance.TextPrinter.Color = Color.Red;
                    }

                    if (cheat)
                    {
                        TGPAContext.Instance.TextPrinter.Color = Color.Silver;
                    }


                    int x    = 137;
                    int xbis = 337;
                    int y    = 212;

                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, x, y, LocalizedStrings.GetString("EndlevelScreenElapsedTime") + " : ");

                    TGPAContext.Instance.TextPrinter.Color = Color.Black;

                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, xbis, 240, h.ToString("00") + "h" + m.ToString("00") + "m" + s.ToString("00") + "s");

                    if ((victory) && (!cheat))
                    {
                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, x, scoreDst.Y + 150, LocalizedStrings.GetString("EndlevelScreenRemainingLives") + " :");

                        //Display heart icons or just a heart and a number
                        if (displayedLives < 6)
                        {
                            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

                            for (int i = 0; i < displayedLives; i++)
                            {
                                Rectangle heartDst = new Rectangle(x + i * (heartSrc.Width / 2), scoreDst.Y + 180, heartSrc.Width, heartSrc.Height);
                                spriteBatch.Draw(sprites, heartDst, heartSrc, Color.White);
                            }

                            spriteBatch.End();
                        }
                        else
                        {
                            Rectangle heartDst = new Rectangle(x, scoreDst.Y + 180, heartSrc.Width, heartSrc.Height);

                            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                            spriteBatch.Draw(sprites, heartDst, heartSrc, Color.White);
                            spriteBatch.End();

                            TGPAContext.Instance.TextPrinter.Color = Color.DarkMagenta;
                            TGPAContext.Instance.TextPrinter.Write(spriteBatch, heartDst.Right + 10, heartDst.Center.Y, " x " + displayedLives, 128);
                            TGPAContext.Instance.TextPrinter.Color = Color.Black;
                        }


                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, xbis, scoreDst.Y + 179, totalLives.ToString("0000000 pts"));

                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, x, scoreDst.Y + 238, LocalizedStrings.GetString("EndlevelScreenRemainingBombs") + " :");

                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                        for (int i = 0; i < displayedBombs; i++)
                        {
                            Rectangle bombDst = new Rectangle(x + i * (bombSrc.Width / 2), scoreDst.Y + 265, bombSrc.Width, bombSrc.Height);
                            spriteBatch.Draw(sprites, bombDst, bombSrc, Color.White);
                        }
                        spriteBatch.End();

                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, xbis, scoreDst.Y + 270, totalBombs.ToString("0000000 pts"));

                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, x, scoreDst.Y + 325, LocalizedStrings.GetString("EndlevelScreenLevelPoints") + " : ");

                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, xbis, scoreDst.Y + 355, score.ToString("0000000 pts"));

                        if (scoreOK)
                        {
                            TGPAContext.Instance.TextPrinter.Color = Color.Blue;
                            TGPAContext.Instance.TextPrinter.Write(spriteBatch, x, scoreDst.Y + 380, "Supertotal : ");
                            TGPAContext.Instance.TextPrinter.Write(spriteBatch, xbis - 40, scoreDst.Y + 410, scoreTotal.ToString("0000000000 pts"));
                            TGPAContext.Instance.TextPrinter.Color = Color.Black;
                        }
                    }
                }
                #endregion

                #region Highscore
                if (highscoreOK)
                {
                    int xHighscoreOK = 480;

                    TGPAContext.Instance.TextPrinter.Size = 0.9f;

                    String mode = this.scoreTypeDisplay == ScoreType.Single ? "Mode1P" : "Mode2P";
                    TGPAContext.Instance.TextPrinter.Write(spriteBatch, xHighscoreOK + 65, scoreDst.Y + 90, "(" + LocalizedStrings.GetString(mode) + ")");

                    if (cheat)
                    {
                        TGPAContext.Instance.TextPrinter.Color = Color.Red;
                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, xHighscoreOK + 65, scoreDst.Y + 120, "Cheats ON (no score)");
                        TGPAContext.Instance.TextPrinter.Color = Color.Black;
                    }

                    for (int i = 0; i < 7; i++)
                    {
                        if ((scoreRank == (i + 1)) && (this.scoreTypeSave == this.scoreTypeDisplay))
                        {
                            TGPAContext.Instance.TextPrinter.Color = Color.Green;
                        }

                        SerializableDictionary <string, ScoreLine[]> scoreDictionnary;

                        if (TGPAContext.Instance.Saver.SaveData.ScoresBylevel.TryGetValue(this.scoreTypeDisplay, out scoreDictionnary))
                        {
                            ScoreLine[] scoreLines;

                            if (scoreDictionnary.TryGetValue(TGPAContext.Instance.CurrentMap, out scoreLines))
                            {
                                TGPAContext.Instance.TextPrinter.Write(spriteBatch, xHighscoreOK + 65, scoreDst.Y + 150 + (i * 30), (i + 1) + ". " + scoreLines[i].ToString());
                            }
                        }
                        else
                        {
                            TGPAContext.Instance.Saver.AddScore(TGPAContext.Instance.CurrentMap, this.scoreTypeDisplay, ScoreLine.GetDefaultScoreLine(1));
                        }

                        if (scoreRank == (i + 1))
                        {
                            TGPAContext.Instance.TextPrinter.Color = Color.Black;
                        }
                    }

                    TGPAContext.Instance.TextPrinter.Size = 1f;

                    //Buttons
                    //***************************************************************************
                    if (highscoreOK)
                    {
                        TGPAContext.Instance.TextPrinter.Color = Color.LightSalmon;
                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, 600, this.scoreDst.Bottom - 65, LocalizedStrings.GetString(this.scoreTypeDisplay == ScoreType.Single ? "SwitchToScoreTypeCoop" : "SwitchToScoreTypeSingle"));
                        TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Plus", TGPAContext.Instance.Player1.Device.Type, 550, this.scoreDst.Bottom - 70);

                        if (victory)
                        {
                            TGPAContext.Instance.TextPrinter.Color = Color.Black;
                        }
                        else
                        {
                            TGPAContext.Instance.TextPrinter.Color = Color.White;
                        }

                        TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Back", TGPAContext.Instance.Player1.Device.Type, 150, 700);
                        if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false)
                        {
                            TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Cancel", TGPAContext.Instance.Player1.Device.Type, 200, 700);
                        }
                        TGPAContext.Instance.ButtonPrinter.Draw(spriteBatch, "#Confirm", TGPAContext.Instance.Player1.Device.Type, 550, 700);

                        if (victory)
                        {
                            TGPAContext.Instance.TextPrinter.Write(spriteBatch, 600, 700, LocalizedStrings.GetString("EndlevelScreenPressAcontinue"));
                        }
                        else
                        {
                            TGPAContext.Instance.TextPrinter.Write(spriteBatch, 600, 700, LocalizedStrings.GetString("EndlevelScreenPressAretry"));
                        }
                        TGPAContext.Instance.TextPrinter.Write(spriteBatch, 245, 700, LocalizedStrings.GetString("EndlevelScreenPressB"));

                        TGPAContext.Instance.TextPrinter.Color = Color.Black;
                    }
                }
                #endregion
            }
        }
Пример #18
0
 private void OnEditLineRequested(ScoreLine line)
 => EditLineRequested?.Invoke(this, new EditLineEventArgs {
     LineToEdit = line
 });