Difference between revisions of "Team Blam-GridCode"

From CDOT Wiki
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
*If you have any changes / upgrades to this code, post here for the benefit of others*
 
*If you have any changes / upgrades to this code, post here for the benefit of others*
 +
**Edit: Updated it to use an array for grid storage
  
 
<pre>
 
<pre>
 +
/*
 +
* Basic char array grid creator
 +
* Created by: Andrew Condinho
 +
* 9/30/2010
 +
*/
 +
 
using System;
 
using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
Line 15: Line 22:
 
         static void Main(string[] args)
 
         static void Main(string[] args)
 
         {
 
         {
             drawGrid();
+
            //create array to hold grid coordinates
 +
            char[,] gridArray = new char[20, 20];
 +
 
 +
            //populate grid -- !!!replace this with a grid generator!!!
 +
            for (int i = 0; i < 20; i++)
 +
            {
 +
                gridArray[0, i] = 'x';
 +
                gridArray[19, i] = 'x';
 +
            }
 +
 
 +
            for (int i = 1; i < 19; i++)
 +
            {
 +
                gridArray[i, 0] = 'x';
 +
                gridArray[i, 19] = 'x';
 +
            }
 +
 
 +
             drawGrid(gridArray);
  
 
             //Grid is useable starting at 1,1
 
             //Grid is useable starting at 1,1
Line 29: Line 52:
 
         }
 
         }
  
         static void drawGrid()
+
         static void drawGrid(char [,] gArray)
 
         {
 
         {
             int i = 0;
+
             int hop = 1;
            int x = 0;
+
             for (int i = 0; i < 20; i++)
 
 
             for (i = 1; i < 19; i++)
 
 
             {
 
             {
                 Console.SetCursorPosition(0, i);
+
                 for (int x = 0; x < 20; x++)
                 Console.Write("x");
+
                {
 +
                    Console.Write(gArray[i, x]);
 +
                }
 +
                 Console.SetCursorPosition(0, hop++);
 
             }
 
             }
 +
        }
  
            for (x = 0; x < 20; x++)
 
            {
 
                Console.SetCursorPosition(x, i);
 
                Console.Write("x");
 
            }
 
 
            for (i = 0; i < 20; i++)
 
            {
 
                Console.SetCursorPosition(i, 0);
 
                Console.Write("x");
 
            }
 
 
            for (x = 0; x < 20; x++)
 
            {
 
                Console.SetCursorPosition(i, x);
 
                Console.Write("x");
 
            }
 
        }
 
 
     }
 
     }
 
}
 
}
 
</pre>
 
</pre>

Latest revision as of 12:20, 30 September 2010

Paste this into a Visual C# project and it will draw a bounding box for a grid of X's

  • If you have any changes / upgrades to this code, post here for the benefit of others*
    • Edit: Updated it to use an array for grid storage
/*
 * Basic char array grid creator
 * Created by: Andrew Condinho
 * 9/30/2010
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Console_Move
{
    class Program
    {
        static void Main(string[] args)
        {
            //create array to hold grid coordinates
            char[,] gridArray = new char[20, 20];

            //populate grid -- !!!replace this with a grid generator!!!
            for (int i = 0; i < 20; i++)
            {
                gridArray[0, i] = 'x';
                gridArray[19, i] = 'x';
            }

            for (int i = 1; i < 19; i++)
            {
                gridArray[i, 0] = 'x';
                gridArray[i, 19] = 'x';
            }

            drawGrid(gridArray);

            //Grid is useable starting at 1,1
            //corner co-ords are
            //TL: 1,1
            //TR: 19,1
            //BL: 1,18
            //BR: 19,18

            Console.SetCursorPosition(0, 21);
            Console.WriteLine("All done");

        }

        static void drawGrid(char [,] gArray)
        {
            int hop = 1;
            for (int i = 0; i < 20; i++)
            {
                for (int x = 0; x < 20; x++)
                {
                    Console.Write(gArray[i, x]);
                }
                Console.SetCursorPosition(0, hop++);
            }
        }

    }
}