Click here to Skip to main content
15,942,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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()//set pictures on positions in boxes
        {
            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)//generate random positions of parts of picture
        {
            int p;
            Random gen = new Random();
            int nc;
            for (p = 0; p < 2000; p++)
            {
                nc = gen.Next(0, 16);
                if (game.isMovePosible(nc))
                {
                    //Console.Write("ok");s000fff
                      game.moveTile(nc);
                }
            }
            UpdatePictures();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        //info about author
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormAbout formAbout = new FormAbout();
            formAbout.ShowDialog();
        }

        //restart game
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }

        //close game
        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?
Posted
Comments
BillWoodruff 28-Mar-16 12:41pm    
Please describe clearly exactly what you mean by "make moves between neighbors' pictures."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900