Cześć pisze gre aranoid i chciałbym aby kafelki byly losowo umieszczne jest tylko jeden progrem nachodzą na siebie i chcialbym to naprawić ale nie wiem jak znaczy chcialbym ustawic margin dla kazdego ale nie dziala nie wiem czemu moze mi ktos wytlumaczyc dlaczego margin nie dziala albo jak w inny sposob mozna to naprawić :)
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 WindowsFormsApp58
{
public partial class Form1 : Form
{
public const int col = 5;
public const int row = 3;
public PictureBox[,] blocks;
public Form1()
{
setBlock();
InitializeComponent();
Cursor.Hide();
}
Random r = new Random();
private void setBlock()
{
int w = 100, h = 100;
blocks = new PictureBox[row, col];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
blocks[i, j] = new PictureBox();
blocks[i, j].Width = w;
blocks[i, j].Height = h;
blocks[i, j].BackColor = Color.DarkBlue;
blocks[i, j].Top = r.Next(0, 400);
blocks[i, j].Left = r.Next(0, 1000);
this.Controls.Add(blocks[i, j]);
}
}
}
int speed_x = 4;
int speed_y = 4;
private void Timer1_Tick(object sender, EventArgs e)
{
ball.Top += speed_y;
ball.Left += speed_x;
if(ball.Bottom >= panel.Bottom)
{
timer1.Stop();
}
if(ball.Right >= panel.Right || ball.Left <= panel.Left)
{
speed_x = -speed_x;
}
if(ball.Top <= panel.Top)
{
speed_y = -speed_y;
}
if(ball.Bounds.IntersectsWith(Racket.Bounds))
{
speed_y = -speed_y;
}
for(int i=0; i<row; i++)
{
for (int j = 0; j < col; j++)
{
if ((ball.Bounds.IntersectsWith(blocks[i, j].Bounds)) && (blocks[i, j].Visible == true)) {
blocks[i, j].Visible = false;
speed_y = -speed_y;
speed_x = -speed_x;
}
}
}
}
private void Panel_MouseMove(object sender, MouseEventArgs e)
{
Racket.Left = e.Location.X - (Racket.Width/2);
}
}
}