找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 3202|回复: 2

[C#] 围猫游戏

[复制链接]

17

主题

28

回帖

590

积分

用户组: 大·技术宅

UID
140
精华
5
威望
30 点
宅币
440 个
贡献
26 次
宅之契约
0 份
在线时间
54 小时
注册时间
2014-3-22
发表于 2014-12-20 20:28:28 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 mzflz 于 2014-12-21 19:07 编辑

这东西虽然使用 面向对象的语言写的,但却没有用到面向对象的思想,这也是本程序的缺点所在,

代码很简单,但不保证可读性。

本程序一定还有Bug,请大神多多指教

不多说了,在这儿只把主要代码粘出来,至于“窗体设计器”生成的代码,大家可以在我上传的附件里找到






  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;



  10. namespace WindowsFormsApplication1
  11. {
  12.     struct point
  13.     {
  14.         public int x, y;
  15.     };

  16.     public partial class Form1 : Form
  17.     {
  18.         
  19.         
  20.         int[,] map = new int[4, 4];
  21.         point r = new point {
  22.             x = 2,
  23.             y = 2
  24.         };
  25.         bool isClick = false;
  26.         point click = new point();
  27.         
  28.         public Form1()
  29.         {
  30.             InitializeComponent();
  31.         }

  32.         private void Form1_Load(object sender, EventArgs e)
  33.         {
  34.             
  35.             for (int i = 0; i < 4; i++)
  36.             {
  37.                 for (int j = 0; j < 4; j++)
  38.                 {
  39.                     map[i, j] = 0;
  40.                 }
  41.             }
  42.             map[r.x, r.y] = 2;

  43.         }

  44.         private void Form1_Paint(object sender, PaintEventArgs e)
  45.         {
  46.             Graphics g = e.Graphics;

  47.             for (int i = 0; i < 4; i++) //x
  48.             {
  49.                 for (int j = 0; j < 4; j++) //y
  50.                 {

  51.                     
  52.                         
  53.                         Pen p = Pens.Black;
  54.                         int x = j%2 == 0 ? i * 20 : i*20+10,
  55.                             y = j * 20;
  56.                         const int w = 20, h = 20;

  57.                         g.DrawEllipse(Pens.Black, x, y, 20, 20);
  58.                         if (map[i, j] == 0) g.FillEllipse(Brushes.Red, x, y, w, h); //No Wall or Stone
  59.                         if (map[i, j] == 1) g.FillEllipse(Brushes.Green, x, y, w, h); // Has Green
  60.                         if (map[i, j] == 2) g.FillEllipse(Brushes.Yellow,x,y, w, h);  //Rabbit      

  61.                     

  62.                 }
  63.             }

  64.         }

  65.         private void Form1_MouseClick(object sender, MouseEventArgs e)
  66.         {
  67.             this.isClick = true;
  68.             
  69.             if(e.Y < 80&&(e.X/20)%2 == 0)
  70.             {
  71.                 click.x = (e.X - 10) / 20 ;
  72.                 click.y = (e.Y / 20) ;
  73.             }
  74.             else if(e.Y<80)
  75.             {
  76.                 click.x = e.X / 20;
  77.                 click.y = e.Y / 20;
  78.             }
  79.             else
  80.             {
  81.                 click.x = click.y = -1;
  82.             }

  83.             if(click.x<4&&click.y<4&&click.x>=0&&click.y>=0)
  84.             {
  85.                 if (map[click.x, click.y] == 2) return;
  86.                 map[click.x, click.y] = 1;
  87.                 this.Refresh();

  88.                 move();
  89.                
  90.             }



  91.             
  92.         }
  93.         private void move()
  94.         {
  95.             int left = r.x;
  96.             int right = 4 - r.x;
  97.             int top = r.y;
  98.             int bottom = 4 - r.y;


  99.            /* List<int> list = new List<int>();

  100.             list.Add(left);
  101.             list.Add(right);
  102.             list.Add(top);
  103.             list.Add(bottom);

  104.             list.Sort();
  105.             */
  106.             if (left > right) //right
  107.             {
  108.                 if (top > bottom) // top
  109.                 {
  110.                     
  111.                     bool isX = true, //行上是否有障碍
  112.                         isY = true ; //列上是否有障碍
  113.                     //自上而下遍历
  114.                     for (int i = r.y;i<4;i++)
  115.                     {
  116.                         if (map[r.x, i] == 1)
  117.                         {
  118.                             isY = false;
  119.                             break;

  120.                         }
  121.                     }
  122.                     for (int i = r.x; i < 4; i++)
  123.                     {
  124.                         if (map[i, r.y] == 1)
  125.                         {
  126.                             isX = false;
  127.                             break;
  128.                         }
  129.                     }

  130.                     map[r.x, r.y] = 0;

  131.                     if (bottom > right)
  132.                     {
  133.                         if (isX)
  134.                         {
  135.                             r.x += 1;
  136.                             Check();
  137.                             map[r.x , r.y] = 2;

  138.                         }
  139.                         else
  140.                         {
  141.                             r.y += 1;
  142.                             Check();
  143.                             map[r.x, r.y ] = 2;
  144.                         }
  145.                     }
  146.                     if(bottom<right)
  147.                     {
  148.                         if (isY)
  149.                         {
  150.                             r.y += r.y; Check();
  151.                             map[r.x, r.y] = 2;
  152.                         }
  153.                         else
  154.                         {
  155.                             r.x += 1; Check();
  156.                             map[r.x , r.y] = 2;
  157.                         }
  158.                     }

  159.                   

  160.                 }
  161.                 else if (top < bottom)
  162.                 {
  163.                     bool isX = true, //行上是否有障碍
  164.                        isY = true; //列上是否有障碍

  165.                     for (int i = r.x; i < 4; i++)
  166.                     {
  167.                         if (map[i, r.y] == 1)
  168.                         {
  169.                             isX = false;
  170.                             break;
  171.                         }
  172.                     }

  173.                     for (int i = r.y; i >= 0; i--)
  174.                     {
  175.                         if (map[r.x, i] == 1)
  176.                         {
  177.                             isY = false;
  178.                             break;
  179.                         }
  180.                     }

  181.                     map[r.x, r.y] = 0;

  182.                     if (top < right)
  183.                     {

  184.                         if (isY)
  185.                         {
  186.                             r.y -= 1; Check();
  187.                             map[r.x, r.y ] = 2;
  188.                         }
  189.                         else
  190.                         {
  191.                             r.x += 1; Check();
  192.                             map[r.x , r.y] = 2;
  193.                         }

  194.                     }
  195.                     else if (top >= right)
  196.                     {
  197.                         if (isX)
  198.                         {
  199.                             r.x += 1; Check();
  200.                             map[r.x , r.y] = 2;
  201.                         }
  202.                         else
  203.                         {
  204.                             r.y -= r.y; Check();
  205.                             map[r.x, r.y ] = 2;
  206.                         }
  207.                     }

  208.                     
  209.                 }


  210.             }
  211.             else if (right >=left)
  212.             {
  213.                 if (top >= bottom)
  214.                 {
  215.                     bool isX = true, //行上是否有障碍
  216.                        isY = true; //列上是否有障碍

  217.                     for (int i = r.x; i >= 0;i-- )//x
  218.                     {
  219.                         if (map[i, r.y] == 1)
  220.                         {
  221.                             isX = false;
  222.                             break;
  223.                         }
  224.                     }
  225.                     for (int i = r.y; i < 4; i++)//y
  226.                     {
  227.                         if (map[r.x, i] == 1)
  228.                         {
  229.                             isY = false;
  230.                         }
  231.                     }
  232.                     map[r.x, r.y] = 0;
  233.                     if (left >= bottom)
  234.                     {
  235.                         if (isY)
  236.                         {
  237.                             r.y += 1; Check();
  238.                             map[r.x, r.y] = 2;
  239.                         }
  240.                         else
  241.                         {
  242.                             r.x -= 1; Check();
  243.                             map[r.x , r.y] = 2;
  244.                         }

  245.                     }
  246.                     else if (left <= bottom)
  247.                     {
  248.                         if (isX)
  249.                         {
  250.                             r.x -= 1; Check();
  251.                             map[r.x , r.y] = 2;
  252.                         }
  253.                         else
  254.                         {
  255.                             r.y += 1; Check();
  256.                             map[r.x, r.y ] = 2;
  257.                         }

  258.                     }

  259.                 }
  260.                 else if (top < bottom)
  261.                 {
  262.                     bool isX = true, //行上是否有障碍
  263.                        isY = true; //列上是否有障碍

  264.                     for (int i = r.x; i >= 0;i-- )//x
  265.                     {
  266.                         if (map[i, r.y] == 1)
  267.                         {
  268.                             isX = false;
  269.                             break;
  270.                         }
  271.                     }

  272.                     for (int i = r.y; i >= 0; i--)
  273.                     {
  274.                         if (map[r.x, i] == 1)
  275.                         {
  276.                             isX = false;
  277.                             break;
  278.                         }
  279.                     }
  280.                     map[r.x, r.y] = 0;
  281.                     if (top < left)
  282.                     {
  283.                         if (isY)
  284.                         {
  285.                             r.y -= 1; Check();
  286.                             map[r.x, r.y ] = 2;
  287.                         }
  288.                         else
  289.                         {
  290.                             r.x -= 1; Check();
  291.                             map[r.x , r.y] = 2; }

  292.                     }
  293.                     if (top > left)
  294.                     {
  295.                         if (isX)
  296.                         {
  297.                             r.x -= 1; Check();
  298.                             map[r.x , r.y] = 2;
  299.                         }
  300.                         else
  301.                         {
  302.                             r.y -= 1; Check();
  303.                             map[r.x, r.y ] = 2;
  304.                         }
  305.                     }
  306.                 }
  307.             }

  308.             //if (r.x < 0 || r.x >3 || r.y < 0 || r.y >3)
  309.             //{
  310.                 ;
  311.             //}

  312.             this.Refresh();
  313.             

  314.         }

  315.         private void timer1_Tick(object sender, EventArgs e)
  316.         {
  317.             if (this.Opacity == 1) timer1.Enabled = false;
  318.             this.Opacity += 0.1;
  319.             
  320.         }
  321.         private void Check()
  322.         {
  323.             if (r.x < 0 || r.x > 3 || r.y < 0 || r.y > 3)
  324.             {
  325.                 GameOver();
  326.             }
  327.         }
  328.         private void GameOver()
  329.         {
  330.             MessageBox.Show("Game Over");
  331.             Process p = Process.GetCurrentProcess();

  332.             p.Kill();

  333.             //p.Kill();
  334.         }
  335.     }
  336. }
复制代码


QQ截图20141220195640.png QQ截图20141220195712.png QQ截图20141220195722.png QQ截图20141220202518.png


刚才重新看了下代码,发现了几个bug,修复了下,现在重新把代码发上来





  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;




  10. namespace WindowsFormsApplication1
  11. {
  12.     struct point
  13.     {
  14.         public int x, y;
  15.     };
  16.     struct pos : IComparable
  17.     {
  18.         public string name;
  19.         public int distance;
  20.         public static bool operator <(pos a, pos b)
  21.         {
  22.             if (a.distance < b.distance)
  23.             {
  24.                 return true;
  25.             }
  26.             else
  27.             {
  28.                 return false;
  29.             }
  30.         }

  31.         public static bool operator >(pos a, pos b)
  32.         {
  33.             return a.distance > b.distance ? true : false;
  34.         }






  35.         public int CompareTo(object obj)
  36.         {
  37.             pos p = (pos)obj;

  38.             return this.distance.CompareTo(p.distance);
  39.         }
  40.     };
  41.     public partial class Form1 : Form
  42.     {

  43.         bool leftHave = false;
  44.         bool rightHave = false;
  45.         bool topHave = false;
  46.         bool bottomHave = false;
  47.         
  48.         int[,] map = new int[4, 4];
  49.         point r = new point {
  50.             x = 2,
  51.             y = 1
  52.         };
  53.         bool isClick = false;
  54.         point click = new point();

  55.         public Form1()
  56.         {
  57.             InitializeComponent();
  58.         }

  59.         private void Form1_Load(object sender, EventArgs e)
  60.         {
  61.             
  62.             for (int i = 0; i < 4; i++)
  63.             {
  64.                 for (int j = 0; j < 4; j++)
  65.                 {
  66.                     map[i, j] = 0;
  67.                 }
  68.             }
  69.             map[r.x, r.y] = 2;

  70.            

  71.         }

  72.         private void Form1_Paint(object sender, PaintEventArgs e)
  73.         {
  74.             Graphics g = e.Graphics;

  75.             for (int i = 0; i < 4; i++) //x
  76.             {
  77.                 for (int j = 0; j < 4; j++) //y
  78.                 {

  79.                     
  80.                         
  81.                         Pen p = Pens.Black;
  82.                         int x = j%2 == 0 ? i * 20 : i*20+10,
  83.                             y = j * 20;
  84.                         const int w = 20, h = 20;

  85.                         g.DrawEllipse(Pens.Black, x, y, 20, 20);
  86.                         if (map[i, j] == 0) g.FillEllipse(Brushes.Red, x, y, w, h); //No Wall or Stone
  87.                         if (map[i, j] == 1) g.FillEllipse(Brushes.Green, x, y, w, h); // Has Green
  88.                         if (map[i, j] == 2) g.FillEllipse(Brushes.Yellow,x,y, w, h);  //Rabbit      

  89.                     

  90.                 }
  91.             }

  92.         }

  93.         private void Form1_MouseClick(object sender, MouseEventArgs e)
  94.         {
  95.             this.isClick = true;
  96.             
  97.             if(e.Y < 80&&(e.X/20)%2 == 0)
  98.             {
  99.                 click.x = (e.X - 10) / 20 ;
  100.                 click.y = (e.Y / 20) ;
  101.             }
  102.             else if(e.Y<80)
  103.             {
  104.                 click.x = e.X / 20;
  105.                 click.y = e.Y / 20;
  106.             }
  107.             else
  108.             {
  109.                 click.x = click.y = -1;
  110.             }

  111.             if(click.x<4&&click.y<4&&click.x>=0&&click.y>=0)
  112.             {
  113.                 if (map[click.x, click.y] == 2) return;
  114.                 map[click.x, click.y] = 1;
  115.                 this.Refresh();

  116.                 _move();
  117.                
  118.             }



  119.             
  120.         }
  121.         private void move()
  122.         {
  123.             int left = r.x;
  124.             int right = 4 - r.x;
  125.             int top = r.y;
  126.             int bottom = 4 - r.y;


  127.            /* List<int> list = new List<int>();

  128.             list.Add(left);
  129.             list.Add(right);
  130.             list.Add(top);
  131.             list.Add(bottom);

  132.             list.Sort();
  133.             */
  134.             if (left > right) //right
  135.             {
  136.                 if (top > bottom) // top
  137.                 {
  138.                     
  139.                     bool isX = true, //行上是否有障碍
  140.                         isY = true ; //列上是否有障碍
  141.                     //自上而下遍历
  142.                     for (int i = r.y;i<4;i++)
  143.                     {
  144.                         if (map[r.x, i] == 1)
  145.                         {
  146.                             isY = false;
  147.                             break;

  148.                         }
  149.                     }
  150.                     for (int i = r.x; i < 4; i++)
  151.                     {
  152.                         if (map[i, r.y] == 1)
  153.                         {
  154.                             isX = false;
  155.                             break;
  156.                         }
  157.                     }

  158.                     map[r.x, r.y] = 0;

  159.                     if (bottom > right)
  160.                     {
  161.                         if (isX)
  162.                         {
  163.                             r.x += 1;
  164.                             Check();
  165.                             map[r.x , r.y] = 2;

  166.                         }
  167.                         else
  168.                         {
  169.                             r.y += 1;
  170.                             Check();
  171.                             map[r.x, r.y ] = 2;
  172.                         }
  173.                     }
  174.                     if(bottom<right)
  175.                     {
  176.                         if (isY)
  177.                         {
  178.                             r.y += r.y; Check();
  179.                             map[r.x, r.y] = 2;
  180.                         }
  181.                         else
  182.                         {
  183.                             r.x += 1; Check();
  184.                             map[r.x , r.y] = 2;
  185.                         }
  186.                     }

  187.                   

  188.                 }
  189.                 else if (top < bottom)
  190.                 {
  191.                     bool isX = true, //行上是否有障碍
  192.                        isY = true; //列上是否有障碍

  193.                     for (int i = r.x; i < 4; i++)
  194.                     {
  195.                         if (map[i, r.y] == 1)
  196.                         {
  197.                             isX = false;
  198.                             break;
  199.                         }
  200.                     }

  201.                     for (int i = r.y; i >= 0; i--)
  202.                     {
  203.                         if (map[r.x, i] == 1)
  204.                         {
  205.                             isY = false;
  206.                             break;
  207.                         }
  208.                     }

  209.                     map[r.x, r.y] = 0;

  210.                     if (top < right)
  211.                     {

  212.                         if (isY)
  213.                         {
  214.                             r.y -= 1; Check();
  215.                             map[r.x, r.y ] = 2;
  216.                         }
  217.                         else
  218.                         {
  219.                             r.x += 1; Check();
  220.                             map[r.x , r.y] = 2;
  221.                         }

  222.                     }
  223.                     else if (top >= right)
  224.                     {
  225.                         if (isX)
  226.                         {
  227.                             r.x += 1; Check();
  228.                             map[r.x , r.y] = 2;
  229.                         }
  230.                         else
  231.                         {
  232.                             r.y -= r.y; Check();
  233.                             map[r.x, r.y ] = 2;
  234.                         }
  235.                     }

  236.                     
  237.                 }


  238.             }
  239.             else if (right >=left)
  240.             {
  241.                 if (top >= bottom)
  242.                 {
  243.                     bool isX = true, //行上是否有障碍
  244.                        isY = true; //列上是否有障碍

  245.                     for (int i = r.x; i >= 0;i-- )//x
  246.                     {
  247.                         if (map[i, r.y] == 1)
  248.                         {
  249.                             isX = false;
  250.                             break;
  251.                         }
  252.                     }
  253.                     for (int i = r.y; i < 4; i++)//y
  254.                     {
  255.                         if (map[r.x, i] == 1)
  256.                         {
  257.                             isY = false;
  258.                         }
  259.                     }
  260.                     map[r.x, r.y] = 0;
  261.                     if (left >= bottom)
  262.                     {
  263.                         if (isY)
  264.                         {
  265.                             r.y += 1; Check();
  266.                             map[r.x, r.y] = 2;
  267.                         }
  268.                         else
  269.                         {
  270.                             r.x -= 1; Check();
  271.                             map[r.x , r.y] = 2;
  272.                         }

  273.                     }
  274.                     else if (left <= bottom)
  275.                     {
  276.                         if (isX)
  277.                         {
  278.                             r.x -= 1; Check();
  279.                             map[r.x , r.y] = 2;
  280.                         }
  281.                         else
  282.                         {
  283.                             r.y += 1; Check();
  284.                             map[r.x, r.y ] = 2;
  285.                         }

  286.                     }

  287.                 }
  288.                 else if (top < bottom)
  289.                 {
  290.                     bool isX = true, //行上是否有障碍
  291.                        isY = true; //列上是否有障碍

  292.                     for (int i = r.x; i >= 0;i-- )//x
  293.                     {
  294.                         if (map[i, r.y] == 1)
  295.                         {
  296.                             isX = false;
  297.                             break;
  298.                         }
  299.                     }

  300.                     for (int i = r.y; i >= 0; i--)
  301.                     {
  302.                         if (map[r.x, i] == 1)
  303.                         {
  304.                             isX = false;
  305.                             break;
  306.                         }
  307.                     }
  308.                     map[r.x, r.y] = 0;
  309.                     if (top < left)
  310.                     {
  311.                         if (isY)
  312.                         {
  313.                             r.y -= 1; Check();
  314.                             map[r.x, r.y ] = 2;
  315.                         }
  316.                         else
  317.                         {
  318.                             r.x -= 1; Check();
  319.                             map[r.x , r.y] = 2; }

  320.                     }
  321.                     if (top > left)
  322.                     {
  323.                         if (isX)
  324.                         {
  325.                             r.x -= 1; Check();
  326.                             map[r.x , r.y] = 2;
  327.                         }
  328.                         else
  329.                         {
  330.                             r.y -= 1; Check();
  331.                             map[r.x, r.y ] = 2;
  332.                         }
  333.                     }
  334.                 }
  335.             }

  336.             //if (r.x < 0 || r.x >3 || r.y < 0 || r.y >3)
  337.             //{
  338.                 ;
  339.             //}

  340.             this.Refresh();
  341.             

  342.         }

  343.         private void _move()
  344.         {

  345.             int bottom = 3 - r.y;
  346.             int top = r.y;
  347.             int left = r.x;
  348.             int right = 3 - r.x;

  349.             pos[] pp = new pos[4];

  350.             pp[0].name = "top";
  351.             pp[0].distance = top;

  352.             pp[1].name = "bottom";
  353.             pp[1].distance = bottom;

  354.             pp[2].name = "left";
  355.             pp[2].distance = left;

  356.             pp[3].name = "right";
  357.             pp[3].distance = right;

  358.             Array.Sort(pp);


  359.             for (int i = r.y; i >= 0; i--)//top
  360.             {
  361.                 if (map[r.x, i] == 1)
  362.                 {
  363.                     topHave = true;
  364.                     break;
  365.                 }
  366.             }

  367.             for (int i = r.y ; i < 4; i++) // bottom
  368.             {
  369.                 if (map[r.x, i] == 1)
  370.                 {
  371.                     bottomHave = true;
  372.                     break;
  373.                 }
  374.             }

  375.             for (int i = r.x; i >= 0; i--) //left
  376.             {
  377.                 if (map[i,r.y] == 1)
  378.                 {
  379.                     leftHave = true;
  380.                     break;
  381.                 }
  382.             }
  383.             for (int i = r.x; i < 4; i++) //right
  384.             {
  385.                 if (map[i, r.y] == 1)
  386.                 {
  387.                     rightHave = true;
  388.                     break;
  389.                 }
  390.             }


  391.             if (!__move(0,pp))
  392.             {
  393.                 GameOver();
  394.             }

  395.             if (leftHave && rightHave && topHave && bottomHave)
  396.             {
  397.                 MessageBox.Show("You Win");
  398.                 Process p = Process.GetCurrentProcess();
  399.                 p.Kill();

  400.             }



  401.         }

  402.         private bool check()
  403.     {

  404.             if (r.y < 0 || r.y > 3 || r.x < 0 || r.x>3)
  405.             {
  406.                 return false;
  407.             }
  408.             else
  409.                 return true;

  410.     }
  411.         bool __move(int i ,pos[] pp)
  412.         {
  413.             if (i >= 3) return false;



  414.             

  415.             switch (pp[i].name)
  416.             {

  417.                 case "top":
  418.                     {
  419.                         if (topHave) return __move(i + 1, pp);
  420.                         else
  421.                         {
  422.                             return move_top();
  423.                            
  424.                         }
  425.                         break;
  426.                     }
  427.                 case "bottom":
  428.                     {
  429.                         if (bottomHave) return  __move(i + 1, pp);
  430.                         else
  431.                         {
  432.                             return move_bottom();
  433.                         }
  434.                         break;
  435.                     }
  436.                 case "left":
  437.                     {
  438.                         if (leftHave) return __move(i + 1, pp);
  439.                         else
  440.                         {
  441.                             return move_left();
  442.                         }
  443.                         break;
  444.                     }
  445.                 case "right":
  446.                     {
  447.                         if (rightHave) return __move(i + 1, pp);
  448.                         else
  449.                         {
  450.                             return move_right();
  451.                         }
  452.                         break;
  453.                     }
  454.             }

  455.             return true;

  456.         }

  457.         bool move_left()
  458.         {
  459.             map[r.x, r.y] = 0;
  460.             r.x -= 1;

  461.             {
  462.                 if (!check()) return false;
  463.                 map[r.x, r.y] = 2;
  464.                // if (!check()) return false;
  465.                 this.Refresh();
  466.                 return true;
  467.             }
  468.         }

  469.         bool  move_right()
  470.         {
  471.             map[r.x, r.y] = 0;
  472.             r.x += 1;
  473.             if (!check()) return false;
  474.             map[r.x , r.y] = 2;
  475.             this.Refresh();
  476.             return true;
  477.         
  478.            
  479.         }

  480.         bool  move_top()
  481.         {
  482.             
  483.             map[r.x, r.y] = 0;
  484.             r.y -= 1;
  485.             if (!check()) return false;
  486.             map[r.x, r.y] = 2;
  487.             this.Refresh();
  488.             return true;
  489.         }
  490.         bool move_bottom()
  491.         {
  492.            // if (!check()) return false;
  493.             map[r.x, r.y] = 0;
  494.             r.y += 1;
  495.             if (!check()) return false;
  496.             map[r.x, r.y ] = 2;
  497.             this.Refresh();
  498.             return true;
  499.         }

  500.         private void timer1_Tick(object sender, EventArgs e)
  501.         {
  502.             if (this.Opacity == 1) timer1.Enabled = false;
  503.             this.Opacity += 0.1;
  504.             
  505.         }
  506.         private void Check()
  507.         {
  508.             if (r.x < 0 || r.x > 3 || r.y < 0 || r.y > 3)
  509.             {
  510.                 GameOver();
  511.             }
  512.         }
  513.         private void GameOver()
  514.         {
  515.             MessageBox.Show("Game Over");
  516.             Process p = Process.GetCurrentProcess();

  517.             p.Kill();

  518.             //p.Kill();
  519.         }
  520.     }
  521. }
复制代码


============================================================================================================================

CatchCat.rar

51.66 KB, 下载次数: 5

回复

使用道具 举报

1111

主题

1651

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
244
威望
743 点
宅币
24239 个
贡献
46222 次
宅之契约
0 份
在线时间
2297 小时
注册时间
2014-1-26
发表于 2014-12-20 22:27:05 | 显示全部楼层
哈哈 创意不错 不过这种是啥语言都能写的。至于面向对象……为什么非得面向对象?你有对象?
回复 赞! 靠!

使用道具 举报

29

主题

315

回帖

1561

积分

用户组: 上·技术宅

UID
3808
精华
11
威望
105 点
宅币
702 个
贡献
165 次
宅之契约
0 份
在线时间
404 小时
注册时间
2018-5-6
发表于 2020-4-8 16:17:41 | 显示全部楼层
0xAA55 发表于 2014-12-20 22:27
哈哈 创意不错 不过这种是啥语言都能写的。至于面向对象……为什么非得面向对象?你有对象? ...

真相了,难受。
Passion Coding!
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-24 05:29 , Processed in 0.047482 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表