Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Snake. cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MOJSNAKE2
- {
- class Snake
- {
- public int x;
- public int y;
- public int X { get { return x; } }
- public int Y { get { return y; } }
- public Snake(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- }
- }
- ******************************************************************************
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MOJSNAKE2
- {
- public partial class Form1 : Form
- {
- List<Kropa> lista = new List<Kropa>();
- Graphics g;
- Random rr = new Random();
- int temp1;
- int temp2;
- int tik = 0;
- int q;
- int w;
- int predkosc;
- int licznik = 1;
- Snake s = new Snake(25, 25);
- bool gora = false;
- bool dol = false;
- bool prawo = false;
- bool lewo = false;
- bool czyDodac = true;
- bool byl = false;
- public Form1()
- {
- InitializeComponent();
- pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
- g = Graphics.FromImage(pictureBox1.Image);
- }
- private void ruszaj()
- {
- pictureBox1.Refresh();
- g.Clear(Color.Green);
- if(gora == true)
- s.y -= 20;
- if(dol == true)
- s.y += 20;
- if(prawo==true)
- s.x += 20;
- if (lewo == true)
- s.x -= 20;
- if (lewo)
- {
- if (s.x < 0)
- {
- s.x = pictureBox1.Width - 1;
- }
- }
- else if (prawo)
- {
- if (s.x > pictureBox1.Width)
- {
- s.x = 0;
- }
- }
- else if (gora)
- {
- if (s.y < 0)
- {
- s.y = pictureBox1.Height - 1;
- }
- }
- else if (dol)
- {
- if (s.y > pictureBox1.Height)
- {
- s.y = 0;
- }
- }
- }
- private void rysuj()
- {
- g.FillEllipse(new SolidBrush(Color.Black), s.x, s.y, 25, 25);
- pictureBox1.Refresh();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (tik % 15 == 0)
- {
- q = rr.Next(20,100 );
- w = rr.Next(20, 100);
- tik++;
- }
- if (tik%15 != 0)
- {
- g.FillEllipse(new SolidBrush(Color.Red), q, w, 25, 25);
- if (Math.Abs(s.x - q) < 15 && Math.Abs(s.y - w) < 15)
- {
- label1.Text = licznik.ToString();
- g.Clear(Color.Green);
- licznik++;
- tik = 0;
- }
- }
- rysuj();
- ruszaj();
- if (s.x < -10 || s.x > pictureBox1.Width + 10 || s.y < -10 || s.y > pictureBox1.Height + 10)
- timer1.Stop();
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if(e.KeyCode == Keys.Down)
- {
- dol = true;
- gora = false;
- lewo = false;
- prawo = false;
- }
- if (e.KeyCode == Keys.Up)
- {
- dol = false;
- gora = true;
- lewo = false;
- prawo = false;
- }
- if(e.KeyCode == Keys.Right)
- {
- dol = false;
- gora = false;
- lewo = false;
- prawo = true;
- }
- if(e.KeyCode == Keys.Left)
- {
- dol = false;
- gora = false;
- lewo = true;
- prawo = false;
- }
- }
- }
- }
- ----------------------------------------------------------------------------------------------------------------
- Kuleczka. cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WindowsFormsApplication2
- {
- class Kuleczka
- {
- public int x;
- public int y;
- public int r;
- public int X { get { return x; } }
- public int Y { get { return y; } }
- public int R { get { return r; } }
- public Kuleczka(int x,int y,int r)
- {
- this.x = x;
- this.y = y;
- this.r = r;
- }
- internal void spadaj()
- {
- y = y + r / 2;
- }
- }
- }
- ******************************************************************************
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- Random rr = new Random();
- List<Kuleczka> lista = new List<Kuleczka>();
- int x;
- int y;
- int r;
- int zmienna = 0;
- Graphics g;
- public Form1()
- {
- InitializeComponent();
- pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
- g = Graphics.FromImage(pictureBox1.Image);
- odrysuj();
- }
- private void odrysuj()
- {
- g.Clear(Color.White);
- x = rr.Next(0, pictureBox1.Width - r);
- y = 0;
- r = rr.Next(30, 60);
- Kuleczka k = new Kuleczka(x, y, r);
- lista.Add(k);
- foreach (Kuleczka kk in lista)
- {
- g.FillEllipse(new SolidBrush(Color.Green), kk.x, kk.y, kk.r, kk.r);
- pictureBox1.Refresh();
- }
- pictureBox1.Refresh();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- foreach (Kuleczka kk in lista)
- {
- if (kk.y + kk.r >= pictureBox1.Height)
- {
- timer1.Stop();
- MessageBox.Show("Przegraels");
- break;
- }
- kk.spadaj();
- }
- odrysuj();
- pictureBox1.Refresh();
- }
- private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
- {
- foreach (Kuleczka k in lista)
- {
- if(Math.Abs(k.x-e.X)< k.r && Math.Abs(k.y-e.Y)<k.r)
- {
- zmienna++;
- lista.Remove(k);
- break;
- }
- }
- odrysuj();
- label1.Text = zmienna.ToString();
- }
- }
- }
- ----------------------------------------------------------------------------------------------
- Rysowanie linii
- g.Clear(Color.White);
- for (int i=0; i<=rozmiarObrazka; i++)
- {
- g.DrawLine(new Pen(Color.Gray),
- i * rozmiarKratki,
- 0,
- i * rozmiarKratki,
- rozmiarObrazka * rozmiarKratki);
- g.DrawLine(new Pen(Color.Gray),
- 0,
- i * rozmiarKratki,
- rozmiarObrazka * rozmiarKratki,
- i * rozmiarKratki);
- }
- Rysunek rys = cbListaRysunkow.SelectedItem as Rysunek;
- foreach(Punkt p in rys.Punkts)
- {
- g.FillEllipse(new SolidBrush(ColorTranslator.FromHtml(p.Kolor)),
- p.X * rozmiarKratki+1,
- p.Y * rozmiarKratki+1,
- rozmiarKratki - 2,
- rozmiarKratki - 2
- );
- }
- rysunek.Refresh();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement