Advertisement
Guest User

kompo

a guest
Sep 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. Snake. cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace MOJSNAKE2
  10. {
  11. class Snake
  12. {
  13. public int x;
  14. public int y;
  15.  
  16. public int X { get { return x; } }
  17. public int Y { get { return y; } }
  18.  
  19.  
  20. public Snake(int x, int y)
  21. {
  22. this.x = x;
  23. this.y = y;
  24. }
  25.  
  26. }
  27. }
  28. ******************************************************************************
  29. using System;
  30. using System.Collections.Generic;
  31. using System.ComponentModel;
  32. using System.Data;
  33. using System.Drawing;
  34. using System.Linq;
  35. using System.Text;
  36. using System.Threading.Tasks;
  37. using System.Windows.Forms;
  38.  
  39. namespace MOJSNAKE2
  40. {
  41. public partial class Form1 : Form
  42. {
  43. List<Kropa> lista = new List<Kropa>();
  44. Graphics g;
  45. Random rr = new Random();
  46. int temp1;
  47. int temp2;
  48. int tik = 0;
  49. int q;
  50. int w;
  51. int predkosc;
  52.  
  53. int licznik = 1;
  54.  
  55. Snake s = new Snake(25, 25);
  56.  
  57.  
  58. bool gora = false;
  59. bool dol = false;
  60. bool prawo = false;
  61. bool lewo = false;
  62. bool czyDodac = true;
  63. bool byl = false;
  64.  
  65.  
  66.  
  67. public Form1()
  68. {
  69. InitializeComponent();
  70.  
  71. pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  72. g = Graphics.FromImage(pictureBox1.Image);
  73.  
  74.  
  75. }
  76.  
  77.  
  78. private void ruszaj()
  79. {
  80.  
  81. pictureBox1.Refresh();
  82. g.Clear(Color.Green);
  83. if(gora == true)
  84. s.y -= 20;
  85. if(dol == true)
  86. s.y += 20;
  87. if(prawo==true)
  88. s.x += 20;
  89. if (lewo == true)
  90. s.x -= 20;
  91.  
  92.  
  93.  
  94. if (lewo)
  95. {
  96.  
  97.  
  98. if (s.x < 0)
  99. {
  100. s.x = pictureBox1.Width - 1;
  101. }
  102.  
  103. }
  104. else if (prawo)
  105. {
  106.  
  107. if (s.x > pictureBox1.Width)
  108. {
  109. s.x = 0;
  110. }
  111. }
  112. else if (gora)
  113. {
  114.  
  115. if (s.y < 0)
  116. {
  117. s.y = pictureBox1.Height - 1;
  118. }
  119. }
  120. else if (dol)
  121. {
  122.  
  123. if (s.y > pictureBox1.Height)
  124. {
  125. s.y = 0;
  126. }
  127. }
  128.  
  129. }
  130.  
  131.  
  132.  
  133. private void rysuj()
  134. {
  135.  
  136. g.FillEllipse(new SolidBrush(Color.Black), s.x, s.y, 25, 25);
  137. pictureBox1.Refresh();
  138.  
  139. }
  140.  
  141. private void timer1_Tick(object sender, EventArgs e)
  142. {
  143.  
  144. if (tik % 15 == 0)
  145. {
  146. q = rr.Next(20,100 );
  147. w = rr.Next(20, 100);
  148. tik++;
  149. }
  150.  
  151. if (tik%15 != 0)
  152. {
  153. g.FillEllipse(new SolidBrush(Color.Red), q, w, 25, 25);
  154.  
  155.  
  156. if (Math.Abs(s.x - q) < 15 && Math.Abs(s.y - w) < 15)
  157. {
  158. label1.Text = licznik.ToString();
  159.  
  160. g.Clear(Color.Green);
  161. licznik++;
  162. tik = 0;
  163. }
  164.  
  165. }
  166.  
  167.  
  168. rysuj();
  169. ruszaj();
  170.  
  171. if (s.x < -10 || s.x > pictureBox1.Width + 10 || s.y < -10 || s.y > pictureBox1.Height + 10)
  172. timer1.Stop();
  173. }
  174.  
  175.  
  176. private void Form1_KeyDown(object sender, KeyEventArgs e)
  177. {
  178. if(e.KeyCode == Keys.Down)
  179. {
  180. dol = true;
  181. gora = false;
  182. lewo = false;
  183. prawo = false;
  184. }
  185.  
  186.  
  187. if (e.KeyCode == Keys.Up)
  188. {
  189. dol = false;
  190. gora = true;
  191. lewo = false;
  192. prawo = false;
  193. }
  194. if(e.KeyCode == Keys.Right)
  195. {
  196. dol = false;
  197. gora = false;
  198. lewo = false;
  199. prawo = true;
  200. }
  201. if(e.KeyCode == Keys.Left)
  202. {
  203. dol = false;
  204. gora = false;
  205. lewo = true;
  206. prawo = false;
  207. }
  208. }
  209. }
  210. }
  211.  
  212. ----------------------------------------------------------------------------------------------------------------
  213.  
  214. Kuleczka. cs
  215.  
  216. using System;
  217. using System.Collections.Generic;
  218. using System.Linq;
  219. using System.Text;
  220. using System.Threading.Tasks;
  221.  
  222. namespace WindowsFormsApplication2
  223. {
  224. class Kuleczka
  225. {
  226. public int x;
  227. public int y;
  228. public int r;
  229.  
  230. public int X { get { return x; } }
  231. public int Y { get { return y; } }
  232. public int R { get { return r; } }
  233.  
  234.  
  235. public Kuleczka(int x,int y,int r)
  236. {
  237. this.x = x;
  238. this.y = y;
  239. this.r = r;
  240. }
  241.  
  242. internal void spadaj()
  243. {
  244. y = y + r / 2;
  245. }
  246.  
  247. }
  248. }
  249. ******************************************************************************
  250.  
  251. using System;
  252. using System.Collections.Generic;
  253. using System.ComponentModel;
  254. using System.Data;
  255. using System.Drawing;
  256. using System.Linq;
  257. using System.Text;
  258. using System.Threading.Tasks;
  259. using System.Windows.Forms;
  260.  
  261. namespace WindowsFormsApplication2
  262. {
  263. public partial class Form1 : Form
  264. {
  265.  
  266. Random rr = new Random();
  267. List<Kuleczka> lista = new List<Kuleczka>();
  268. int x;
  269. int y;
  270. int r;
  271. int zmienna = 0;
  272. Graphics g;
  273.  
  274. public Form1()
  275. {
  276. InitializeComponent();
  277.  
  278. pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  279. g = Graphics.FromImage(pictureBox1.Image);
  280. odrysuj();
  281. }
  282.  
  283. private void odrysuj()
  284. {
  285. g.Clear(Color.White);
  286.  
  287. x = rr.Next(0, pictureBox1.Width - r);
  288. y = 0;
  289. r = rr.Next(30, 60);
  290.  
  291. Kuleczka k = new Kuleczka(x, y, r);
  292. lista.Add(k);
  293.  
  294.  
  295.  
  296.  
  297. foreach (Kuleczka kk in lista)
  298. {
  299. g.FillEllipse(new SolidBrush(Color.Green), kk.x, kk.y, kk.r, kk.r);
  300. pictureBox1.Refresh();
  301. }
  302.  
  303.  
  304.  
  305.  
  306. pictureBox1.Refresh();
  307.  
  308.  
  309. }
  310.  
  311. private void timer1_Tick(object sender, EventArgs e)
  312. {
  313. foreach (Kuleczka kk in lista)
  314. {
  315.  
  316. if (kk.y + kk.r >= pictureBox1.Height)
  317. {
  318. timer1.Stop();
  319. MessageBox.Show("Przegraels");
  320. break;
  321. }
  322. kk.spadaj();
  323. }
  324. odrysuj();
  325. pictureBox1.Refresh();
  326. }
  327.  
  328. private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
  329. {
  330. foreach (Kuleczka k in lista)
  331. {
  332. if(Math.Abs(k.x-e.X)< k.r && Math.Abs(k.y-e.Y)<k.r)
  333. {
  334. zmienna++;
  335. lista.Remove(k);
  336. break;
  337.  
  338. }
  339.  
  340. }
  341. odrysuj();
  342. label1.Text = zmienna.ToString();
  343. }
  344. }
  345. }
  346. ----------------------------------------------------------------------------------------------
  347. Rysowanie linii
  348.  
  349. g.Clear(Color.White);
  350. for (int i=0; i<=rozmiarObrazka; i++)
  351. {
  352. g.DrawLine(new Pen(Color.Gray),
  353. i * rozmiarKratki,
  354. 0,
  355. i * rozmiarKratki,
  356. rozmiarObrazka * rozmiarKratki);
  357. g.DrawLine(new Pen(Color.Gray),
  358. 0,
  359. i * rozmiarKratki,
  360. rozmiarObrazka * rozmiarKratki,
  361. i * rozmiarKratki);
  362. }
  363. Rysunek rys = cbListaRysunkow.SelectedItem as Rysunek;
  364.  
  365. foreach(Punkt p in rys.Punkts)
  366. {
  367. g.FillEllipse(new SolidBrush(ColorTranslator.FromHtml(p.Kolor)),
  368. p.X * rozmiarKratki+1,
  369. p.Y * rozmiarKratki+1,
  370. rozmiarKratki - 2,
  371. rozmiarKratki - 2
  372. );
  373. }
  374. rysunek.Refresh();
  375. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement