Good morning I have problem, with my game. How can I make moves between neighbors pictures? We have an problem with moving of parts of pictures. It must move only when part of picture and the white field are next to each. Here are
Form:
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 PuzzleN
{
public partial class Form1 : Form
{
private Field game;
private PictureBox[,] picture;
public Form1()
{
InitializeComponent();
game = new Field();
initPictures();
}
private void initPictures()
{
picture = new PictureBox[4, 4];
picture[0, 0] = pictureBox0;
picture[0, 1] = pictureBox1;
picture[0, 2] = pictureBox2;
picture[0, 3] = pictureBox3;
picture[1, 0] = pictureBox4;
picture[1, 1] = pictureBox5;
picture[1, 2] = pictureBox6;
picture[1, 3] = pictureBox7;
picture[2, 0] = pictureBox8;
picture[2, 1] = pictureBox9;
picture[2, 2] = pictureBox10;
picture[2, 3] = pictureBox11;
picture[3, 0] = pictureBox12;
picture[3, 1] = pictureBox13;
picture[3, 2] = pictureBox14;
picture[3, 3] = pictureBox15;
UpdatePictures();
}
private void UpdatePictures()
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
picture[i, j].Image = game.getTile(i, j).getImage();
}
}
}
private void pict1_Click(object sender, EventArgs e)
{
}
private void startGameToolStripMenuItem_Click(object sender, EventArgs e)
{
int p;
Random gen = new Random();
int nc;
for (p = 0; p < 2000; p++)
{
nc = gen.Next(0, 16);
if (game.isMovePosible(nc))
{
game.moveTile(nc);
}
}
UpdatePictures();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
FormAbout formAbout = new FormAbout();
formAbout.ShowDialog();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
Application.Restart();
}
private void exitGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void pictureBox0_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
What I have tried:
We have method for randomize position of tiles in class Tile but it must change onclick by mouse on box. How to do?