Visual C#.NET'te Yılan Oyunu
Visual C#.NET de Yılan Oyunu
--------------------------------------------------------------------------------
Çalışmalarınıza bir örnek.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace gameyilan2007
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
this.Text = " Yılan 2007 programmer Ahmet ALi Süzen";
Game.Load_Graphic();
Game.uz = 17;
Game.j = 17;
Game.x = 10;
Game.y = 10;
Game.yem.X = -1;
Game.yem.Y = -1;
if (Game.bmp != null)
{
Game.yilanrengi = Brushes.BlueViolet;
Game.background = Brushes.Black;
Game.yilanderirengi = Brushes.Yellow;
pictureBox1.Image = Game.bmp;
pictureBox1.Refresh();
}
Game.rota = 2;
Game.yemvar = false;
Game.yemrengi = Brushes.DarkRed;
Game.yemderirengi = Brushes.DarkSeaGreen;
Game.puan = 0;
Game.bekleint = 5;
}
private void timer1main_Tick(object sender EventArgs e)
{
if (Game.rota ==1) Game.move_yilan_left();
if (Game.rota ==2) Game.move_yilan_rigth();
if (Game.rota ==3) Game.move_yilan_up();
if (Game.rota ==4) Game.move_yilan_down();
Game.Draw_Yilan(Game.x Game.y);
Game.alanX[Game.j] = Game.x;
Game.alanY[Game.j] = Game.y;
Game.j++;
Game.Bos_Draw_Yilan(Game.alanX[Game.j-Game.uz]Game.alanY[Game.j-Game.uz]);
if (Game.j > 899)
{
Game.j = Game.uz;
for (int z = 0; z <Game.uz; ++z)
{
Game.alanX[Game.uz - z] = Game.alanX[900 - z];
Game.alanY[Game.uz - z] = Game.alanY[900 - z];
}
}
if ((Game.yilan_esit_yem()==false)&&(Game.yemvar == false))
{
Game.yem_koord_yerlestir();
Game.yem_koy(Game.yem.X Game.yem.Y);
}
if (Game.yilan_esit_yem() == true)
{
Game.yem.X = -1;
Game.yem.Y = -1;
Game.yemvar = false;
Game.puan += 1;
label1.Text = " PUAN : " + Game.puan.ToString();
Game.uz += 1;
}
pictureBox1.Image = Game.bmp;
pictureBox1.Refresh();
//Game.yilanin_koordinatlari();
if (Game.yilan_kendisine_carptimi() == true)
{
timer1main.Enabled = false;
bekle.Enabled = true;
if (Game.bekleint <= 0)
{
}
else
{
Game.bekleint = 20;
}
}
if (Game.x > 40) Game.x = 0;
if (Game.x < 0) Game.x = 40;
if (Game.y > 40) Game.y = 0;
if (Game.y < 0) Game.y = 40;
}
private void Form1_KeyDown(object sender KeyEventArgs e)
{
if (e.KeyCode == Keys.Left) Game.rota = 1;
if (e.KeyCode == Keys.Right) Game.rota = 2;
if (e.KeyCode == Keys.Up) Game.rota = 3;
if (e.KeyCode == Keys.Down) Game.rota = 4;
if (e.KeyCode == Keys.Escape) Application.Exit();
Game.bekleint = 20;
bekle.Enabled = false;
timer1main.Enabled = true;
}
private void startToolStripMenuItem_Click(object sender EventArgs e)
{
timer1main.Interval = 100;
timer1main.Enabled = true;
}
private void stopToolStripMenuItem_Click(object sender EventArgs e)
{
timer1main.Enabled = false;
}
private void bekle_Tick(object sender EventArgs e)
{
Game.bekleint--;
if (Game.bekleint == 0)
{
bekle.Enabled = false;
Game_Over();
}
}
public void Game_Over()
{
timer1main.Interval = 100;
timer1main.Enabled = false;
MessageBox.Show("Oyun Bitti Puan :" + label1.Text);
Game.game_reset();
Game.Load_Graphic();
Game.yemvar = false;
timer1main.Enabled = true;
}
private void pictureBox1_Click(object sender EventArgs e)
{
}
//finish
}
}
__________________
بِسْــــــــــــــــــــــمِ اﷲِارَّحْمَنِ ارَّحِيم
-------------------------------------------------
Bu Soysuzlar Bu Vatansızlar Sarsada Yurdumu Ben Yaratan'dan Alırım Asil Kanı ve Gücü. -------------------------------------------------
|