Difference between revisions of "Team Blam-GridCode"
Ajcondinho (talk | contribs) |
Ajcondinho (talk | contribs) |
||
(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 | + | int hop = 1; |
− | + | for (int i = 0; i < 20; i++) | |
− | |||
− | for (i = | ||
{ | { | ||
− | Console. | + | for (int x = 0; x < 20; x++) |
− | Console. | + | { |
+ | Console.Write(gArray[i, x]); | ||
+ | } | ||
+ | Console.SetCursorPosition(0, hop++); | ||
} | } | ||
+ | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
</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++); } } } }