用SliverLight做三国杀(六)让卡牌在界面中动起来
2011-04-07 17:57
246 查看
前面几个随笔分别定义了Card、CardHeap、Player类,我们现在可以把他们结合起来,制作一个控件让玩家出牌了。
定义个一个控件玩家出牌区.xaml,设置为控件
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="SilverlightApplication1.玩家出牌区" d:DesignWidth="1029" d:DesignHeight="252"> <Grid x:Name="LayoutRoot"> <Image Source="img/b.png" Stretch="Fill" d:IsLocked="True"/> </Grid> </UserControl>
后台代码需要动态加载上去,其实也就是画几个Rectangle,然后给他们鼠标操作的事件
首先定义一个静态变量choose_cardid,用来标记选中的卡牌的ID号。
public static int choose_CardID=0;//0代表当前没有选中的卡片
接着定义画卡片的函数,通过LayoutRoot.Children.Add(r);将矩形添加至
public void DrawCard(List<Card> card) { //定义有count张牌 cardcount = card.Count; int cc = -550, ccend = 550; for(int i=1;i<=card.Count;i++) { Rectangle r=new Rectangle(); r.Name="r"+i.ToString(); ToolTipService.SetToolTip(r, card[i - 1].Name); //r.Tag = card[i - 1].Name; r.Fill = new ImageBrush() { ImageSource = new BitmapImage(new Uri( card[i-1].ImagePath , UriKind.Relative)) }; //card.RemoveRange(0, 1); r.Width=96; r.Height=134; r.Margin=new Thickness(cc,80,0,0); LayoutRoot.Children.Add(r); cc=cc+1004/card.Count; //如果有多张卡片会显示成折叠效果 } //int A=0; foreach (var rec in LayoutRoot.Children) { if (rec is Rectangle) { var onerec = rec as Rectangle; //注册鼠标点击事件 onerec.MouseLeftButtonDown += new MouseButtonEventHandler(rec_MouseLeftButtonDown); //onerec.MouseMove += new MouseEventHandler(rec_MouseMove); //onerec.MouseLeave += new MouseEventHandler(rec_MouseLeave); } } //MessageBox.Show(A.ToString()); }
卡片的折叠效果
cc=cc+1004/card.Count; //如果有多张卡片会显示成折叠效果
相关文章推荐
- 用SliverLight做三国杀(四)重新定义卡牌类,增加牌堆类
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- 用SliverLight做三国杀(一)
- cocos2d-x 3.3 之卡牌设计 NO.6 Loading界面(异步加载图片,plist)
- POP动画之让分享界面动起来
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- 用SliverLight做三国杀(二)
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- [置顶] Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)
- Sliverlight-界面研究1
- 用SliverLight做三国杀(三)
- cocos2d-x 3.3 之卡牌设计 NO.5 设置界面(透明层和屏蔽下层触控)
- 加载界面(伪加载),进度条制作,让人物图片动起来
- Sliverlight-界面研究2
- 用SliverLight做三国杀(五)玩家类
- CC炫图:让通话界面动起来
- Android 界面滑动实现---Scroller类 从源码和开发文档中学习(让你的布局动起来)