Ana içeriğe atla

C# - Düşen Şeker Vurma Oyunu





KODLAR
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 WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Graphics tuval;
        Pen kalem = new Pen(Color.Black , 3 );
        int x, y, x1=0, y1=0, x2 = 0, y2 = 0,xk;
        bool atis = false;
        int px1, px2, px3, px4;
        int py1, py2, py3, py4;
        Random Rastgele = new Random();
        int puanlama = 0;

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            x = Cursor.Position.X;
            y = Cursor.Position.Y;
            Point P = PointToScreen(new Point(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top));
            xk = x - P.X;
            x1 = Convert.ToInt16( Math.Abs(450 - (x - P.X)) / 5 );
            y1 = Convert.ToInt16( Math.Abs(400 - (y - P.Y)) / 5);
            x2 = 450;
            y2 = 400;
            atis = true;
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox2.Parent = pictureBox1;
            pictureBox2.BackColor = Color.Transparent;

            pictureBox3.Parent = pictureBox1;
            pictureBox3.BackColor = Color.Transparent;

            pictureBox4.Parent = pictureBox1;
            pictureBox4.BackColor = Color.Transparent;

            pictureBox5.Parent = pictureBox1;
            pictureBox5.BackColor = Color.Transparent;

            tuval = pictureBox1.CreateGraphics();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            timer1.Interval = 100;
            timer1.Start();

            px1 = Rastgele.Next(50,850);
            py1 = 0;
            pictureBox2.Location = new Point(px1,py1);

            px2 = Rastgele.Next(50, 850);
            py2 = 0;
            pictureBox3.Location = new Point(px2, py2);

            px3 = Rastgele.Next(50, 850);
            py3 = 0;
            pictureBox4.Location = new Point(px3, py3);

            px4 = Rastgele.Next(50, 850);
            py4 = 0;
            pictureBox5.Location = new Point(px4, py4);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureBox1.Refresh();

            x = Cursor.Position.X;
            y = Cursor.Position.Y;
            Point P = PointToScreen(new Point(pictureBox1.Bounds.Left, pictureBox1.Bounds.Top));
            x = x - P.X;
            y = y - P.Y;

            if (atis)
            {
                if (xk < 450)
                {
                    x2 = x2 - x1;
                }
                else
                {
                    x2 = x2 + x1;
                }
                y2 = y2 - y1;
                tuval.DrawRectangle(kalem, x2, y2, 5, 5);
            }
            

            tuval.DrawLine(kalem, 450 , 400 , x , y);
            tuval.DrawLine(kalem, x - 25 , y , x + 25 , y);
            tuval.DrawLine(kalem, x , y - 25 , x , y + 25);
            tuval.DrawEllipse(kalem , x - 10 , y - 10 , 20 , 20);
            tuval.DrawArc(kalem , 425 , 375 , 50 , 50 , 270 , 360);

            //nesnelerin hareketinin saglanması
            py1 = py1 + Rastgele.Next(5,20);
            pictureBox2.Location = new Point(px1,py1);

            py2 = py2 + Rastgele.Next(5, 20);
            pictureBox3.Location = new Point(px2, py2);

            py3 = py3 + Rastgele.Next(5, 20);
            pictureBox4.Location = new Point(px3, py3);

            py4 = py4 + Rastgele.Next(5, 20);
            pictureBox5.Location = new Point(px4, py4);

            //oyun dışına çıkan nesnelerin başlangıç noktasından tekrar başlatılması
            if (py1 > 400)
            {
                py1 = -30;
                px1 = Rastgele.Next(50,850);
            }
            if (py2 > 400)
            {
                py2 = -30;
                px2 = Rastgele.Next(50, 850);
            }
            if (py3 > 400)
            {
                py3 = -30;
                px3 = Rastgele.Next(50, 850);
            }
            if (py4 > 400)
            {
                py4 = -30;
                px4 = Rastgele.Next(50, 850);
            }

            //vurma olayının gerçekleştirilmesi
            if (x2 > px1 && y2 > py1 && x2 < px1 + 30 && y2 < py1 + 30 )
            {
                py1 = -30;
                px1 = Rastgele.Next(50, 850);
                puanlama = puanlama + 10;
            }
            if (x2 > px2 && y2 > py2 && x2 < px2 + 30 && y2 < py2 + 30)
            {
                py2 = -30;
                px2 = Rastgele.Next(50, 850);
                puanlama = puanlama + 10;
            }
            if (x2 > px3 && y2 > py3 && x2 < px3 + 30 && y2 < py3 + 30)
            {
                py3 = -30;
                px3 = Rastgele.Next(50, 850);
                puanlama = puanlama + 10;
            }
            if (x2 > px4 && y2 > py4 && x2 < px4 + 30 && y2 < py4 + 30)
            {
                py4 = -30;
                px4 = Rastgele.Next(50, 850);
                puanlama = puanlama + 10;
            }
            label2.Text = Convert.ToString(puanlama);
        }
    }
}

Yorumlar

Bu blogdaki popüler yayınlar

Matlab Operatörler

Matematiksel operatörler: +  Toplama –  Çıkarma *  Çarpma /  Bölme ^  Üst alma .* Elemanter çarpım ./  Elemanter bölme .^  Elemanter üst alma a+b  Boyutları aynı olan a ve b matrisini toplar. a-b  Boyutları aynı olan a ve b matrislerinin farkını alır. a*b  Sütun sayısı m olan a matrisiyle satır sayısı m olan b matrisini çarpar. a/b  b düzenli kare bir matrisse (determinantı sıfırdan farklıysa), aynı boyutlu a matrisiyle; a*inv(b)işlemini yapar. a.*b  Boyutları aynı olan a ve b matrislerinin elemanlarını karşılıklı olarak çarpar. a./b  Boyutları aynı olan a ve b matrislerinin elemanlarını karşılıklı oranlar. sqrt  Kök alma abs  Mutlak değer rats  Kesirli gösterim Mantıksal operatörler: &  Ve |  Veya ~  Değil /  Bölme Karar operatörleri: >  Büyüktür <  Küçüktür >=  Büyük eşittir <=  Küçük eşittir ==  Eşittir ~= ...

2. Dereceden 1 Bilinmeyenli Denklemin Köklerini Buldurma - MATLAB

2. dereceden bir bilinmeyenli denklemin köklerini buldurmak için denklemin bilinmeyen katsayılarına ve sabit sayısına ihtiyacımız var. Kök buldurma denklemi aşagıdaki gibidir. Yapacagımız işlemleri daha iyi anlamanız için akış diyagramı aşagıda ki fotoğrafta görülmektedir Akış diyagramından yola çıkarak matlab kodlarıını adım adım yazalım. a=input(‘a= ’); %x^2nin katsayısını kullanıcıdan girmesini istiyoruz b=input(‘a= ’); %x in katsayısını kullanıcıdan girmesini istiyoruz c=input(‘a= ’); %c nin yani sabit sayının kullanıcıdan girmesini istiyoruz disp (‘ ’); %ekrana birazcık boşluk bırakıyoruz d=b * b - 4 * a * c; if (d > 0 ) disp (‘Gerçek İki Kök Vardır’); %ekrana kök bulunduğunu yazıyoruz x1=( - b - sqrt (d)) / ( 2 * a); %birinci kökü buluyoruz x2=( - b + sqrt (d)) / ( 2 * a); %ikinci kökü buluyoruz [yz,ht]=sprintf(‘ 1. Kök: %0.5f’,x1); disp(yz); %birinci kökü ekrana formatlı olarak yazdırıyoruz [yz,ht]=spri...