1 Востаннє редагувалося voldkost (01.12.2016 21:17:33)

Тема: Перенести дані масиву з одного класу в інший

Є в мене програма Лабіринт. Генерує рандомний лабіринт розбитий на клітинки. Кожна клітинка має 4 стіни зі значенням 0 або 1.
Також створив мітку(гравець) якою потрібно проходити лабіринт.
Мені треба зробити щось таке:

if (keyData == Keys.Up && Cells[x][y].Walls[0]) 
{ 
label1.Top += -2; 
return true; 
} 

(це в frmMaze знаходиться)
Мені треба якось викликати масив цей з іншого класу щоб коли Є стіна то return false якщо ні то true

Cell.cs

Прихований текст

using System;
using System.Collections;
using System.Drawing;

namespace MazeSolution
{
    /// <summary>
    /// Summary description for Cell.
    /// </summary>
    public class Cell
    {
        public enum CellState
        {
            FREE = 0,
            WALLA = 1,
            WALLB = 2,
            WALLC = 3,
            WALLD = 4,
            WALLE = 5,
            WALLF = 6,
            WALLG = 7,
            WALLH = 8,
            WALLI = 9,
            WALLJ = 10,
            WALLK = 11,
            WALLL = 12,
            WALLM = 13,
            WALLN = 14,
            WALLO = 15,
            WALLP = 16
        }

        public const int PADDING = 20;
        public static int kCellSize = 20;
        public int[] Walls  = new int[4]{1, 1, 1, 1};
        public CellState cellState = CellState.FREE;
        public int Row;
        public int Column;
        private long Seed = DateTime.Now.Ticks;
        public static Random TheRandom;
        
        
        public Cell()
        {
            TheRandom = new Random((int)Seed);
        }

        public bool HasAllWalls()
        {
            for (int i = 0; i < 4; i++)
            {
                 if (Walls[i] == 0)
                     return false;
            }

            return true;
        }

        public void KnockDownWall(int theWall)
        {
            Walls[theWall] = 0;
        }

        public void KnockDownWall(Cell theCell)
        {
            // find adjacent wall
            int theWallToKnockDown = FindAdjacentWall(theCell);
            Walls[theWallToKnockDown] = 0;
            int oppositeWall = (theWallToKnockDown + 2) % 4;
            theCell.Walls[oppositeWall] = 0;
        }


        public int FindAdjacentWall(Cell theCell)
        {
            if (theCell.Row == Row) 
            {
                if (theCell.Column < Column)
                    return 0;
                else
                    return 2;
            }
            else // columns are the same
            {
                if (theCell.Row < Row)
                    return 1;
                else
                    return 3;
            }
        }

        public int GetRandomWall()
        {
            int nextWall = TheRandom.Next(0, 3);
            while ( (Walls[nextWall] == 0)  
            ||        ((Row == 0) && (nextWall == 0)) ||
                    ((Row == Maze.kDimension - 1) && (nextWall == 2)) ||
                    ((Column == 0) && (nextWall == 1)) ||
                    ((Column == Maze.kDimension - 1) && (nextWall == 3)) 
                   )
            {
                nextWall = TheRandom.Next(0, 3);
            }

            return nextWall;
        }

        public void Draw(Graphics g)
        {
            Pen fillPen = null;
            Brush fillBrush = null;

            // Each wall type is drawn in a different color.
            switch( cellState )
            {
                case CellState.WALLA:
                    fillPen = new Pen( Color.BlueViolet );
                    fillBrush = Brushes.BlueViolet;
                    break;
                case CellState.WALLB:
                    fillPen = new Pen( Color.DarkViolet );
                    fillBrush = Brushes.DarkViolet;
                    break;
                case CellState.WALLC:
                    fillPen = new Pen( Color.SlateBlue );
                    fillBrush = Brushes.SlateBlue;
                    break;
                case CellState.WALLD:
                    fillPen = new Pen( Color.MediumPurple );
                    fillBrush = Brushes.MediumPurple;
                    break;
                case CellState.WALLE:
                    fillPen = new Pen( Color.Green );
                    fillBrush = Brushes.Green;
                    break;
                case CellState.WALLF:
                    fillPen = new Pen( Color.DarkGreen );
                    fillBrush = Brushes.DarkGreen;
                    break;
                case CellState.WALLG:
                    fillPen = new Pen( Color.MidnightBlue );
                    fillBrush = Brushes.MidnightBlue;
                    break;
                case CellState.WALLH:
                    fillPen = new Pen( Color.Indigo );
                    fillBrush = Brushes.Indigo;
                    break;
                case CellState.WALLI:
                    fillPen = new Pen( Color.Navy );
                    fillBrush = Brushes.Navy;
                    break;
                case CellState.WALLJ:
                    fillPen = new Pen( Color.RoyalBlue );
                    fillBrush = Brushes.RoyalBlue;
                    break;
                case CellState.WALLK:
                    fillPen = new Pen( Color.SlateGray );
                    fillBrush = Brushes.SlateGray;
                    break;
                case CellState.WALLL:
                    fillPen = new Pen( Color.DarkOliveGreen );
                    fillBrush = Brushes.DarkOliveGreen;
                    break;
                case CellState.WALLM:
                    fillPen = new Pen( Color.DarkSlateBlue );
                    fillBrush = Brushes.DarkSlateBlue;
                    break;
                case CellState.WALLN:
                    fillPen = new Pen( Color.DodgerBlue );
                    fillBrush = Brushes.DodgerBlue;
                    break;
                case CellState.WALLO:
                    fillPen = new Pen( Color.ForestGreen );
                    fillBrush = Brushes.ForestGreen;
                    break;
                case CellState.WALLP:
                    fillPen = new Pen( Color.SkyBlue );
                    fillBrush = Brushes.SkyBlue;
                    break;
            }

            // First fill in all cells that are not free...
            if ( (int)cellState > (int)CellState.FREE )
            {
                g.FillRectangle(fillBrush, Row*kCellSize + PADDING + 1, Column*kCellSize + PADDING + 1, kCellSize - 1, kCellSize - 1);

                if (Walls[0] == 0)
                    g.DrawLine(fillPen, Row*kCellSize + PADDING, Column*kCellSize + PADDING, (Row+1) * kCellSize   + PADDING, Column*kCellSize +  + PADDING);
                if (Walls[1] == 0)
                    g.DrawLine(fillPen, Row*kCellSize  + PADDING, Column*kCellSize + PADDING, Row*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);
                if (Walls[2] == 0)
                    g.DrawLine(fillPen, Row*kCellSize + PADDING, (Column+1)*kCellSize + PADDING, (Row+1)*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);
                if (Walls[3] == 0)
                    g.DrawLine(fillPen, (Row+1)*kCellSize + PADDING , Column*kCellSize + PADDING, (Row+1)*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);
            }

            // Then draw the cell walls.
            if (Walls[0] == 1)
                g.DrawLine(Pens.Blue, Row*kCellSize + PADDING, Column*kCellSize + PADDING, (Row+1) * kCellSize   + PADDING, Column*kCellSize +  + PADDING);

            if (Walls[1] == 1)
                g.DrawLine(Pens.Blue, Row*kCellSize  + PADDING, Column*kCellSize + PADDING, Row*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);

            if (Walls[2] == 1)
                g.DrawLine(Pens.Blue, Row*kCellSize + PADDING, (Column+1)*kCellSize + PADDING, (Row+1)*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);

            if (Walls[3] == 1)
                g.DrawLine(Pens.Blue,(Row+1)*kCellSize + PADDING , Column*kCellSize + PADDING, (Row+1)*kCellSize + PADDING, (Column+1)*kCellSize + PADDING);
        }
        
      
    }
}

Maze.cs

Прихований текст

Maze.cs
using System;
using System.Collections;
using System.Drawing;
using System.Threading;

/*
 * create a CellStack (LIFO) to hold a list of cell locations  
set TotalCells = number of cells in grid  
choose a cell at random and call it CurrentCell  
set VisitedCells = 1  
   
while VisitedCells < TotalCells  
find all neighbors of CurrentCell with all walls intact   
if one or more found  
choose one at random  
knock down the wall between it and CurrentCell  
push CurrentCell location on the CellStack  
make the new cell CurrentCell  
add 1 to VisitedCells 
else  
pop the most recent cell entry off the CellStack  
make it CurrentCell 
endIf 
endWhile  
*/

namespace MazeSolution
{
    /// <summary>
    /// Summary description for Maze.
    /// </summary>
    public class Maze
    {
        public static int kDimension = 20;
        Cell[][] Cells = null;
        Stack CellStack = new Stack();
        int VisitedCells = 1;
        int TotalCells = kDimension * kDimension;
        Cell CurrentCell = null;

        // A delegate type for hooking up completion notifications.
        public delegate void MazeEventHandler(object sender, EventArgs e);
        
        public event MazeEventHandler MazeSolutionComplete;

        public Maze()
        {
            Initialize();
        }

        private ArrayList GetNeighborsWithWalls(Cell aCell)
        {
            ArrayList Neighbors = new ArrayList();
            //int count = 0;
            for (int countRow = -1; countRow <= 1; countRow++)
                for (int countCol = -1; countCol <= 1; countCol++)
                {
                    if ( (aCell.Row + countRow < kDimension) &&  
                         (aCell.Column+countCol < kDimension) &&
                         (aCell.Row+countRow >= 0) &&
                         (aCell.Column+countCol >= 0) &&
                         ((countCol == 0) || (countRow == 0)) &&
                         (countRow != countCol)
                        )
                    {
                        if (Cells[aCell.Row+countRow][aCell.Column+countCol].HasAllWalls())
                        {
                            Neighbors.Add( Cells[aCell.Row+countRow][aCell.Column+countCol]);
                        }
                    }
                }

            return Neighbors;
        }

        public void Initialize()
        {
            Cells = new Cell[kDimension][];
            TotalCells = kDimension * kDimension;
            for (int i = 0; i < kDimension; i++)
            {
                Cells[i] = new Cell[kDimension];
                for (int j = 0; j < kDimension; j++)
                {
                    Cells[i][j] =  new Cell();
                    Cells[i][j].Row = i;
                    Cells[i][j].Column = j;
                }
            }

            CurrentCell = Cells[0][0];
            VisitedCells = 1;
            CellStack.Clear();

        }

        public void  Generate()
        {
            while (VisitedCells < TotalCells)
            {
                // get a list of the neighboring cells with all walls intact
                ArrayList AdjacentCells = GetNeighborsWithWalls(CurrentCell);
                // test if a cell like this exists
                if (AdjacentCells.Count > 0)
                {
                    // yes, choose one of them, and knock down the wall between it and the current cell
                    int randomCell = Cell.TheRandom.Next(0, AdjacentCells.Count);
                    Cell theCell = ((Cell)AdjacentCells[randomCell]);
                    CurrentCell.KnockDownWall(theCell);
                    CellStack.Push(CurrentCell); // push the current cell onto the stack
                    CurrentCell = theCell; // make the random neighbor the new current cell
                    VisitedCells++;
                }
                else
                {
                    // No cells with walls intact, pop current cell from stack
                    CurrentCell = (Cell)CellStack.Pop();
                }

            }

            // Show the entry and exit
            Cells[0][0].Walls[0] = 0;
            Cells[kDimension-1][kDimension-1].Walls[3] = 0;

        }

        public void SolveIt( Cell.CellState cellState )
        {
            bool steadyState = true;

            // Loop through the maze, with each pass blocking off more and more
            // dead ends until steadyState = true.
            do
            {
                steadyState = true;
                
                for( int i=0; i<kDimension; i++ )
                {
                    for( int j=0; j<kDimension; j++ )
                    {
                        if( Cells[i][j].cellState == Cell.CellState.FREE )
                        {
                            if ( !IsFree(i,j) ) 
                            {
                                Cells[i][j].cellState = cellState;
                                steadyState = false;
                            }
                        }
                    }
                    Thread.Sleep(0);
                }
            } while( !steadyState );
        }

        public void SolveItBackward( Cell.CellState cellState )
        {
            bool steadyState = true;

            // Loop backward through the maze, with each pass blocking off more and more
            // dead ends until steadyState = true.
            do
            {
                steadyState = true;
                
                for( int i=kDimension-1; i>=0; i-- )
                {
                    for( int j=kDimension-1; j>=0; j-- )
                    {
                        if( Cells[i][j].cellState == Cell.CellState.FREE )
                        {
                            if ( !IsFree(i,j) ) 
                            {
                                Cells[i][j].cellState = cellState;
                                steadyState = false;
                            }
                        }
                    }
                    Thread.Sleep(0);
                }
            } while( !steadyState );
        }

        // Each solution method just uses a different wall type
        // which is drawn in a different color so that we can
        // see each threads progress.  When complete, the event
        // MazeSolutionComplete is raised.
        public void SolveA()
        {
            SolveIt( Cell.CellState.WALLA );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveB()
        {
            SolveItBackward( Cell.CellState.WALLB );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveC()
        {
            SolveIt( Cell.CellState.WALLC );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveD()
        {
            SolveItBackward( Cell.CellState.WALLD );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveE()
        {
            SolveIt( Cell.CellState.WALLE );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveF()
        {
            SolveItBackward( Cell.CellState.WALLF );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveG()
        {
            SolveIt( Cell.CellState.WALLG );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveH()
        {
            SolveItBackward( Cell.CellState.WALLH );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveI()
        {
            SolveIt( Cell.CellState.WALLI );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveJ()
        {
            SolveItBackward( Cell.CellState.WALLJ );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveK()
        {
            SolveIt( Cell.CellState.WALLK );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveL()
        {
            SolveItBackward( Cell.CellState.WALLL );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveM()
        {
            SolveIt( Cell.CellState.WALLM );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveN()
        {
            SolveItBackward( Cell.CellState.WALLN );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveO()
        {
            SolveIt( Cell.CellState.WALLO );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        public void SolveP()
        {
            SolveItBackward( Cell.CellState.WALLP );
            MazeSolutionComplete( this, EventArgs.Empty );
        }

        /// <summary>
        /// This is the key to solving the maze.  If a cell isn't free, block it off.
        /// We determine whether it is free by examining its walls and the free state
        /// of all neighboring cells.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private bool IsFree( int x, int y )
        {
            int walls = 0;

            if( Cells[x][y].Walls[0] == 1 )
                walls ++;
            else if( y > 0 && ((int)Cells[x][y-1].cellState > (int)Cell.CellState.FREE ))
                walls++;

            if( Cells[x][y].Walls[1] == 1 )
                walls ++;
            else if( x > 0 && ((int)Cells[x-1][y].cellState > (int)Cell.CellState.FREE ))
                walls++;

            if( Cells[x][y].Walls[2] == 1 )
                walls ++;
            else if( y < kDimension-1 && ((int)Cells[x][y+1].cellState  > (int)Cell.CellState.FREE ))
                walls++;

            if( Cells[x][y].Walls[3] == 1 )
                walls ++;
            else if( x < kDimension-1 && ((int)Cells[x+1][y].cellState  > (int)Cell.CellState.FREE ))
                walls++;
            
            return (walls < 3);
        }

        public void Draw(Graphics g)
        {
            for (int i = 0; i < kDimension; i++)
                for (int j = 0; j < kDimension; j++)
                {
                    Cells[i][j].Draw(g);
                }
        }

        public void Reset()
        {
            for (int i = 0; i < kDimension; i++)
                for (int j = 0; j < kDimension; j++)
                {
                    Cells[i][j].cellState = Cell.CellState.FREE;
                }
        }

       
        
    }
}

frmMaze.cs Тут в кінці є метод в якому треба використати масив

Прихований текст

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using  System.Runtime.InteropServices;
namespace MazeSolution
{
    /// <summary>
    /// Summary description for frmMaze.
    /// </summary>
    public class frmMaze : System.Windows.Forms.Form
    {
        private IContainer components;
        // maze array
        private System.Drawing.Printing.PrintDocument printDocument1;
        private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem PrintMenu;
        private System.Windows.Forms.MenuItem PreviewMenu;
        private System.Windows.Forms.MenuItem DimensionsMenu;
        private System.Windows.Forms.MenuItem menuItem3;
        private System.Windows.Forms.StatusBar statusBar;
        private System.Windows.Forms.MenuItem ResetMenu;
        private System.Windows.Forms.MenuItem SolveTwoThreads;
        private System.Windows.Forms.MenuItem SolveSingleThread;
        private System.Windows.Forms.MenuItem SolveFourThreads;
        private System.Windows.Forms.MenuItem SolveEightThreads;
        private System.Windows.Forms.MenuItem Solve16Threads;
        private System.Windows.Forms.MenuItem mnuExit;
        private System.Windows.Forms.MenuItem menuItem4;
        private Maze TheMaze = null;
        private int threads = 0;
        private int threadCount = 0;
        private System.Windows.Forms.MenuItem SolveThreadPool;
        private MenuItem menuItem2;
        private Label label1;
        private DateTime startTime;

        public frmMaze()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            SetStyle(ControlStyles.AllPaintingInWmPaint,true);
            SetStyle(ControlStyles.UserPaint,true);
            SetStyle(ControlStyles.DoubleBuffer,true);

            this.Cursor = Cursors.WaitCursor;
            TheMaze = new Maze();
            TheMaze.Generate();
            TheMaze.MazeSolutionComplete += new Maze.MazeEventHandler(MazeComplete);
            this.Cursor = Cursors.Default;

            SetBounds(this.Left, this.Top, (Maze.kDimension + 8) * Cell.kCellSize + Cell.PADDING, (Maze.kDimension + 12) * Cell.kCellSize + Cell.PADDING + statusBar.Height );
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new frmMaze());
            
        }

        private void frmMaze_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.FillRectangle(Brushes.White, ClientRectangle);
            TheMaze.Draw(g);        
        }

        private void mnuExit_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            TheMaze.Draw(e.Graphics);        
        }

        private void PreviewMenu_Click(object sender, System.EventArgs e)
        {
         this.printPreviewDialog1.ShowDialog();
        }

        private void PrintMenu_Click(object sender, System.EventArgs e)
        {
          printDocument1.Print();
        }

        private void DimensionsMenu_Click(object sender, System.EventArgs e)
        {
            DimensionsDialog theDialog = new DimensionsDialog();
            theDialog.numericUpDown1.Value = Maze.kDimension;
        //    theDialog.numericUpDown2.Value = Cell.kCellSize;
            if (theDialog.ShowDialog() == DialogResult.OK)
            {
                label1.Location = new Point(22, 22);
                Maze.kDimension =     (int)theDialog.numericUpDown1.Value;
            //    Cell.kCellSize =  (int)theDialog.numericUpDown2.Value;
                TheMaze.Initialize();
                TheMaze.Generate();
                SetBounds(this.Left, this.Top, (Maze.kDimension + 8) * Cell.kCellSize + Cell.PADDING, (Maze.kDimension + 12) * Cell.kCellSize + Cell.PADDING + statusBar.Height );
                Invalidate();
            }
        }

        private void ResetMenu_Click(object sender, System.EventArgs e)
        {
            statusBar.Text = "";
            TheMaze.Reset();
            this.Refresh();
        }

        private void SolveSingleThread_Click(object sender, System.EventArgs e)
        {
            // Initialize all necessary variables
            threads = 1;
            threadCount = 0;
            statusBar.Text = "";

            // Clear the maze and refresh the form before we start the clock
            TheMaze.Reset();
            this.Refresh();

            // Set the cursor and start the clock
            this.Cursor = Cursors.WaitCursor;
            startTime = DateTime.Now;

            // Create one thread and start it running
            Thread aThread = new Thread(new ThreadStart(TheMaze.SolveA));
            aThread.Start();
        }

        private void SolveTwoThreads_Click(object sender, System.EventArgs e)
        {
            // Run the code for a single thread...
            SolveSingleThread_Click(sender, e);
            threads = 2;

            // And add one more thread
            Thread bThread = new Thread(new ThreadStart(TheMaze.SolveB));
            bThread.Start();
        }

        private void SolveFourThreads_Click(object sender, System.EventArgs e)
        {
            SolveTwoThreads_Click(sender, e);
            threads = 4;

            // Add two additional threads
            Thread cThread = new Thread(new ThreadStart(TheMaze.SolveC));
            Thread dThread = new Thread(new ThreadStart(TheMaze.SolveD));
            cThread.Start();
            dThread.Start();
        }

        private void SolveEightThreads_Click(object sender, System.EventArgs e)
        {
            SolveFourThreads_Click(sender, e);
            threads = 8;

            // Add four additional threads
            Thread eThread = new Thread(new ThreadStart(TheMaze.SolveE));
            Thread fThread = new Thread(new ThreadStart(TheMaze.SolveF));
            Thread gThread = new Thread(new ThreadStart(TheMaze.SolveG));
            Thread hThread = new Thread(new ThreadStart(TheMaze.SolveH));
            eThread.Start();
            fThread.Start();
            gThread.Start();
            hThread.Start();

        }

        private void Solve16Threads_Click(object sender, System.EventArgs e)
        {
            SolveEightThreads_Click(sender, e);
            threads = 16;

            // Add eight additional threads
            Thread iThread = new Thread(new ThreadStart(TheMaze.SolveI));
            Thread jThread = new Thread(new ThreadStart(TheMaze.SolveJ));
            Thread kThread = new Thread(new ThreadStart(TheMaze.SolveK));
            Thread lThread = new Thread(new ThreadStart(TheMaze.SolveL));
            Thread mThread = new Thread(new ThreadStart(TheMaze.SolveM));
            Thread nThread = new Thread(new ThreadStart(TheMaze.SolveN));
            Thread oThread = new Thread(new ThreadStart(TheMaze.SolveO));
            Thread pThread = new Thread(new ThreadStart(TheMaze.SolveP));
            iThread.Start();
            jThread.Start();
            kThread.Start();
            lThread.Start();
            mThread.Start();
            nThread.Start();
            oThread.Start();
            pThread.Start();

        }
        
        private void SolveThreadPool_Click(object sender, System.EventArgs e)
        {
            // Reset all necessary variables
            threads = 8;
            threadCount = 0;
            statusBar.Text = "";

            // Clear the maze and refresh the form
            TheMaze.Reset();
            this.Refresh();

            // Start the clock and queue up 8 threads for execution
            this.Cursor = Cursors.WaitCursor;
            startTime = DateTime.Now;
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncA));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncB));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncC));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncD));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncE));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncF));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncG));
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadFuncH));
        }

        private void ThreadFuncA(Object O)
        {
            TheMaze.SolveA();
        }

        private void ThreadFuncB(Object O)
        {
            TheMaze.SolveB();
        }

        private void ThreadFuncC(Object O)
        {
            TheMaze.SolveC();
        }

        private void ThreadFuncD(Object O)
        {
            TheMaze.SolveD();
        }

        private void ThreadFuncE(Object O)
        {
            TheMaze.SolveE();
        }

        private void ThreadFuncF(Object O)
        {
            TheMaze.SolveF();
        }

        private void ThreadFuncG(Object O)
        {
            TheMaze.SolveG();
        }

        private void ThreadFuncH(Object O)
        {
            TheMaze.SolveH();
        }

        private void MazeComplete(object sender, EventArgs e)
        {
            // Roll call for the threads
            threadCount++;

            // When they all call in, we know we're done so put up the results
            if( threadCount == threads )
            {
                this.Refresh();
                
                statusBar.Text = "Completed using "  + " threads in " + (DateTime.Now - startTime);            
                this.Cursor = Cursors.Default;
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
    //       MazeSolution.Cell Cells = new MazeSolution.Cell masWall[x][y];
           
            //capture up arrow key
            if (keyData == Keys.Up && )
            {
                label1.Top += -2;
                return true;
            }

            //capture down arrow key
            if (keyData == Keys.Down)
            {
                label1.Top += 2;
                return true;
            }
            //capture left arrow key
            if (keyData == Keys.Left)
            {
                label1.Left += -2;
                return true;
            }
            //capture right arrow key
            if (keyData == Keys.Right)
            {
                label1.Left += 2;
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);

        }

       
       

       

        
    }
}

2 Востаннє редагувалося koala (01.12.2016 19:49:23)

Re: Перенести дані масиву з одного класу в інший

Використовуйте тег code 8)

3

Re: Перенести дані масиву з одного класу в інший

koala написав:

Використовуйте тег code 8)

відредагував, спочатку не побачив цього тегу