Most efficient way to make a board
Mar 7, 2014 at 1:48pm UTC
I'm making a board for a dungeon crawler game I am making, and he way I have done it is extremely inefficient and time wasting, so I was wondering if there is any other way to make a board. I have the way I made my board down below.
1 2 3 4 5 6 7 8 9 10
cout << "----------" <<boardSpaces[172]<<boardSpaces[173]<<boardSpaces[174]<<"----------\n" ;
cout << "|" <<boardSpaces[151]<<boardSpaces[152]<<boardSpaces[153]<<boardSpaces[154]<<boardSpaces[155]<<boardSpaces[156]<<boardSpaces[157]<<boardSpaces[158]<<boardSpaces[159]<<boardSpaces[160]<<boardSpaces[162]<<boardSpaces[162]<<boardSpaces[163]<<boardSpaces[164]<<boardSpaces[165]<<boardSpaces[166]<<boardSpaces[167]<<boardSpaces[168]<<boardSpaces[169]<<boardSpaces[170]<<boardSpaces[171]<<"|\n" ;
cout << "|" <<boardSpaces[130]<<boardSpaces[131]<<boardSpaces[132]<<boardSpaces[133]<<boardSpaces[134]<<boardSpaces[135]<<boardSpaces[136]<<boardSpaces[137]<<boardSpaces[138]<<boardSpaces[139]<<boardSpaces[140]<<boardSpaces[141]<<boardSpaces[142]<<boardSpaces[143]<<boardSpaces[144]<<boardSpaces[145]<<boardSpaces[146]<<boardSpaces[147]<<boardSpaces[148]<<boardSpaces[149]<<boardSpaces[150]<<"|\n" ;
cout << "|" <<boardSpaces[109]<<boardSpaces[110]<<boardSpaces[111]<<boardSpaces[112]<<boardSpaces[113]<<boardSpaces[114]<<boardSpaces[115]<<boardSpaces[116]<<boardSpaces[117]<<boardSpaces[118]<<boardSpaces[119]<<boardSpaces[120]<<boardSpaces[121]<<boardSpaces[122]<<boardSpaces[123]<<boardSpaces[124]<<boardSpaces[125]<<boardSpaces[126]<<boardSpaces[127]<<boardSpaces[128]<<boardSpaces[129]<<"|\n" ;
cout << "|" <<boardSpaces[88]<<boardSpaces[89]<<boardSpaces[90]<<boardSpaces[91]<<boardSpaces[92]<<boardSpaces[93]<<boardSpaces[94]<<boardSpaces[95]<<boardSpaces[96]<<boardSpaces[97]<<boardSpaces[98]<<boardSpaces[99]<<boardSpaces[100]<<boardSpaces[101]<<boardSpaces[102]<<boardSpaces[103]<<boardSpaces[104]<<boardSpaces[105]<<boardSpaces[106]<<boardSpaces[107]<<boardSpaces[108]<<"|\n" ;
cout << "|" <<boardSpaces[67]<<boardSpaces[68]<<boardSpaces[69]<<boardSpaces[70]<<boardSpaces[71]<<boardSpaces[72]<<boardSpaces[73]<<boardSpaces[74]<<boardSpaces[75]<<boardSpaces[76]<<boardSpaces[77]<<boardSpaces[78]<<boardSpaces[79]<<boardSpaces[80]<<boardSpaces[81]<<boardSpaces[82]<<boardSpaces[83]<<boardSpaces[84]<<boardSpaces[85]<<boardSpaces[86]<<boardSpaces[87]<<"|\n" ;
cout << "|" <<boardSpaces[46]<<boardSpaces[47]<<boardSpaces[48]<<boardSpaces[49]<<boardSpaces[50]<<boardSpaces[51]<<boardSpaces[52]<<boardSpaces[53]<<boardSpaces[54]<<boardSpaces[55]<<boardSpaces[56]<<boardSpaces[57]<<boardSpaces[58]<<boardSpaces[59]<<boardSpaces[60]<<boardSpaces[61]<<boardSpaces[62]<<boardSpaces[63]<<boardSpaces[64]<<boardSpaces[65]<<boardSpaces[66]<<"|\n" ;
cout << "|" <<boardSpaces[25]<<boardSpaces[26]<<boardSpaces[27]<<boardSpaces[28]<<boardSpaces[29]<<boardSpaces[30]<<boardSpaces[31]<<boardSpaces[32]<<boardSpaces[33]<<boardSpaces[34]<<boardSpaces[35]<<boardSpaces[36]<<boardSpaces[37]<<boardSpaces[38]<<boardSpaces[39]<<boardSpaces[40]<<boardSpaces[41]<<boardSpaces[42]<<boardSpaces[43]<<boardSpaces[44]<<boardSpaces[45]<<"|\n" ;
cout << "|" <<boardSpaces[4]<<boardSpaces[5]<<boardSpaces[6]<<boardSpaces[7]<<boardSpaces[8]<<boardSpaces[9]<<boardSpaces[10]<<boardSpaces[11]<<boardSpaces[12]<<boardSpaces[13]<<boardSpaces[14]<<boardSpaces[15]<<boardSpaces[16]<<boardSpaces[17]<<boardSpaces[18]<<boardSpaces[19]<<boardSpaces[20]<<boardSpaces[21]<<boardSpaces[22]<<boardSpaces[23]<<boardSpaces[24]<<"|\n" ;
cout << "----------" <<boardSpaces[1]<<boardSpaces[2]<<boardSpaces[3]<<"----------\n" ;
Mar 7, 2014 at 1:52pm UTC
a 'for' loop perhaps???
Mar 7, 2014 at 1:55pm UTC
I thought about that but I couldn't figure out how to do it
Mar 7, 2014 at 2:14pm UTC
The way you have done it is not inefficient in any way other than that you had to write a lot to get it done, so that will take up lots of space in your code.
Try it this way:
1 2 3 4 5 6 7 8 9 10 11 12 13
cout << "----------" << boardSpace[172] << " " << boardSpace[173] <<
" " << boardSpace[174] << "----------\n" ;
for (int x = 172; x - 21 > 0; x -= 21) {
cout << '|' ;
for (int v = x - 21; v < x; ++v) {
cout << " " << boardSpace[v];
}
cout << " |\n" ;
}
cout << "----------" << boardSpace[1] << " " << boardSpace[2] <<
" " << boardSpace[3] << "----------\n" ;
Last edited on Mar 7, 2014 at 2:16pm UTC
Mar 7, 2014 at 2:16pm UTC
Thank you!
Topic archived. No new replies allowed.