Проблема с определением количества блоков, нарисованных на доске *XNA*

У меня есть код, который рисует прямоугольники на доске Qbert, как мне выяснить, как определить, на какие цветные блоки наступили?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace QBert
{
    public class Map
    {
        public int[,] board;
        public Color[] blockColors = new Color[] { Color.Blue, Color.Green }; //this makes it so it takes one time to step  to get to green
        Texture2D block;



        public Map(Texture2D block)   //draws the map of the blocks
        {
            this.block = block;

            board = new int[8, 7] 
            {
                { 0, 0, 0, 1, 0, 0, 0 },
                { 0, 0, 1, 1, 0, 0, 0 },
                { 0, 0, 1, 1, 1, 0, 0 },
                { 0, 1, 1, 1, 1, 0, 0 },
                { 0, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 0 },
                { 1, 1, 1, 1, 1, 1, 1 },
                { -1, -1, -1, -1, -1, -1, -1 },

            }
            ;
        }

        public Vector2 GetSquareCoords(int x, int y) //cordinates of the block
        {
            int ofs = block.Width / 2;
            ofs *= y % 2;

            return new Vector2(x * block.Width + ofs, y * 96); // 96  
        }

        public Vector2 GetSquareCenter(int x, int y)  //method for to jump on the middle of a block
        {
            Vector2 coords = GetSquareCoords(x, y);

            return new Vector2(coords.X + block.Width / 2, coords.Y + 32); //32
        }


        public Vector2 GetNextSquare(bool down, bool left, Vector2 position)  //this is how you jump to a next square
        {
            // If on even row, right is directly below and left is below and to the left
            // If on odd row, left is directly below and right is below and to the right
            int next_x = 0, next_y = 0;
            int x = (int)position.X;
            int y = (int)position.Y;

            if (down)
            {
                next_y = y + 1;
                if (left)
                {
                    next_x = x - 1;  // -1
                }
                else
                {
                    next_x = x;
                }

            }
            else
            {
                next_y = y - 1;

            }

            if (y % 2 == 0)
            {

                if (left)
                    next_x = x - 1;
                else
                    next_x = x;


            }
            else
            {
                if (left)
                    next_x = x;
                else
                    next_x = x + 1;  //+1 

            }


            if (next_x < 0)
            {
                next_x += 1;

            }
            if (next_x > 6)
            {
                next_x -= 1;

            }
            if (next_y < 0)
            {
                next_y += 1;

            }
            if (next_y > 7)
            {
                next_y -= 1;

            }


            if (board[next_y, next_x] == 0)
            {
                return new Vector2(x, y);
            }
            else
            {
                return new Vector2(next_x, next_y);
            }


        }


        public void Draw(SpriteBatch spriteBatch) //draws the blocks and colors of the block
        {
            int drawXOffset = 30;
            int drawYOffset = 60;


            for (int x = 0; x < 7; x++)
                for (int y = 0; y < 7; y++)
                {
                    Vector2 coord = GetSquareCoords(x, y);
                    if (board[y, x] > 0)
                        spriteBatch.Draw(block, new Rectangle(drawXOffset + (int)coord.X, drawYOffset + (int)coord.Y, block.Width, block.Height), blockColors[board[y, x] - 1]);




                }
        }
    }
    } 

Я пытаюсь, чтобы код определял количество нарисованных блоков, чтобы я знал, когда они все определенного цвета.

Мне нужно сделать блок определенного цвета, чтобы закончить игру.

Прямо сейчас у меня он начинается с синего цвета блока, а затем меняется на зеленый блок, как я могу определить, что если наступить на все зеленые блоки, игра закончится?

0
задан Javier 23 May 2012 в 01:20
поделиться