Example #1
0
        //*************************************************************************************************

        private void pan_click(object sender, EventArgs e)
        {
            if (userTurn)
            {
                //check for checkmate
                //in multiplayer, this seems to cause oponent piece to switch from alive to dead
                //              **should be fixed, keep testing
                if (checkMate(game.squares))
                {
                    //end game here
                    MessageBox.Show("CHECK MATE!!!    Loser!");
                }

                var panel = sender as Panel;

                int    x     = (panel.Location.X - 140) / 80;
                int    y     = (panel.Location.Y - 20) / 80;
                string pname = game.squares[x, y].name;
                PTypes type  = game.squares[x, y].type;

                if (fclick)
                {
                    //check which piece is selected
                    for (int a = 0; a < 16; a++)
                    {
                        if (game.userPieces[a].name == pname && game.userPieces[a].type == type)
                        {
                            currentSelection = a;
                            showValidMoves(game.userPieces[a], game.squares, ref game.MovBoard, ref game.renderer);
                            break;
                        }
                    }
                    fclick = false;
                }
                else
                {
                    //move
                    if (game.MovBoard[x, y].moveable)
                    {
                        multiplayerMove = true;
                        bool isCheck = false;
                        game.userPieces[currentSelection] = move(game.userPieces[currentSelection], x, y, true, ref game.squares, out isCheck);
                        multiplayerMove = false;

                        render();

                        //problem here!
                        if (checkMate(game.squares))
                        {
                            MessageBox.Show("CHECK MATE  Loser!!");
                        }

                        //reset background color
                        for (int a = 0; a < 8; a++)
                        {
                            for (int b = 0; b < 8; b++)
                            {
                                if (a % 2 == 0)
                                {
                                    game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.White : Color.Gray;
                                }
                                else
                                {
                                    game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.Gray : Color.White;
                                }
                            }
                        }

                        //if user is in check, alert
                        if (isCheck)
                        {
                            MessageBox.Show("Can't move, in check");
                        }
                    }

                    //reset background colors
                    for (int a = 0; a < 8; a++)
                    {
                        for (int b = 0; b < 8; b++)
                        {
                            if (a % 2 == 0)
                            {
                                game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.White : Color.Gray;
                            }
                            else
                            {
                                game.renderer[a, b].BackColor = (b % 2 == 0) ? Color.Gray : Color.White;
                            }
                        }
                    }

                    fclick = true;
                }
            }
        }
Example #2
0
    private IEnumerable <ICoroutine> MyLoading()
    {
        NewMap();

        _TABLE.SetPath("Tables/");
        foreach (var item in _TABLE.LoadT地形Async())
        {
            yield return(item);
        }

        ResetViewport();
        // 预设地形分类
        Dictionary <string, List <T地形> > dics = new Dictionary <string, List <T地形> >();

        foreach (var item in _TABLE._T地形)
        {
            string key;
            if (string.IsNullOrEmpty(item.Texture))
            {
                key = "碰撞区域";
            }
            else
            {
                key = item.Texture.Split('\\')[1];
            }

            List <T地形> list;
            if (!dics.TryGetValue(key, out list))
            {
                list = new List <T地形>();
                dics.Add(key, list);
            }

            list.Add(item);
        }
        // 加载预设
        foreach (var type in dics)
        {
            var cb = ___CBTypes();
            cb.Name       = type.Key;
            cb.Text       = type.Key;
            cb.X          = PTypes.ChildCount * cb.Width + 5;
            cb.OnChecked += (sender1, e1) =>
            {
                PPre.Clear();

                List <T地形> list = dics[sender1.Name];
                for (int i = 0; i < list.Count; i++)
                {
                    var item = list[i];

                    TextureBox container = new TextureBox();
                    container.Width       = 100;
                    container.Height      = 100;
                    container.X           = 10 + (i % 5) * (container.Width + 5);
                    container.Y           = 5 + (i / 5) * (container.Height + 5);
                    container.DisplayMode = EViewport.Strength;
                    container.Texture     = PATCH.GetNinePatch(COLOR.TransparentBlack, COLOR.Black, 1);

                    TextureBox tb = new TextureBox();
                    tb.Tag         = item;
                    tb.Width       = container.Width;
                    tb.Height      = container.Height;
                    tb.DisplayMode = EViewport.Adapt;
                    tb.Flip        = item.Flip;
                    if (string.IsNullOrEmpty(item.Texture))
                    {
                        // 没有图像时绘制碰撞区域
                        tb.DrawAfterEnd = (sender, sb, e) =>
                        {
                            float   scale;
                            VECTOR2 offset;
                            __GRAPHICS.ViewAdapt(item.BoundingBox.Size, tb.Size, out scale, out offset);
                            RECT view = sender.ViewClip;
                            //foreach (var area in item._Hit)
                            //{
                            //    sb.Draw(TEXTURE.Pixel,
                            //        new RECT(view.X + offset.X + (area.X - item.BoundingBox.X) * scale,
                            //            view.Y + offset.Y + (area.Y - item.BoundingBox.Y) * scale,
                            //            area.Width * scale, area.Height * scale),
                            //        new COLOR(255, 0, 0, 128));
                            //}
                            item.DrawHitArea(view.X + offset.X, view.Y + offset.Y, scale);
                        };
                    }
                    else
                    {
                        tb.Texture = Content.Load <TEXTURE>(item.Texture);
                    }
                    tb.Clicked += (sender, e) =>
                    {
                        // 单击选中地形
                        painting.ID      = item.ID;
                        painting.Data    = item;
                        painting.Texture = tb.Texture;
                    };

                    container.Add(tb);
                    PPre.Add(container);
                }
            };
            PTypes.Add(cb);
        }
        ((CheckBox)PTypes[0]).DoCheck();

        font = new UIText();
        //font.FontSize = 12;
        font.FontColor  = COLOR.White;
        font.TextShader = new TextShader()
        {
            Color = COLOR.Silver,
        };
        font.TextAlignment = EPivot.BottomLeft;
    }