PageRenderTime 68ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/BoxJumpV2.0/BoxJumpV2.0/Form1.Designer.cs

https://gitlab.com/JoshuaWright/BoxJump-V2.0
C# | 395 lines | 335 code | 45 blank | 15 comment | 20 complexity | 810640766896bbda13ed7a5d1dd951d8 MD5 | raw file
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4. using BoxJumpDLL;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System;
  8. using System.Reflection;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. namespace BoxJumpV2_0
  12. {
  13. partial class Form1
  14. {
  15. /// <summary>
  16. /// Required designer variable.
  17. /// </summary>
  18. private System.ComponentModel.IContainer components = null;
  19. /// <summary>
  20. /// Clean up any resources being used.
  21. /// </summary>
  22. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  23. protected override void Dispose(bool disposing)
  24. {
  25. if (disposing && (components != null)) {
  26. components.Dispose();
  27. }
  28. base.Dispose(disposing);
  29. }
  30. private void DrawAllEnemys(Graphics g)
  31. {
  32. foreach (Enemy e in enemys) {
  33. e.Draw(g);
  34. }
  35. }
  36. private void DrawAllClouds(Graphics g)
  37. {
  38. foreach (Cloud c in clouds) {
  39. c.Draw(g);
  40. }
  41. }
  42. private void DrawBackGround_MidDay(Graphics g)
  43. {
  44. using (Brush brush = new LinearGradientBrush(this.ClientRectangle,
  45. Color.DeepSkyBlue,
  46. Color.SkyBlue,
  47. 90F)) {
  48. g.FillRectangle(brush, ClientRectangle);
  49. }
  50. using (Brush brush = new SolidBrush(Color.Green)) {
  51. g.FillRectangle(brush,
  52. new Rectangle(new Point(0, 313), new Size(529, 55)));
  53. }
  54. using (Pen pen = new Pen(Color.Black, 1)) {
  55. g.DrawLine(pen,
  56. new Point(0, 313),
  57. new Point(527, 313));
  58. }
  59. sun.MidDay();
  60. sun.reDraw(g);
  61. }
  62. private void DrawBackGround_EndDay(Graphics g)
  63. {
  64. using (Brush brush = new LinearGradientBrush(this.ClientRectangle,
  65. Color.Red,
  66. Color.Orange,
  67. 90F)) {
  68. g.FillRectangle(brush, ClientRectangle);
  69. }
  70. using (Brush brush = new SolidBrush(Color.Green)) {
  71. g.FillRectangle(brush,
  72. new Rectangle(new Point(0, 313), new Size(528, 55)));
  73. }
  74. using (Pen pen = new Pen(Color.Black, 1)) {
  75. g.DrawLine(pen,
  76. new Point(0, 313),
  77. new Point(527, 313));
  78. }
  79. sun.EndDay();
  80. sun.reDraw(g);
  81. }
  82. private void DrawBackGround_Night(Graphics g)
  83. {
  84. using (Brush brush = new LinearGradientBrush(this.ClientRectangle,
  85. Color.Black,
  86. Color.DarkBlue,
  87. 100F)) {
  88. g.FillRectangle(brush, ClientRectangle);
  89. }
  90. using (Brush brush = new SolidBrush(Color.Green)) {
  91. g.FillRectangle(brush,
  92. new Rectangle(new Point(0, 313), new Size(528, 55)));
  93. }
  94. using (Pen pen = new Pen(Color.Black, 1)) {
  95. g.DrawLine(pen,
  96. new Point(0, 313),
  97. new Point(527, 313));
  98. }
  99. moon.reDraw(g);
  100. }
  101. private void Game_Menu(object sender, PaintEventArgs e)
  102. {
  103. menuBt.ForeColor = backBt.ForeColor = changeTimeBt.ForeColor =
  104. aboutBt.ForeColor = textColor = Color.Black;
  105. if (BackGrounds[backGroundChoice] == DrawBackGround_Night) {
  106. menuBt.ForeColor = backBt.ForeColor = changeTimeBt.ForeColor =
  107. aboutBt.ForeColor = textColor = Color.Lime;
  108. Cloud.TimeOfDay = 2;
  109. }
  110. else if(BackGrounds[backGroundChoice] == DrawBackGround_EndDay) {
  111. Cloud.TimeOfDay = 1;
  112. }
  113. else {
  114. Cloud.TimeOfDay = 0;
  115. }
  116. BackGrounds[backGroundChoice](e.Graphics);
  117. using (Brush brush = new SolidBrush(textColor)) {
  118. e.Graphics.DrawString("BoxJump v2.0\n",
  119. new Font(FontFamily.GenericSansSerif, 22, FontStyle.Bold),
  120. brush, new Point(150, 100));
  121. }
  122. }
  123. private void Game_About(object sender, PaintEventArgs e)
  124. {
  125. BackGrounds[backGroundChoice](e.Graphics);
  126. using (Brush brush = new SolidBrush(textColor)) {
  127. e.Graphics.DrawString("Author: \tJoshua Wright\n" +
  128. "Contact: \tjoshuawright1197@gmail.com\n" +
  129. "Date: \t\t2016-11-14",
  130. new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold), brush
  131. , new Point(120, 100));
  132. }
  133. }
  134. private void Game_Started(object sender, PaintEventArgs e)
  135. {
  136. foreach (PerformPaints fp in PaintActions) {
  137. fp(e.Graphics);
  138. }
  139. using (Brush brush = new SolidBrush(textColor)) {
  140. e.Graphics.DrawString("SCORE: " + score * 10,
  141. new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold),
  142. brush, new Point(10, 10));
  143. }
  144. }
  145. private void GameInProgress(object sender, EventArgs e)
  146. {
  147. enemys.RemoveAll(x => x.isActive() == false);
  148. clouds.RemoveAll(x => x.isActive() == false);
  149. score += Enemy.HavePassed;
  150. if(Generate.Next(1,500) == 3 && backGroundChoice == 0) {
  151. clouds.Add(new Cloud());
  152. }
  153. if (Generate.Next(1, 20) == 1 &&
  154. GameTime.Elapsed.TotalSeconds - SpanTime >= Enemy.MinSpanTimeDelaySeconds) {
  155. enemys.Add(new Enemy());
  156. SpanTime = Convert.ToInt32(GameTime.Elapsed.TotalSeconds);
  157. Debug.WriteLine("AT ENEMY GENERATON");
  158. }
  159. foreach (Enemy ee in enemys.FindAll(x => x.CurrentLocation.X <= 150)) {
  160. if (player.Hit(ee)) {
  161. isMenu = true;
  162. enemys.Clear();
  163. clouds.Clear();
  164. if (score * 10 > Player.HighScore)
  165. Player.HighScore = score * 10;
  166. score = 0;
  167. this.Paint += Game_Over;
  168. timer.Stop();
  169. Started = false;
  170. menuBt.Visible = true;
  171. GameTime.Reset();
  172. Enemy.HavePassed = 0;
  173. Debug.WriteLine("==================");
  174. isMenu = false;
  175. break;
  176. }
  177. }
  178. Refresh();
  179. }
  180. private void Game_Over(object sender, PaintEventArgs e)
  181. {
  182. BackGrounds[backGroundChoice](e.Graphics);
  183. using (Brush brush = new SolidBrush(textColor)) {
  184. e.Graphics.DrawString(" GAME OVER\nHIGHT SCORE:" + Player.HighScore,
  185. new Font(FontFamily.GenericSansSerif, 18, FontStyle.Bold), brush
  186. , new Point(150, 100));
  187. }
  188. }
  189. private void ChangeTimebt_click(object sender, EventArgs e)
  190. {
  191. backGroundChoice++;
  192. if (backGroundChoice > 2)
  193. backGroundChoice = 0;
  194. Refresh();
  195. }
  196. private void Aboutbt_click(object sender, EventArgs e)
  197. {
  198. Paint += Game_About;
  199. changeTimeBt.Visible = false;
  200. aboutBt.Visible = false;
  201. backBt.Visible = true;
  202. isMenu = true;
  203. Refresh();
  204. }
  205. private void Backbt_click(object sender, EventArgs e)
  206. {
  207. Paint += Game_Menu;
  208. backBt.Visible = false;
  209. changeTimeBt.Visible = true;
  210. aboutBt.Visible = true;
  211. isMenu = false;
  212. Refresh();
  213. }
  214. private void Menubt_click(object sender, EventArgs e)
  215. {
  216. Paint += Game_Menu;
  217. menuBt.Visible = false;
  218. changeTimeBt.Visible = true;
  219. aboutBt.Visible = true;
  220. Refresh();
  221. }
  222. private void InitializeComponent2()
  223. {
  224. Started = false;
  225. isJumping = false;
  226. backGroundChoice = 0;
  227. score = 0;
  228. gameFont = new Font(FontFamily.GenericSansSerif, 18, FontStyle.Bold);
  229. DoubleBuffered = true;
  230. isMenu = false;
  231. Paint += Game_Menu;
  232. GameTime = new Stopwatch();
  233. timer = new System.Windows.Forms.Timer();
  234. timer.Interval = 1;
  235. timer.Tick += GameInProgress;
  236. enemys = new List<Enemy>();
  237. PaintActions = new List<PerformPaints>();
  238. BackGrounds = new List<PerformPaints>();
  239. clouds = new List<Cloud>();
  240. Generate = new Random();
  241. moon = new Moon();
  242. sun = new Sun();
  243. player = new Player();
  244. changeTimeBt = new Label()
  245. {
  246. Text = "Change Time",
  247. Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold),
  248. ForeColor = Color.Black,
  249. Size = new Size(90, 30),
  250. Location = new Point(220, 145),
  251. FlatStyle = FlatStyle.Flat,
  252. BackColor = Color.Transparent
  253. };
  254. changeTimeBt.Click += ChangeTimebt_click;
  255. aboutBt = new Label()
  256. {
  257. Text = "About",
  258. ForeColor = Color.Black,
  259. Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold),
  260. Size = new Size(90, 30),
  261. Location = new Point(240, 175),
  262. FlatStyle = FlatStyle.Flat,
  263. BackColor = Color.Transparent
  264. };
  265. aboutBt.Click += Aboutbt_click;
  266. menuBt = new Label()
  267. {
  268. Text = "Menu",
  269. Font = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Bold),
  270. ForeColor = Color.Black,
  271. Size = new Size(90, 30),
  272. Location = new Point(230, 165),
  273. FlatStyle = FlatStyle.Flat,
  274. BackColor = Color.Transparent,
  275. Visible = false
  276. };
  277. menuBt.Click += Menubt_click;
  278. backBt = new Label()
  279. {
  280. Text = "Back",
  281. Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold),
  282. ForeColor = Color.Black,
  283. Size = new Size(90, 30),
  284. Location = new Point(120, 185),
  285. FlatStyle = FlatStyle.Flat,
  286. BackColor = Color.Transparent,
  287. Visible = false
  288. };
  289. backBt.Click += Backbt_click;
  290. Controls.Add(changeTimeBt);
  291. Controls.Add(aboutBt);
  292. Controls.Add(menuBt);
  293. Controls.Add(backBt);
  294. //loading list for backgrounds
  295. BackGrounds.Add(DrawBackGround_MidDay);
  296. BackGrounds.Add(DrawBackGround_EndDay);
  297. BackGrounds.Add(DrawBackGround_Night);
  298. }
  299. #region Windows Form Designer generated code
  300. /// <summary>
  301. /// Required method for Designer support - do not modify
  302. /// the contents of this method with the code editor.
  303. /// </summary>
  304. private void InitializeComponent()
  305. {
  306. this.SuspendLayout();
  307. //
  308. // Form1
  309. //
  310. this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
  311. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  312. this.BackColor = System.Drawing.Color.White;
  313. this.ClientSize = new System.Drawing.Size(704, 450);
  314. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  315. this.Name = "Form1";
  316. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  317. this.Text = "Box Jump v2.0";
  318. this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(SpaceBar_KeyPress);
  319. this.ResumeLayout(false);
  320. }
  321. private void PlayerJumpValidate()
  322. {
  323. player.Jump(ref isJumping);
  324. }
  325. #endregion
  326. private bool isMenu;
  327. private int score;
  328. private bool isJumping;
  329. private Font gameFont;
  330. private int backGroundChoice;
  331. private Color textColor = Color.Black;
  332. private Label changeTimeBt;
  333. private Label aboutBt;
  334. private Label menuBt;
  335. private Label backBt;
  336. private int SpanTime;
  337. private System.Windows.Forms.Timer timer;
  338. private Stopwatch GameTime;
  339. private delegate void PerformPaints(Graphics g);
  340. private List<Cloud> clouds;
  341. private List<PerformPaints> BackGrounds;
  342. private List<PerformPaints> PaintActions;
  343. private List<Enemy> enemys;
  344. private bool Started;
  345. private Player player;
  346. private Sun sun;
  347. private Moon moon;
  348. private Random Generate;
  349. }
  350. }