Cevaplar

2012-12-04T16:18:58+02:00

yılan oyunu 

 

namespace blog_yalan
{
public partial class Form1 : Form
{
int say=0,uzunluk=5;
int a, b,indis=0,yem=0,puan=0;
int x1=0,y1=0;
int[] kuyrukx = new int[250];
int[] kuyruky = new int[250];
public Form1()
{
InitializeComponent();
}

public void kare_ciz(){


Graphics g;
Pen p = new Pen(Color.Yellow, 2);
SolidBrush s = new SolidBrush(Color.Yellow);
g = this.CreateGraphics();

g.DrawRectangle(p, x1, y1, 10, 10);

g.FillRectangle(s, x1, y1, 10, 10);

for (int i = 0; i < uzunluk; i++)
{
g.DrawRectangle(p, kuyrukx[i], kuyruky[i], 10, 10);
}

g.Dispose();

}
public void yem_at() {
Random r=new Random();
Graphics g;

a=r.Next()%390;
b=r.Next()%290;
a = a - (a % 10);
b = b - (b % 10);
if (a < 10) { a = 10; }
if (b < 10) { b = 10; }
SolidBrush s = new SolidBrush(Color.Red);
g = this.CreateGraphics();
g.FillRectangle(s, a, b, 10, 10);

}
public void temizle()
{

Graphics g = this.CreateGraphics();

g.Clear(Color.Black);
Pen p = new Pen(Color.Red, 3);

SolidBrush s = new SolidBrush(Color.Red);
g.FillRectangle(s, a, b, 10, 10);
g.DrawRectangle(p, 0, 0, 410, 303);
}
public void kontrol_et()
{


if (x1 == a && y1 == b) { yem = 0; puan += 5; uzunluk++; label2.Text = puan.ToString(); }


}
private void timer1_Tick(object sender, EventArgs e)
{
kontrol_et();
if (yem == 0) { yem_at(); yem = 1; }
if (say % 4 == 0)
{
temizle();
kuyrukx[indis] = x1;
kuyruky[indis] = y1;
indis++;
if (indis > uzunluk-1) { indis = 0; }
kare_ciz();

x1 += 10;
if (x1 >= 400){ x1 = 0; }
}
if (say % 4 == 1) {

temizle();
kuyrukx[indis] = x1;
kuyruky[indis] = y1;
indis++;
if (indis >uzunluk-1) { indis = 0; }
kare_ciz();

y1 += 10;
if (y1 >= 300) { y1 = 0; }
}
if (say % 4 == 2)
{
temizle();
kuyrukx[indis] = x1;
kuyruky[indis] = y1;
indis++;

if (indis > uzunluk-1) { indis = 0; }
kare_ciz();

x1 -= 10;
if (x1 <= 0) { x1 = 400; }
}
if (say % 4 == 3) {

temizle();
kuyrukx[indis] = x1;
kuyruky[indis] = y1;
indis++;
if (indis > uzunluk-1) { indis = 0; }
kare_ciz();

y1 -= 10;
if (y1 <= 0) { y1 = 300; }

}

}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
if (say == 1) { return; }
say = 1;
}
if (e.KeyCode == Keys.Right)
{
if (say == 0) { return; }
say = 0;
}
if (e.KeyCode == Keys.Left)
{
if (say == 2) { return; }
say = 2;
}
if (e.KeyCode == Keys.Up)
{
if (say == 3) { return; }
say = 3;
}
if (e.KeyCode == Keys.Escape)
{
Application.Exit();

}
}

}
}

0