Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:54:13+00:00 2026-06-04T12:54:13+00:00

I have this code that draws the boxes on a Qbert board, how would

  • 0

I have this code that draws the boxes on a Qbert board, how would i figure out how to detect what color blocks are stepped on?

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]);




                }
        }
    }
    } 

I am trying to have the code detect the number of blocks drawn so that I know when they are all a certain color.

I need to make it a certain color of a block to end the game.

Right now, i have it starting out as a Blue Block Color then changing to a Green Block, how would i make it detect that if all the green blocks are stepped on that the game ends?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:54:15+00:00Added an answer on June 4, 2026 at 12:54 pm

    Somewhere in your Update method, you will want something like this:

    bool finished = true;
    for (int x = 0; x < 7; x++)
    {
        for (int y = 0; y < 7; y++)
        {
            if (board != 0 && board != 2) // 2 is green
            {
                finished = true;
                break;
            }
        }
        if (finished)
            break;
    }
    if (finished)
    {
        // Move to next level
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that makes a string and then echos the loop out
I have this code that draws a Rectangle ( Im trying to remake the
I have a UIView subclass that draws a simple rectangle with this code: -
I have this code, that draws an image. private void timer1_Tick(object sender, EventArgs e)
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.