PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/Soutenance_finale/eradiKor/General/GameOver.cs

http://xe8tmw7c.googlecode.com/
C# | 237 lines | 188 code | 32 blank | 17 comment | 34 complexity | f1fed5060642ae8ec60f6750b1cf935c MD5 | raw file
Possible License(s): GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. namespace eradiKor.General
  10. {
  11. public class GameOver
  12. {
  13. #region Attribut
  14. private Dictionary<string, string> datas;
  15. private bool scoreSend;
  16. private string strErreur;
  17. private bool gagne;
  18. private int min = 0;
  19. private int sec = 0;
  20. #endregion
  21. #region Constructeur
  22. /// <summary>
  23. /// Constructeur d'un écran de GameOver/GameWin
  24. /// </summary>
  25. /// <param name="gagne">Le joueur a-t-il gagné ?</param>
  26. /// <param name="multi">La partie a-t-elle eu lieu en multijoueur ?</param>
  27. public GameOver(Structures.GameData datas, bool gagne, bool multi)
  28. {
  29. datas.Notifies.Clear();
  30. this.gagne = gagne;
  31. string titre;
  32. if (gagne)
  33. titre = "Vous avez gagné !";
  34. else
  35. titre = "Vous avez perdu :-(";
  36. //On écoute les événements web
  37. Kore.Datas.OnQueryDone += new Kore.Datas.WebEventHandler(Datas_OnQueryDone);
  38. if (multi)
  39. {
  40. this.scoreSend = true;
  41. this.strErreur = "Pas de publication de sKors en mode multijoueurs !";
  42. }
  43. else if (Kore.Datas.offline)
  44. {
  45. this.scoreSend = true;
  46. this.strErreur = "Mode hors ligne, publication de sKors impossible !";
  47. }
  48. else if (datas.Stats.Cheats)
  49. {
  50. this.scoreSend = true;
  51. this.strErreur = "Vous avez triché, votre sKor n'est pas pris en compte !";
  52. }
  53. else
  54. {
  55. datas.Notifies.Add(new eradiKor.Graphics.Notify(eradiKor.Graphics.NotifyType.InputBox, this.Dialog_ValidName, ushort.MaxValue, titre, "Indiquez votre pseudo pour figurer dans le classement en ligne :", new Point(datas.Window.Width / 2, datas.Window.Height * 5 / 6), datas));
  56. this.scoreSend = false;
  57. this.strErreur = " ";
  58. }
  59. //Calcul du temps de jeu
  60. int min = datas.Stats.TpsDeJeu / 60;
  61. //On ajoute au score final une partie de l'argent restant
  62. datas.Player.Score += datas.Player.Money / 20;
  63. //Création du dictionnaire contenant les statistiques
  64. this.datas = new Dictionary<string, string> {
  65. { "Votre sKor :", datas.Player.Score.ToString() },
  66. { "Nombre de vagues envoyées :", (datas.Vagues.actuelle + 1).ToString() },
  67. { "Temps de jeu :", min + " minute" + (min > 1 ? "s " : " ") + (datas.Stats.TpsDeJeu % 60) },
  68. { "Nombre de monstres tués :", datas.Stats.MonstersKilled.ToString() },
  69. { "Nombre de monstres écrasés :", datas.Stats.HammerKill.ToString() },
  70. { "Nombre de monstres non tués :", (datas.Stats.MonstersStarted - datas.Stats.MonstersKilled).ToString() },
  71. { "Nombre de tours construites :", datas.Stats.TowerBuilded.ToString() },
  72. { "Nombre de tours vendues :", datas.Stats.TowerSpended.ToString() },
  73. { "Codes triche activés ?", (datas.Stats.Cheats ? "Oui" : "Non") }
  74. };
  75. //On met ŕ jour le profil du joueur
  76. datas.Stats.exportToProfile(datas.Player.Score, gagne, multi, (datas.Map.Hash == "38F6B60B6352DE86DB3322F4BDB1B0D154EA90737E40003A5655C49E12D90C6B0AE5F1039E52D18F9DEDF4D4AD5F0059" ||
  77. datas.Map.Hash == "6EB7D6AB1667EDC6733C16F9C452D91024F6BC85D22EBDC18E08C79895CD4A4076FCAFF66CBB67ED416BBCBB95386CA5" ||
  78. datas.Map.Hash == "F49EB3C478A81E321C658279B06E54A4280BE3C3D04022828A048B27243846339E57B816FC72E774375A25D0AACD3CCC" ||
  79. datas.Map.Hash == "12051EE7DC73E8F581EF239AB2E5176A0CFB71186193EEC05689BE750C5314F641C5D97DBABBECA25BDD6E300F8B90D3" ||
  80. datas.Map.Hash == "98B3EA37FA52434B1D7E11CFB6A405CB9089016E455D9C377389C6384C15E52F513ADC7A53E4C3F6FFEC81E6EF885CC9" ||
  81. datas.Map.Hash == "45AE495A7BFCD1108A3F473559BB4BD5A0418603895381FA44737605AF63ACEF77391A5431006F39C480D6413A253AB7" ||
  82. datas.Map.Hash == "F9A7B5C0F8A799FDA69B8171F90225B594DDBA82466E3DA82EB2181312451517EADDAFE49CCB85AB73160B80EF9223B4" ||
  83. datas.Map.Hash == "53D2ED7C3A015B36204482541A50671E47E3211456F32022151AFDA10F39CB373E372D548BF2D382CCD389253553027A" ||
  84. datas.Map.Hash == "2A2872B4675897BA1E97F48FC432FA1D3D2359BEE56218E00D3F934FD083FC77BACCD4030F91F2290D0347EAA0BA14C0" ||
  85. datas.Map.Hash == "FF29A8ECD806EC545159EAECFFF81EF3A1FC4C3EECDD461D4FD2B0DE07CAF5D4C2AA240BAC6E55F591AE775E6167AA29" ||
  86. datas.Map.Hash == "85DC2B795C3D0D583264FAD106ACD9CA503943F85BB7CB75ED74C8790D9A0B7C6ECD48BD559ADD9BC72FC2FDF75DE3E2"));
  87. }
  88. #endregion
  89. #region Méthodes
  90. public void update(Structures.GameData datas, KeyboardState kb, double sec)
  91. {
  92. if (kb.IsKeyDown(Keys.Escape))
  93. {
  94. datas.Notifies.Clear();
  95. datas.Transition = new Fade(eradiKor.Structures.GameType.Menu, Screen.Main);
  96. }
  97. if (datas.Stats.TpsDeJeu == 0)
  98. datas.Stats.TpsDeJeu = (int)sec;
  99. }
  100. public void draw(Structures.GameData datas, Structures.Window window, MouseState mouse, SpriteBatch spritebatch, GameTime gametime, SpriteFont[,] fonts, Dictionary<string, Graphics.Texture> textures)
  101. {
  102. string tits = "Statistiques et sKor";
  103. //Affichage du fond
  104. if (gagne)
  105. { //FIXME PLACER ICI L'ÉCRAN GAGNÉ
  106. int w = window.Height * textures["gamewin"].Tex.Width / textures["gamewin"].Tex.Height;
  107. spritebatch.Draw(textures["gamewin"].Tex, new Rectangle(window.Width / 2 - w / 2, 0, w, window.Height), Color.White);
  108. tits = "Gagné ! Statistiques :";
  109. }
  110. else
  111. {
  112. int w = window.Height * textures["gameover"].Tex.Width / textures["gameover"].Tex.Height;
  113. spritebatch.Draw(textures["gameover"].Tex, new Rectangle(window.Width / 2 - w / 2, 0, w, window.Height), Color.White);
  114. tits = "Perdu... Statistiques :";
  115. }
  116. Vector2 tmp = fonts[1, 3].MeasureString(tits);
  117. tmp.X = datas.Window.Width / 2 - tmp.X / 2;
  118. tmp.Y = 10;
  119. spritebatch.DrawString(fonts[1, 3], tits, tmp, Color.LavenderBlush);
  120. //Coeffs de placement
  121. int w3 = window.Width / 3;
  122. int w4 = window.Width / 4;
  123. int h4 = window.Height / 5;
  124. //Affichage du résumé
  125. Rectangle resume = new Rectangle(w4, 70, w4 * 2, 3 * h4);
  126. spritebatch.Draw(textures["pixel"].Tex, resume, new Color(128, 128, 178, 128));
  127. int r23 = resume.Width * 3 / 4;
  128. int pxpInfo = resume.Height / (this.datas.Count + 1);
  129. tmp = fonts[0, 2].MeasureString(strErreur);
  130. tmp.X = resume.Center.X - tmp.X / 2;
  131. tmp.Y = resume.Y + pxpInfo / 2 - tmp.Y / 2;
  132. spritebatch.DrawString(fonts[0, 2], strErreur + " ", tmp, Color.Azure);
  133. Color colorfond;
  134. Rectangle fond = new Rectangle(resume.X + 25, resume.Y + 35, resume.Width * 7 / 8, pxpInfo - 2);
  135. Vector2 col1 = new Vector2(fond.X + 20, fond.Y + pxpInfo - tmp.Y / 3);
  136. Vector2 col2 = new Vector2(resume.X + r23, fond.Y + pxpInfo - tmp.Y / 3);
  137. int i = 1;
  138. foreach (KeyValuePair<string, string> stat in this.datas)
  139. {
  140. //On affiche la ligne de fond
  141. if (fond.Intersects(new Rectangle(mouse.X, mouse.Y, 1, 1)))
  142. colorfond = new Color(Color.LawnGreen, 140);
  143. else if (i % 2 == 1)
  144. colorfond = new Color(Color.LightCyan, 140);
  145. else
  146. colorfond = new Color(Color.LightBlue, 140);
  147. spritebatch.Draw(textures["pixel"].Tex, fond, colorfond);
  148. spritebatch.Draw(textures["degradeL"].Tex, new Rectangle(fond.X - 10, fond.Y, 10, fond.Height), colorfond);
  149. spritebatch.Draw(textures["degradeR"].Tex, new Rectangle(fond.Right, fond.Y, 10, fond.Height), colorfond);
  150. spritebatch.DrawString(fonts[0, 2], stat.Key, col1, Color.Cornsilk);
  151. spritebatch.DrawString(fonts[0, 2], stat.Value, col2, Color.Cornsilk);
  152. //On incrémente les variables
  153. fond.Y += pxpInfo;
  154. col1.Y += pxpInfo;
  155. col2.Y += pxpInfo;
  156. i++;
  157. }
  158. }
  159. #endregion
  160. #region Méthodes événementielle
  161. private void Datas_OnQueryDone(object sender, Kore.Events.WebEventArgs e)
  162. {
  163. this.strErreur = e.Details;
  164. }
  165. public PlayerWill GameOver_OnClick(object sender, eradiKor.Events.MouseEventArgs e)
  166. {
  167. //On revient au menu si les stats sont affichées
  168. if (scoreSend)
  169. return PlayerWill.Menu;
  170. else
  171. return PlayerWill.None;
  172. }
  173. public void GameOver_OnResize(object sender, eradiKor.Events.WindowEventArgs e)
  174. { }
  175. public bool Dialog_ValidName(Graphics.Notify notify, int button, object more)
  176. {
  177. if (notify.Type == eradiKor.Graphics.NotifyType.InputBox && button == 0)
  178. {
  179. //On commence par vérifier le nom indiqué
  180. Regex format_nom = new Regex("^[a-zA-Z0-9_@]{4,32}$");
  181. if (format_nom.IsMatch(notify.textbox.CurrentText))
  182. {
  183. this.strErreur = "";
  184. this.scoreSend = true;
  185. HTTP.Requetes skor = new HTTP.Requetes(Kore.Events.RequeteType.pubSkor, System.Reflection.Assembly.GetExecutingAssembly().FullName.Split(',')[1].Replace("Version=", "").Trim());
  186. skor.pubSkor("LEPASSICI", notify.textbox.CurrentText, ((Structures.GameData)more).Player.Score, ((Structures.GameData)more).Map.Hash, ((Structures.GameData)more).Vagues.actuelle, 1, ((Structures.GameData)more).Stats);
  187. notify.goToEnd();
  188. this.strErreur = "Publication de vos sKors en ligne ...";
  189. }
  190. else if (notify.textbox.CurrentText == "")
  191. {
  192. this.scoreSend = true;
  193. this.strErreur = "Vos sKors n'ont pas étés envoyés.";
  194. notify.goToEnd();
  195. }
  196. else
  197. {
  198. this.strErreur = "Votre pseudo ne correspond pas au format attendu !";
  199. }
  200. }
  201. return true;
  202. }
  203. #endregion
  204. }
  205. }