Exemplo n.º 1
0
        private void DrawBlocksLines(DrawLineData data)
        {
            SpriteBatch batch = data.Batch;

            Point[] line     = data.LineInfo;
            Point[] position = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                var temp = _blocks[line[i].X * 8 + line[i].Y];
                position[i] = new Point(temp.Position.X + temp.Size.X / 2, temp.Position.Y + temp.Size.Y / 2);
            }
            for (int i = 0; i < 3; i++)
            {
                var temp1 = position[i];
                var temp2 = position[i + 1];
                if (temp1 == temp2)
                {
                    continue;
                }
                if (temp1.X > temp2.X || temp1.Y > temp2.Y)
                {
                    var area = new Rectangle(temp2.X, temp2.Y, temp1.X - temp2.X + 10, temp1.Y - temp2.Y + 10);
                    batch.Draw(_blocks[i].LineTexture, area, Color.White);
                }
                else
                {
                    var area = new Rectangle(temp1.X, temp1.Y, temp2.X - temp1.X + 10, temp2.Y - temp1.Y + 10);
                    batch.Draw(_blocks[i].LineTexture, area, Color.White);
                }
            }
            //Thread.Sleep(1000);
        }
Exemplo n.º 2
0
        public void Draw(SpriteBatch batch)
        {
            batch.Draw(Background,
                       new Rectangle(0, 0, _size.X, _size.Y), //draw background
                       Color.White);
            if (_searchFlag == false)
            {
                getLine     = CanLine();
                _searchFlag = true;
            }

            if (_num == 0 || getLine.Count == 0)
            {
                batch.DrawString(font, "congratulation!There is no blocks can line", new Vector2(_size.X / 2, _size.Y / 2), Color.Red);
                return;
            }
            if (timer.GetLatsTime() <= 0)
            {
                batch.DrawString(font, "time over!", new Vector2(_size.X / 2, _size.Y / 2), Color.Red);
                return;
            }
            timer.Draw(batch);
            MouseState mouseState    = Mouse.GetState();
            var        mousePosition = new Point(mouseState.X, mouseState.Y);

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                _nowChoose = -1;
            }
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (_isChoose[i * 8 + j] == false)
                    {
                        if (mousePosition.IsIn(_blocks[i * 8 + j].Position, _blockSize))
                        {
                            _blocks[i * 8 + j].Draw(batch, true);
                            if (mouseState.LeftButton == ButtonState.Pressed)
                            {
                                if (_nowChoose == -1)
                                {
                                    _nowChoose = i * 8 + j;
                                }
                                else
                                {
                                    Point a = new Point(i, j);
                                    Point b = new Point(_nowChoose / 8, _nowChoose % 8);
                                    if (a == b)
                                    {
                                        continue;
                                        //_nowChoose = -1;
                                        //break;
                                    }
                                    foreach (var line in getLine)
                                    {
                                        if ((a == ((Point[])line)[0] && b == ((Point[])line)[1]) || (a == ((Point[])line)[1] && b == ((Point[])line)[0]))
                                        {
                                            var lines    = (Point[])lineInfo[getLine.IndexOf(line)];
                                            var tempData = new DrawLineData(batch, lines);
                                            //Thread thread = new Thread(() => DrawBlocksLines(tempData));
                                            //thread.Start();

                                            //DrawBlocksLines(tempData);
                                            drawLineTask.Add(tempData);
                                            _blocksData[a.X][a.Y] = 0;
                                            _blocksData[b.X][b.Y] = 0;
                                            _isChoose[_nowChoose] = true;
                                            _isChoose[i * 8 + j]  = true;
                                            _nowChoose            = -1;
                                            _num       -= 2;
                                            _searchFlag = false;
                                            break;
                                        }
                                    }
                                    _nowChoose = -1;
                                }
                            }
                        }
                        else if (_nowChoose == i * 8 + j)
                        {
                            _blocks[i * 8 + j].Draw(batch, true);
                        }
                        else
                        {
                            _blocks[i * 8 + j].Draw(batch);
                        }
                    }
                }
            }
            for (int i = 0; i < drawLineTask.Count; i++)
            {
                var temp = (DrawLineData)drawLineTask[i];
                DrawBlocksLines(temp);
                temp.Times--;
                if (temp.Times <= 0)
                {
                    drawLineTask.RemoveAt(i);
                }
            }
        }