0% found this document useful (0 votes)
32 views2 pages

Zadatak 3

The document defines a Windows Forms application that displays a randomly moving red dot. It tracks the number of times the user clicks on the dot. The form initializes a random point for the dot's position. A timer moves the dot to a new random position and checks for a click match. The number of matches and timer ticks are displayed. When the user clicks, it checks if the click matches the dot's position.

Uploaded by

棕色扶手椅
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Zadatak 3

The document defines a Windows Forms application that displays a randomly moving red dot. It tracks the number of times the user clicks on the dot. The form initializes a random point for the dot's position. A timer moves the dot to a new random position and checks for a click match. The number of matches and timer ticks are displayed. When the user clicks, it checks if the click matches the dot's position.

Uploaded by

棕色扶手椅
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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 Zadatak_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Tacka t;
private void Form1_Load(object sender, EventArgs e)
{
Random r = new Random();
t = new Tacka(new Point(r.Next(ClientRectangle.Width),
r.Next(ClientRectangle.Height)));
Text = poeni + ":" + brojp;
timer1.Start();
}

private void Form1_Paint(object sender, PaintEventArgs e)


{
t.Boji(e.Graphics);
}
int poeni = 0;
int brojp = 0;
private void timer1_Tick(object sender, EventArgs e)
{

if (t.SadrziTacku(x, y))
{
poeni++;
}
t.Promenikoorde(ClientRectangle.Width, ClientRectangle.Height);
brojp++;
Text = poeni + ":" + brojp;
Refresh();
}
int x;
int y;
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}
}
}
class Tacka
{
private const int r = 10;
private Point o;
public Tacka( Point o)
{
this.o = o;
}
public void Boji(Graphics g)
{
SolidBrush cetka = new SolidBrush(Color.Red);
g.FillEllipse(cetka,o.X - r, o.Y - r, 2 * r, 2 * r);
}
public void Promenikoorde(int sirina, int visina)
{
Random rnd = new Random();
o = new Point(rnd.Next(sirina - r), rnd.Next(visina - r));
}
public bool SadrziTacku(int x, int y)
{
if(o.X - r < x && o.Y - r < y && o.X + r > x && o.Y + r > y)
{
return true;
}
else
return false;
}

You might also like