zoukankan      html  css  js  c++  java
  • windows phone7 项目一俄罗斯方块源码 及说明

       俄罗斯方块是一种曾经风靡全球的项目,可谓老少皆宜。一年前的今天,闲来无事,故作此项目。  

      依照面向对象的我们首先要看做这个项目需要哪些的类。

      1. 首先,所有形状的砖块继承一个基砖块的类。他有哪些 方法和属性。  有这几个属性,一个是Color ,记录砖块的颜色。一个是maxIndex,他这个画布下的砖块的最大的索引。

     一个是NextIndex 就是下一个砖块行数的索引。

        有那几个方法啊。 方块是不是要进行变形啊  因此  需要GetRotate()

    方法,  获取下一个砖块的型号的方法,需要 下一个GetIndex()方法.

         2.然后,  使T字形,天字形,z字形继承与基砖块的方法。  

         3. 然后, 我们需要UIControl类将这些类的 有机组合起来, 

           我们再看看相应的类图

         

    那是怎么用什么的东西代表那个位置有砖块,我们用0代表无砖块,用1代表代表有砖块。 比如 **                           0,0,0,0

                                                                                                                          ** 用所规定的源代码是0,1,1,0

                                                                                                                                                        0,1,1,0

                                                                                                                                                        0,0,0,0

      那怎么来删除 相应的砖块。我们用了一个RemoveRow 的方法、 这个 来判断这行是否的全部是1,是1的全部消去。

    private void RemoveRow()
    {
    int removeRowCount = 0;
    for (int y = 0; y < _rows; y++)
    {
    bool isLine = true;

    for (int x = 0; x < _coloumns; x++)
    {
    if (Container[y, x].Color == null)
    {
    isLine = false;
    break;
    }
    }

    if (isLine)
    {
    removeRowCount++;
    for (int x = 0; x < _coloumns; x++)
    {
    Container[y, x].Color = null;
    }

    for (int i = y; i > 0; i--)
    {
    for (int x = 0; x < _coloumns; x++)
    {
    Container[i, x].Color = Container[i - 1, x].Color;
    }
    }
    }
    }

    if (removeRowCount > 0)
    {
    Score += 10*(int) Math.Pow(2, removeRowCount);
    }


    RemoveRowCount += removeRowCount;

    Level = (int) Math.Sqrt(RemoveRowCount/5);

    _timer.Interval =
    TimeSpan.FromMilliseconds(_InitSpeed - _LevelSpeed*Level > _LevelSpeed
    ? _InitSpeed - _LevelSpeed*Level
    : _LevelSpeed);
    }

    那怎么移动砖块。我们分别有左移(MoveToLeft),右移(MoveToRight), 下移(MoveToDown) 方法, 我们  无非是利用移动相应的坐标。在进行填充。

    public void MoveToLeft()
    {
    if (GameStatus != GameStatus.Play)
    {
    return;
    }
    if (!IsBoundary(CurrentPieces.Matrix, -1, 0))
    {
    RemovePiece();
    AddPiece(-1, 0);
    }
    }

    public void MoveToRight()
    {
    if (GameStatus != GameStatus.Play)
    {
    return;
    }

    if (!IsBoundary(CurrentPieces.Matrix, 1, 0))
    {
    RemovePiece();
    AddPiece(1, 0);
    }
    }

    public void MoveToDown()
    {
    if (GameStatus != GameStatus.Play)
    {
    return;
    }
    if (!IsBoundary(CurrentPieces.Matrix, 0, 1))
    {
    RemovePiece();
    AddPiece(0, 1);
    }
    else
    {
    RemoveRow();
    CreatePiece();
    Score++;
    }
    }

    怎么变形啊,这次又一个GetRotate方法,每个形状有不同的枚举

         这样子俄罗斯方块就写完了

         开源地址 http://www.51aspx.com/code/Tetris7

  • 相关阅读:
    json对象和字符串的相互转换
    使用link rel="shortcut icon"为网页标题加图标
    jQuery——Js与jQuery的相互转换
    用accessKey设置快捷键
    CSS :invalid 选择器
    创建并调用 DLL(1)
    调用外部 DLL 中的函数(2. 晚绑定)
    调用外部 DLL 中的函数(1. 早绑定)
    VCL 中的 Windows API 函数(6): BeginDeferWindowPos
    VCL 中的 Windows API 函数(5): AlphaBlend
  • 原文地址:https://www.cnblogs.com/manuosex/p/2687476.html
Copyright © 2011-2022 走看看