PDA

View Full Version : چطور باید برنامه زیر رو با استفاده از کلاس بنویسم؟



hasan1500
شنبه 10 فروردین 1392, 19:27 عصر
سلام
من دارم یک بازی ساده می نویسم با این مشخصات که
1- هر وقت روی فرم کلیک شد یک توپ بصورت تصادفی شروع به حرکت کنه و اگه به کناره های فرم خود مسیرشو تصادفی انتخب کنه.
2- اگه یک بار دیگه روی فرم کلیک شدٰ یک توپ جدید ایجاد بشه و .همین طور الی بعد....
3- در ضمن وقتی دو تا ار ین توپ ها بهم خوردن هر دو حذف بشند.
* من تونستم کد بخش اولشو بنویسم.(البته بدون کلاس نویسی)
لطفا هر کی قسمتهای دو و سه رو بلده یاری برسونه.(البته بروش کلاس نویسی)
اینم کدهایی که نوشتم:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication46
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Boolean top = true;
public Boolean left = true;
public int Speed =5;
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (top == true) pictureBox1.Top += Speed; else pictureBox1.Top -= Speed;
if (left == true) pictureBox1.Left += Speed; else pictureBox1.Left -= Speed;

if (pictureBox1.Top >= this.Height-100) top = false;
if (pictureBox1.Left >= this.Width-100) left = false;


if (pictureBox1.Top < -5) top = true;
if (pictureBox1.Left < -5) left = true;
}
catch
{
timer1.Enabled = false;
}
}
private void Form1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
}