Advertisement
BrU32

C# Gravity Ball Game SRC V1

Mar 10th, 2017
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Microsoft.VisualBasic.PowerPacks;
  10.  
  11. namespace C_Sharp_Gravity_Ball_SRC
  12. {
  13.  
  14. public partial class Form1 : Form
  15. {
  16. public int UPDOWN = 0;
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void Form1_Load(object sender, EventArgs e)
  23. {
  24.  
  25. }
  26.  
  27. private void timer1_Tick(object sender, EventArgs e)
  28. {
  29. if (UPDOWN == 2)
  30. {
  31. ovalShape1.Location = new Point(ovalShape1.Location.X, ovalShape1.Location.Y + 1);
  32. }
  33. if (UPDOWN == 1)
  34. {
  35. ovalShape1.Location = new Point(ovalShape1.Location.X, ovalShape1.Location.Y - 1);
  36. }
  37. if (UPDOWN == 0)
  38. {
  39. // ovalShape1.Location = new Point(ovalShape1.Location.X + 1, ovalShape1.Location.Y);
  40. }
  41. ovalShape1.Location = new Point(ovalShape1.Location.X + 1, ovalShape1.Location.Y);
  42. if (ovalShape1.Location == ovalShape2.Location)
  43. {
  44. GameOver();
  45. timer1.Enabled = false;
  46. MessageBox.Show("You Win!!");
  47. Application.Exit();
  48.  
  49. return;
  50. }
  51. if (ovalShape1.Location.Y <= -29 ^ ovalShape1.Location.Y >= 410)
  52. {
  53. GameOver1();
  54. MessageBox.Show("You Win!!");
  55. Application.Exit();
  56.  
  57. return;
  58. }
  59. if (ovalShape1.Location.X >= 521)
  60. {
  61. GameOver1();
  62. MessageBox.Show("You Win!!");
  63. Application.Exit();
  64.  
  65. return;
  66. }
  67. }
  68.  
  69. private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  70. {
  71. if (e.KeyChar == 38)
  72. {
  73. UPDOWN = 2;
  74. //ovalShape1.Location = new Point(ovalShape1.Location.X, ovalShape1.Location.Y - 1);
  75.  
  76. }
  77.  
  78.  
  79. if (e.KeyChar == 40)
  80. {
  81. UPDOWN = 1;
  82. //ovalShape1.Location = new Point(ovalShape1.Location.X, ovalShape1.Location.Y + 1);
  83.  
  84. }
  85. }
  86.  
  87. private void Form1_KeyDown(object sender, KeyEventArgs e)
  88. {
  89. if (e.KeyCode == Keys.Up)
  90. {
  91. UPDOWN = 2;
  92.  
  93.  
  94. }
  95.  
  96.  
  97. if (e.KeyCode == Keys.Down)
  98. {
  99. UPDOWN = 1;
  100.  
  101.  
  102.  
  103. }
  104. }
  105.  
  106. private void button2_Click(object sender, EventArgs e)
  107. {
  108. UPDOWN = 2;
  109. }
  110.  
  111. private void button1_Click(object sender, EventArgs e)
  112. {
  113. UPDOWN = 1;
  114. }
  115. public void GameOver()
  116. {
  117. DialogResult PlayAgain;
  118. timer1.Enabled = false;
  119. MessageBox.Show("You Win!!", "Gravity Ball [Ver 1.0]", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  120. PlayAgain = MessageBox.Show("Do you want to play again?", "Gravity Ball [Ver 1.0]", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  121. if (PlayAgain == DialogResult.No)
  122. {
  123. Application.Exit();
  124. ActiveForm.Close();
  125. }
  126. else if (PlayAgain == DialogResult.Yes)
  127. {
  128. // System.Diagnostics.Process.Start("Gravity Ball [Version 1.0].exe");
  129. System.Diagnostics.Process.Start("C-Sharp Gravity Ball SRC.exe");
  130. Application.Exit();
  131. ActiveForm.Close();
  132. }
  133.  
  134. }
  135.  
  136.  
  137.  
  138. public void GameOver1()
  139. {
  140. DialogResult PlayAgain;
  141. timer1.Enabled = false;
  142. MessageBox.Show("You Lose!!", "Gravity Ball [Ver 1.0]", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  143. PlayAgain = MessageBox.Show("Do you want to play again?", "Gravity Ball [Ver 1.0]", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  144. if (PlayAgain == DialogResult.No)
  145. {
  146. Application.Exit();
  147. ActiveForm.Close();
  148. }
  149. else if (PlayAgain == DialogResult.Yes)
  150. {
  151. // System.Diagnostics.Process.Start("Gravity Ball [Version 1.0].exe");
  152. System.Diagnostics.Process.Start("C-Sharp Gravity Ball SRC.exe");
  153. Application.Exit();
  154. ActiveForm.Close();
  155. }
  156.  
  157. }
  158.  
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement