예제 #1
0
        private void gridPanel_MouseUp(object sender, MouseEventArgs e)
        {
            DrawLineCommand tempDlc;
            List<DrawTileCommand> tempTilesToDraw = new List<DrawTileCommand>();

            foreach(DrawLineCommand dlc in DrawLineList) {
                foreach(DrawTileCommand dtc in dlc.TilesDrawn)
                tempTilesToDraw.Add(dtc);
            }

            tempDlc = new DrawLineCommand(this, tempTilesToDraw);
            commandQueue.Push(tempDlc);
            DrawLineList.Clear();

            mouseDown = false;
            oldMouseX = -1;
            oldMouseY = -1;
        }
예제 #2
0
        private void DrawTileLine(int oldMouseX, int oldMouseY, int newX, int newY)
        {
            int x = newX;
                int y = newY;
                if (oldMouseX >= 0 && oldMouseY >= 0)
                {
                    int distanceX = x - oldMouseX;
                    int distanceY = y - oldMouseY;

                    int dx = -1;
                    int dy = -1;

                    if (distanceX < 0) dx = 1;
                    if (distanceY < 0) dy = 1;

                    distanceX = Math.Abs(distanceX);
                    distanceY = Math.Abs(distanceY);

                    int counter = 0;
                    List<DrawTileCommand> tilesToDraw = new List<DrawTileCommand>();
                    while (distanceX > 0 || distanceY > 0)
                    {

                        if (x + dx < tiles.GetLength(0) && x + dx >= 0 && y + dy < tiles.GetLength(1) && y + dy >= 0)
                        {

                            DrawTileCommand com = new DrawTileCommand(this, x, y, tiles[x, y].Image, currentImage);
                            tilesToDraw.Add(com);
                            //tiles[x, y].Image = currentImage;
                            counter++;
                            if (distanceX > 0) distanceX--;
                            if (distanceY > 0) distanceY--;
                            if (distanceX == 0) dx = 0;
                            if (distanceY == 0) dy = 0;
                            x += dx;
                            y += dy;
                        }

                        else
                        {
                            break;
                        }
                    }

                    ICommand dlc = new DrawLineCommand(this, tilesToDraw);
                    DrawLineList.Add(dlc as DrawLineCommand);
                    dlc.Execute();
                    redoCommandQueue.Clear();

            }
        }