自己编写的silverlight小游戏

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Expression.Shapes; using System.Collections.Generic; using Microsoft.Expression.Controls; using System.Windows.Media.Imaging;

namespace SilverlightApplication1 {  public partial class MainPage : UserControl  {         List<Grid> positions = new List<Grid>();         List<Grid> savepositions = new List<Grid>();   public MainPage()   {    // 为初始化变量所必需    InitializeComponent();             InitGrid();             ScaleTransform st = new ScaleTransform();             st.ScaleX = 2;             st.ScaleY = 2;             LayoutRoot.RenderTransform = st;   }         private void InitGrid()         {             Path gridPath = new Path();             PathGeometry pg = new PathGeometry();             PathFigure pf = new PathFigure();             pf.StartPoint = new Point(0, 0);             LineSegment line1 = new LineSegment();             line1.Point = new Point(300,0);             pf.Segments.Add(line1);             LineSegment line2 = new LineSegment();             line2.Point = new Point(300, 300);             pf.Segments.Add(line2);             LineSegment line3 = new LineSegment();             line3.Point = new Point(0, 300);             pf.Segments.Add(line3);             pf.IsClosed = true;             pg.Figures.Add(pf);             PathFigure pf2 = new PathFigure();             pf2.StartPoint = new Point(100, 0);             LineSegment ls2 = new LineSegment();             ls2.Point = new Point(100, 300);             pf2.Segments.Add(ls2);             pg.Figures.Add(pf2);             PathFigure pf3 = new PathFigure();             pf3.StartPoint = new Point(200, 0);             LineSegment ls3 = new LineSegment();             ls3.Point = new Point(200, 300);             pf3.Segments.Add(ls3);             pg.Figures.Add(pf3);             PathFigure pf4 = new PathFigure();             pf4.StartPoint = new Point(0, 100);             LineSegment ls4 = new LineSegment();             ls4.Point = new Point(300, 100);             pf4.Segments.Add(ls4);             pg.Figures.Add(pf4);             PathFigure pf5 = new PathFigure();             pf5.StartPoint = new Point(0, 200);             LineSegment ls5 = new LineSegment();             ls5.Point = new Point(300, 200);             pf5.Segments.Add(ls5);             pg.Figures.Add(pf5);             gridPath.Data = pg;             gridPath.Stroke = new SolidColorBrush(Colors.Black);             gridPath.StrokeThickness = 1;             this.LayoutRoot.Children.Add(gridPath);             List<Grid> plist = new List<Grid>();             for (int i = 0; i <= 300;i = i + 100 )             {                 for (int j = 0; j <= 300;j=j+100 )                 {                     Grid grid = new Grid();                     grid.Width = 30;                     grid.Height = 30;                     grid.VerticalAlignment = VerticalAlignment.Top;                     grid.HorizontalAlignment = HorizontalAlignment.Left;                     grid.Margin = new Thickness(i-15, j-15, 0, 0);                     grid.Background = new SolidColorBrush(Colors.LightGray);                     MyCard card = new MyCard(new Point(i, j));                     card.IsSave = false;                     grid.Tag = card;                     plist.Add(grid);                 }             }             Random random = new Random();             int indext=1;             while (plist.Count > 0)             {                 Grid grid = plist[random.Next(plist.Count)];                 plist.Remove(grid);                 MyCard card = grid.Tag as MyCard;                 card.Index = indext++;                 grid.Tag = card;                 positions.Add(grid);                 this.LayoutRoot.Children.Add(grid);                 grid.Background = new SolidColorBrush(Colors.LightGray);                 grid.MouseLeftButtonDown += new MouseButtonEventHandler(grid_MouseLeftButtonDown);             }             for (int i = 50; i <= 250;i+=100 )             {                 for (int j = 50; j <= 250;j+=100 )                 {                     Grid grid = new Grid();                     grid.Width = 30;                     grid.Height = 30;                     grid.VerticalAlignment = VerticalAlignment.Top;                     grid.HorizontalAlignment = HorizontalAlignment.Left;                     grid.Margin = new Thickness(i - 15, j - 15, 0, 0);                     MyCard card = new MyCard(new Point(i, j));                     card.IsSave = true;                     grid.Tag = card;                     savepositions.Add(grid);

grid.MouseLeftButtonDown += new MouseButtonEventHandler(grid_MouseLeftButtonDown);                 }             }         }         Grid selectGrid=null;         void grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)         {             if (selectGrid==null)             {                 selectGrid = sender as Grid;                 MyCard card = selectGrid.Tag as MyCard;                 if (card==null)                 {                     selectGrid.Background = new SolidColorBrush(Colors.White);                     selectGrid = null;                     return;                 }                 if (!card.IsActive)                 {                     Image image = new Image();                     image.Source = new BitmapImage(new Uri("/SilverlightApplication1;component/Images/" + card.Index.ToString() + ".jpg", UriKind.Relative));                     //TextBlock textblock = new TextBlock();                     //textblock.Text = card.Index.ToString();                     selectGrid.Children.Add(image);                     card.ImageCard = image;                     selectGrid.Background = new SolidColorBrush(Colors.White);                     selectGrid = null;                     card.IsActive = true;                 }                 else                 {                     selectGrid.Background = new SolidColorBrush(Colors.Purple);                 }             }             else             {                 Grid directGrid = sender as Grid;                 MyCard card1 = selectGrid.Tag as MyCard;                 MyCard card2 = directGrid.Tag as MyCard;                 double distance = Math.Sqrt(Math.Pow(card1.Position.X - card2.Position.X, 2) + Math.Pow(card1.Position.Y - card2.Position.Y, 2));                 if (distance>100)                 {                     selectGrid.Background = new SolidColorBrush(Colors.White);                     selectGrid = null;                     return;                 }                 if (card1==card2)                 {                     selectGrid.Background = new SolidColorBrush(Colors.White);                     selectGrid = null;                     return;                 }                 if (card2!=null)                 {                     if (!card2.IsActive)                     {                         return;                     }                     if (card1 != null && card1.ImageCard != null)                     {                         if ((card1.Index > 8 && card2.Index > 8) || (card1.Index <= 8 && card2.Index <= 8))                         {                             MessageBox.Show("自己人");                             return;                         }                         if (card1.Index%8>card2.Index%8)                         {                             if (card1.Index % 8 != 1 && card2.Index % 8==0)                             {                                 if (selectGrid.Children.Contains(card1.ImageCard))                                     selectGrid.Children.Remove(card1.ImageCard);                                 selectGrid.Tag = null;                                 selectGrid.Background = null;                                 directGrid.Tag = card1;                                 directGrid.Children.Add(card1.ImageCard);                                 selectGrid = directGrid;                                 selectGrid.Background = new SolidColorBrush(Colors.Purple);                             }                         }                         else if (card1.Index % 8 < card2.Index % 8)                         {                             if (card1.Index % 8 == 0 && card2.Index % 8!=1)                             {                                 MessageBox.Show("不可以");                                 return;                             }                             else                             {                                 if (selectGrid.Children.Contains(card1.ImageCard))                                     selectGrid.Children.Remove(card1.ImageCard);                                 selectGrid.Tag = null;                                 selectGrid.Background = null;                                 directGrid.Tag = card1;                                 directGrid.Children.Add(card1.ImageCard);                                 selectGrid = directGrid;                                 selectGrid.Background = new SolidColorBrush(Colors.Purple); ;                             }                         }                     }                 }             }         }  }     public class MyCard     {         private bool m_isactive;         public bool IsActive         {             get { return m_isactive; }             set { m_isactive = value; }         }         private bool m_issave;         public bool IsSave         {             get { return m_issave; }             set { m_issave = value; }         }         private Point m_position;         public Point Position         {             get { return m_position; }             set { m_position = value; }         }         private int index;         public int Index         {             get { return index; }             set { index = value; }         }         //public TextBlock TextCard;         public MyCard(Point point)         {             m_isactive = false;             m_issave = false;             m_position = point;             ImageCard = new Image();         }         public Image ImageCard;         public void SetImage(int dex)         {             //ImageSource imageSource = new BitmapImage(new Uri("image1.jpg", UriKind.RelativeOrAbsolute));             //ImageSource imageSource=new ImageSource()             ImageCard.Source = new BitmapImage(new Uri("/SilverlightApplication1;component/Images/"+dex.ToString()+".jpg", UriKind.Relative));         }     } }

自己编写的silverlight小游戏

时间: 2024-10-09 04:38:52

自己编写的silverlight小游戏的相关文章

C语言编写的迷宫小游戏

C语言编写的迷宫小游戏 #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> #define N 20/*迷宫的大小,可改变*/ int  oldmap[N][N];/*递归用的数组,用全局变量节约时间*/ int  yes=0;/*yes是判断是否找到路的标志,1找到,0没找到*/ int  way[100

c语言:编写猜数字小游戏。

编写猜数字小游戏. 程序: #include<stdio.h> #include<time.h> void menu() { printf("***欢迎来挑战猜数字游戏***\n"); printf("*****请选择开始或退出*****\n"); printf("******1.start 0.exit******\n"); } void game() { int num = 0; srand((unsigned)tim

使用Vue编写点击数字小游戏

使用vue编写一个点击数字计时小游戏,列入你在文本框中输入3,点击开始会生成一个3行3列的表格,表格数据为1-9随机排列,这时候从1开始点击,按顺序点到9,当按正确顺序点击完毕,会提示所用的时间,如果顺序没有按对,会提示游戏结束. 1.首先下载vue源码,下载地址http://cn.vuejs.org 2.jquery是在面向dom操作,而vue是面向数据操作的,所以使用vue最好不要去操作dom,尽量发挥出vue的独到之处,(如果使用过angularjs可能更容易理解) 3.建立一个普通的ht

介绍一款Android小游戏--交互式人机对战五子棋

文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6589025 学习Android系统开发之余,编写了一个小游戏--交互式人机对战五子棋,自娱自乐.之所以称之为交互式人机对战五子棋,一是因为在进入人机对战模式这前,你可以任意设置好开局,同时,在对战过程中,你可以看到机器的思考过程,还可以标识出每一个落子点的优劣势:二是因为可以为机器增加游戏经验,使得机器越来越聪明.希望喜欢五子棋的同学能够喜欢,

Python编写微信打飞机小游戏(一)

最近开始学习Python语言,发现Python有一个神奇的Pygame模块,在编写小游戏时显得非常方便,于是参照教学视频编写了一个微信打飞机的小游戏,网上有很多相关的博客,但都不是很详细,大都是直接贴代码,于是决定沉下心来把编写程序的过程记录下来,与大家分享. 首先声明一点,这篇博客完全参照了小甲鱼的<零基础入门学习Python>教学视频,为了尊重原创,特将原作者的视频地址公布如下:<零基础入门学习Python> Python编译器和Pygame模块的安装网上的教程很多,这里不再赘

编写小游戏《贪头蛇》第三篇

源码下载地址:http://download.csdn.net/detail/oyangyufu/7492917 点击NEW GAME按钮,进入游戏主场景 代码: 游戏背景 layer = (CCLayer*)this->getChildren()->objectAtIndex(SnakeConstants::LAYER_BACKGROUND); layer->setTouchEnabled(false); //游戏背景 CCSize size = CCDirector::sharedD

蓝懿iOS编写小游戏实现新功能

今天是练习日,通过几天的系统学习,我对基础的一些知识有了简单的了解,今天用了一天的时间通过整理几天所学到的东西,成功编写了一个简单的小游戏.游戏中几乎用到了学到的所有控件功能,Label,text,UiImageView,UiButton,NsTimer等. 今天我自己编写的游戏是实现一个角色图片通过设置好的四个button 按钮点击控制它的移动,中间有三个障碍图片,碰到障碍会减少血量,并且回到起始点.检测碰撞的地方用到了NsTimer的知识,其中还有一个雷区,雷区里通过问李国斌老师学会了新知识

编写小游戏《贪头蛇》第一篇

小游戏<贪头蛇>设计场景有: 主菜单.游戏主场景.游戏继续.游戏设置.游戏暂停.关于 进入游戏第一场景,显示该款游戏由哪家工作室或个人开发的 代码: SnakeSceneManager类用来管理游戏所有场景的切换,包括创建新的场景,切换下一个场景,和关卡场景 OpenLayer类用来创建该场景 CCScene *SnakeSceneManager::createscene() { CCScene *Scene = CCScene::create(); //进入游戏第1个图层 OpenLayer

Python编写微信打飞机小游戏(十一)

在这篇博文中,我们准备为打飞机小游戏添加一个暂停的功能,即用户在游戏过程中随时可以通过单击屏幕右上方的一个暂停按钮来暂停和恢复游戏.这个功能看似比较简单,但其中涉及了鼠标操作.图片切换.代码结构的重置等等,接下来我们一一进行介绍. 1.加载暂停按钮图标 在image文件夹下一共有四张暂停按钮的图片,分别为深色和浅色两组,首先在main()函数中加载相关图片资源并初始化暂停/开始标志位: paused = False # 标志是否暂停游戏 pause_nor_image = pygame.imag