How do I express a range of array positions in c++? -
how express:
array[0-9][0-9] print player array[0-9][10-79] print blankspace array[10-19[0-29] print blankspace array[10-19][30-39] print tree1
etc.
if it's not obvious i'm trying print game map can control player moving on "tiles" (each 1 equal 10x10 of array positions or char spaces if prefer) can't seem find way "select" range of positions in arrays instead of 2 positions.
if said [0][9] player example print player character on 1 position seeing i'm printing in type char. equal '!' example. i'm meant print square of '!'s example take 10x10 chars.
then using logic, if "select" range of array positions print out pre-defined array of characters making overall character's using player() function. same blankspaces , tree1 etc.
any help/criticism/sarcastic banter on fail logic appreciated.
well, there's no built-in way work ranges quite way you've described it, there loops, come pretty close :-)
for (int j = 0; j != 10; ++j) { (int = 0; != 10; ++i) { printplayerat(j, i); } }
it looks you're going end "repainting" whole rectangular region, though, , making cursor jump around in (what i'm assuming console/command line) window non-trivial. suggest changing logic away object-oriented "print this *here*" locality-oriented "when we're here, print this. pseudo-code clarify:
for (int j = 0; j != 20; ++j) { (int = 0; != 80; ++i) { if ((0 <= j && j < 10) && (0 <= && < 10)) { printplayer(); } else if ((10 <= j && j < 20) && (30 <= && < 40)) { printtree(); } // ... else { printblankspace(); } } }
Comments
Post a Comment