moving around in an array with arrow keys

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

moving around in an array with arrow keys

 
0
  #1
Mar 3rd, 2006
i am totally stumped on what to do here. basically whats goin on is i have a 3D dynamic array and i need to have a cursor inside of it and move around on the inside. i do i go about doing that? like i said im completely stumped.

here is my code:

  1. #include <iostream>
  2. #include <conio.h>
  3. #include "Definitions.h"
  4. using namespace std;
  5.  
  6.  
  7. class Darray{
  8. protected:
  9. int DEPTH,
  10. ROW,
  11. COL;
  12. int*** array;
  13.  
  14. public:
  15.  
  16. Darray();
  17. Darray(int depth, int row, int col);
  18. ~Darray();
  19. Darray(const Darray& darray); //copy constructor
  20. Darray& Darray::operator= (const Darray& darray); //assignment operator
  21.  
  22. void getDimensions(int DEPTH, int ROW, int COL);
  23. void destroy();
  24. void create();
  25. void init();
  26. void resetSize(int DEPTH, int ROW, int COL);
  27. };
  28.  
  29. Darray::Darray()
  30. {
  31. DEPTH=0;
  32. ROW=0;
  33. COL=0;
  34. array=NULL;
  35. }
  36.  
  37. void Darray::create()
  38. {
  39. array = new int** [DEPTH];
  40. for(int d=0; d<DEPTH; d++) {
  41. *(array+d) = new int* [ROW];
  42. for (int r=0; r<ROW; r++)
  43. *(*(array+d)+r) = new int [COL];
  44. }
  45. }
  46.  
  47. Darray::Darray(int depth, int row, int col)
  48. {
  49. DEPTH = depth;
  50. ROW = row;
  51. COL = col;
  52. create();
  53. init();
  54.  
  55. }
  56.  
  57. Darray::~Darray()
  58. {
  59. destroy();
  60. }
  61.  
  62. Darray::Darray(const Darray& darray)
  63. {
  64. DEPTH = darray.DEPTH;
  65. ROW = darray.ROW;
  66. COL = darray.COL;
  67. create();
  68.  
  69. for(int d=0; d<DEPTH; d++)
  70. for(int r=0; r<ROW; r++)
  71. for(int c=0; c<COL; c++)
  72. array[d][r][c] = darray.array[d][r][c];
  73. }
  74.  
  75. Darray& Darray::operator= (const Darray& darray)
  76. {
  77. resetSize(darray.DEPTH, darray.ROW, darray.COL);
  78.  
  79. for(int d=0; d<DEPTH; d++)
  80. for(int r=0; r<ROW; r++)
  81. for(int c=0; c<COL; c++)
  82. array[d][r][c] = darray.array[d][r][c];
  83.  
  84. return *this;
  85. }
  86.  
  87. void Darray::destroy()
  88. {
  89. for (int d=0; d<DEPTH; d++)
  90. {
  91. for(int r=0; r<ROW; r++)
  92. delete [] *(*(array+d)+r);
  93. delete [] *(array+d);
  94. }
  95. delete [] array;
  96. }
  97.  
  98.  
  99. void Darray::init()
  100. {
  101. for(int d=0; d<DEPTH; d++)
  102. for(int r=0; r<ROW; r++)
  103. for(int c=0; c<COL; c++)
  104. array[d][r][c] = 0;
  105. }
  106.  
  107. void Darray::getDimensions(int DEPTH, int ROW, int COL)
  108. {
  109.  
  110. cout << "The Depth is: " << DEPTH << " The Row is: " << ROW
  111. << " The Columns is: " << COL << endl;
  112. }
  113.  
  114. void Darray::resetSize(int depth, int row, int col)
  115. {
  116. destroy();
  117. DEPTH=depth;
  118. ROW=row;
  119. COL=col;
  120. create();
  121. init();
  122. }
  123.  
  124. /***********************************************************************************/
  125. class Grid : public Darray {
  126. private:
  127. int currentRow,
  128. currentDepth,
  129. currentCol;
  130.  
  131. public:
  132. Grid();
  133. void arrow_keys();
  134. void UsDsFunction(int DEPTH, int ROW, int COL);
  135. void print () const;
  136. };
  137.  
  138. Grid::Grid()
  139. {
  140. int depth,
  141. row,
  142. col;
  143.  
  144.  
  145. cout << "Enter the grid dimensions: " << endl;
  146. cin >> depth >> row >> col;
  147.  
  148. // set up dimensions
  149. DEPTH = depth;
  150. ROW = row;
  151. COL = col;
  152.  
  153. // set up position
  154. currentRow = ROW / 2 + 1;
  155. currentDepth = DEPTH / 2 + 1;
  156. currentCol = COL / 2 + 1;
  157.  
  158. create();
  159.  
  160. }
  161.  
  162. void Grid::print () const
  163. {
  164.  
  165. // makes grid
  166.  
  167. //makes top row or grid
  168. for(int d=0; d<DEPTH; d++)
  169. {
  170. if(d<DEPTH)
  171. {
  172. cout << U_L;
  173. cout << LINE;
  174.  
  175. for(int c=0; c<COL-1; c++)
  176. {
  177. cout << T_M;
  178. cout << LINE;
  179.  
  180. }// end for
  181.  
  182. cout << U_R;
  183. cout << "\n";
  184.  
  185. for( c=0; c<COL+1; c++)
  186. {
  187.  
  188. cout << VERT_LINE;
  189. cout << " ";
  190.  
  191. }// end vertical line first row
  192.  
  193. }cout << "\n";// end top of grid
  194.  
  195. // makes gird middle
  196. for(int r=0; r<ROW-1; r++)
  197. if(r<ROW)
  198. {
  199. cout << L_SM;
  200. cout << LINE;
  201.  
  202. for(int c=0; c<COL-1; c++)
  203. {
  204.  
  205. cout << M;
  206. cout << LINE;
  207. }// end for
  208.  
  209.  
  210. cout << R_SM;
  211. cout << "\n";
  212.  
  213. for( c=0; c<COL+1; c++)
  214. {
  215. cout << VERT_LINE;
  216. cout << " ";
  217. }cout << endl;
  218. }// end middle of grid
  219.  
  220. // makes last line
  221. if(d<DEPTH)
  222. {
  223.  
  224. cout << L_L;
  225. cout << LINE;
  226.  
  227. for(int c=0; c<COL-1; c++)
  228. {
  229. cout << L_MT;
  230. cout << LINE;
  231. }
  232.  
  233. cout << L_R;
  234. }
  235. cout << endl;
  236.  
  237. }//end last row
  238.  
  239.  
  240. }
  241. void Grid::UsDsFunction(int DEPTH, int ROW, int COL)
  242. {
  243. int num,
  244. num2;
  245. cout << "would you like to upsize, downsize or keep the dimensions the same? " <<
  246. "\n\n";
  247. cout << "Choose an option: " << endl;
  248. cout << "1.) Upsize" << endl;
  249. cout << "2.) Downsize" << endl;
  250. cout << "3.) Keep the same" << endl;
  251. cin >> num;
  252.  
  253. switch (num)
  254. {
  255. case 1:
  256.  
  257. resetSize(DEPTH, ROW, COL);
  258.  
  259.  
  260.  
  261. break;
  262.  
  263. case 2:
  264.  
  265. resetSize(DEPTH, ROW, COL);
  266.  
  267.  
  268. break;
  269.  
  270. case 3:
  271.  
  272. cout << "Grid staying the same" << endl;
  273. break;
  274. }
  275.  
  276.  
  277. }
  278.  
  279.  
  280. void Grid::arrow_keys()
  281. {
  282. char key;
  283. bool flag = false;
  284.  
  285. do {
  286. key = getch();
  287. switch (toascii(key)) {
  288. case 96:
  289. case 224:
  290. flag = true;
  291. break;
  292. case 72: // up arrow
  293. if (flag) {
  294. cout << ACTIVE;
  295. cout << endl;
  296. flag = false;
  297. }
  298. else
  299. cout << "try again. " << endl;
  300. break;
  301. case 77:
  302. if (flag) {
  303. cout << ACTIVE;
  304. cout << endl;
  305. flag = false;
  306. }
  307. else
  308. cout << "try again. " << endl;
  309. break;
  310. case 75:
  311. if (flag) {
  312. cout << ACTIVE;
  313. cout << endl;
  314. flag = false;
  315. }
  316. else
  317. cout << "try again. " << endl;
  318. break;
  319. case 80:
  320. if (flag) {
  321. cout << ACTIVE;
  322. cout << endl;
  323. flag = false;
  324. }
  325. else
  326. cout << "try again. " << endl;
  327. break;
  328. case 13:
  329. cout << "Enter" << endl;
  330. break;
  331. default:
  332. cout << "try again. " << endl;
  333. break;
  334. }
  335. } while (key != 13);
  336. }
  337.  
  338. /******************************************************************************/
  339. class Cell{
  340. private:
  341. bool visit,
  342. active;
  343.  
  344. public:
  345. Cell();
  346. ~Cell();
  347. void fill();
  348.  
  349. };
  350.  
  351. Cell::Cell()
  352. {
  353. visit = 0;
  354. active = 0;
  355. }
  356.  
  357. Cell::~Cell()
  358. {
  359.  
  360. }
  361. //fill cell when visited
  362. void fill()
  363. {
  364.  
  365. }
  366.  
  367.  
  368. /*******************************************************************************/
  369. void main()
  370. {
  371. //Darray d;
  372. Grid g;
  373. Cell c;
  374. //d.getDimensions(depth, row, col);
  375. g.print();
  376.  
  377.  
  378. g.arrow_keys();
  379. //g.UsDsFunction(depth, row, col);
  380. g.print();
  381.  
  382. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: moving around in an array with arrow keys

 
0
  #2
Mar 3rd, 2006
Originally Posted by tyczj
i am totally stumped on what to do here. basically whats goin on is i have a 3D dynamic array and i need to have a cursor inside of it and move around on the inside. i do i go about doing that? like i said im completely stumped.

here is my code:

  1. #include <iostream>
  2. #include <conio.h>
  3. #include "Definitions.h"
  4. using namespace std;
  5.  
  6.  
  7. class Darray{
  8. protected:
  9. int DEPTH,
  10. ROW,
  11. COL;
  12. int*** array;
  13.  
  14. public:
  15.  
  16. Darray();
  17. Darray(int depth, int row, int col);
  18. ~Darray();
  19. Darray(const Darray& darray); //copy constructor
  20. Darray& Darray::operator= (const Darray& darray); //assignment operator
  21.  
  22. void getDimensions(int DEPTH, int ROW, int COL);
  23. void destroy();
  24. void create();
  25. void init();
  26. void resetSize(int DEPTH, int ROW, int COL);
  27. };
  28.  
  29. Darray::Darray()
  30. {
  31. DEPTH=0;
  32. ROW=0;
  33. COL=0;
  34. array=NULL;
  35. }
  36.  
  37. void Darray::create()
  38. {
  39. array = new int** [DEPTH];
  40. for(int d=0; d<DEPTH; d++) {
  41. *(array+d) = new int* [ROW];
  42. for (int r=0; r<ROW; r++)
  43. *(*(array+d)+r) = new int [COL];
  44. }
  45. }
  46.  
  47. Darray::Darray(int depth, int row, int col)
  48. {
  49. DEPTH = depth;
  50. ROW = row;
  51. COL = col;
  52. create();
  53. init();
  54.  
  55. }
  56.  
  57. Darray::~Darray()
  58. {
  59. destroy();
  60. }
  61.  
  62. Darray::Darray(const Darray& darray)
  63. {
  64. DEPTH = darray.DEPTH;
  65. ROW = darray.ROW;
  66. COL = darray.COL;
  67. create();
  68.  
  69. for(int d=0; d<DEPTH; d++)
  70. for(int r=0; r<ROW; r++)
  71. for(int c=0; c<COL; c++)
  72. array[d][r][c] = darray.array[d][r][c];
  73. }
  74.  
  75. Darray& Darray::operator= (const Darray& darray)
  76. {
  77. resetSize(darray.DEPTH, darray.ROW, darray.COL);
  78.  
  79. for(int d=0; d<DEPTH; d++)
  80. for(int r=0; r<ROW; r++)
  81. for(int c=0; c<COL; c++)
  82. array[d][r][c] = darray.array[d][r][c];
  83.  
  84. return *this;
  85. }
  86.  
  87. void Darray::destroy()
  88. {
  89. for (int d=0; d<DEPTH; d++)
  90. {
  91. for(int r=0; r<ROW; r++)
  92. delete [] *(*(array+d)+r);
  93. delete [] *(array+d);
  94. }
  95. delete [] array;
  96. }
  97.  
  98.  
  99. void Darray::init()
  100. {
  101. for(int d=0; d<DEPTH; d++)
  102. for(int r=0; r<ROW; r++)
  103. for(int c=0; c<COL; c++)
  104. array[d][r][c] = 0;
  105. }
  106.  
  107. void Darray::getDimensions(int DEPTH, int ROW, int COL)
  108. {
  109.  
  110. cout << "The Depth is: " << DEPTH << " The Row is: " << ROW
  111. << " The Columns is: " << COL << endl;
  112. }
  113.  
  114. void Darray::resetSize(int depth, int row, int col)
  115. {
  116. destroy();
  117. DEPTH=depth;
  118. ROW=row;
  119. COL=col;
  120. create();
  121. init();
  122. }
  123.  
  124. /***********************************************************************************/
  125. class Grid : public Darray {
  126. private:
  127. int currentRow,
  128. currentDepth,
  129. currentCol;
  130.  
  131. public:
  132. Grid();
  133. void arrow_keys();
  134. void UsDsFunction(int DEPTH, int ROW, int COL);
  135. void print () const;
  136. };
  137.  
  138. Grid::Grid()
  139. {
  140. int depth,
  141. row,
  142. col;
  143.  
  144.  
  145. cout << "Enter the grid dimensions: " << endl;
  146. cin >> depth >> row >> col;
  147.  
  148. // set up dimensions
  149. DEPTH = depth;
  150. ROW = row;
  151. COL = col;
  152.  
  153. // set up position
  154. currentRow = ROW / 2 + 1;
  155. currentDepth = DEPTH / 2 + 1;
  156. currentCol = COL / 2 + 1;
  157.  
  158. create();
  159.  
  160. }
  161.  
  162. void Grid::print () const
  163. {
  164.  
  165. // makes grid
  166.  
  167. //makes top row or grid
  168. for(int d=0; d<DEPTH; d++)
  169. {
  170. if(d<DEPTH)
  171. {
  172. cout << U_L;
  173. cout << LINE;
  174.  
  175. for(int c=0; c<COL-1; c++)
  176. {
  177. cout << T_M;
  178. cout << LINE;
  179.  
  180. }// end for
  181.  
  182. cout << U_R;
  183. cout << "\n";
  184.  
  185. for( c=0; c<COL+1; c++)
  186. {
  187.  
  188. cout << VERT_LINE;
  189. cout << " ";
  190.  
  191. }// end vertical line first row
  192.  
  193. }cout << "\n";// end top of grid
  194.  
  195. // makes gird middle
  196. for(int r=0; r<ROW-1; r++)
  197. if(r<ROW)
  198. {
  199. cout << L_SM;
  200. cout << LINE;
  201.  
  202. for(int c=0; c<COL-1; c++)
  203. {
  204.  
  205. cout << M;
  206. cout << LINE;
  207. }// end for
  208.  
  209.  
  210. cout << R_SM;
  211. cout << "\n";
  212.  
  213. for( c=0; c<COL+1; c++)
  214. {
  215. cout << VERT_LINE;
  216. cout << " ";
  217. }cout << endl;
  218. }// end middle of grid
  219.  
  220. // makes last line
  221. if(d<DEPTH)
  222. {
  223.  
  224. cout << L_L;
  225. cout << LINE;
  226.  
  227. for(int c=0; c<COL-1; c++)
  228. {
  229. cout << L_MT;
  230. cout << LINE;
  231. }
  232.  
  233. cout << L_R;
  234. }
  235. cout << endl;
  236.  
  237. }//end last row
  238.  
  239.  
  240. }
  241. void Grid::UsDsFunction(int DEPTH, int ROW, int COL)
  242. {
  243. int num,
  244. num2;
  245. cout << "would you like to upsize, downsize or keep the dimensions the same? " <<
  246. "\n\n";
  247. cout << "Choose an option: " << endl;
  248. cout << "1.) Upsize" << endl;
  249. cout << "2.) Downsize" << endl;
  250. cout << "3.) Keep the same" << endl;
  251. cin >> num;
  252.  
  253. switch (num)
  254. {
  255. case 1:
  256.  
  257. resetSize(DEPTH, ROW, COL);
  258.  
  259.  
  260.  
  261. break;
  262.  
  263. case 2:
  264.  
  265. resetSize(DEPTH, ROW, COL);
  266.  
  267.  
  268. break;
  269.  
  270. case 3:
  271.  
  272. cout << "Grid staying the same" << endl;
  273. break;
  274. }
  275.  
  276.  
  277. }
  278.  
  279.  
  280. void Grid::arrow_keys()
  281. {
  282. char key;
  283. bool flag = false;
  284.  
  285. do {
  286. key = getch();
  287. switch (toascii(key)) {
  288. case 96:
  289. case 224:
  290. flag = true;
  291. break;
  292. case 72: // up arrow
  293. if (flag) {
  294. cout << ACTIVE;
  295. cout << endl;
  296. flag = false;
  297. }
  298. else
  299. cout << "try again. " << endl;
  300. break;
  301. case 77:
  302. if (flag) {
  303. cout << ACTIVE;
  304. cout << endl;
  305. flag = false;
  306. }
  307. else
  308. cout << "try again. " << endl;
  309. break;
  310. case 75:
  311. if (flag) {
  312. cout << ACTIVE;
  313. cout << endl;
  314. flag = false;
  315. }
  316. else
  317. cout << "try again. " << endl;
  318. break;
  319. case 80:
  320. if (flag) {
  321. cout << ACTIVE;
  322. cout << endl;
  323. flag = false;
  324. }
  325. else
  326. cout << "try again. " << endl;
  327. break;
  328. case 13:
  329. cout << "Enter" << endl;
  330. break;
  331. default:
  332. cout << "try again. " << endl;
  333. break;
  334. }
  335. } while (key != 13);
  336. }
  337.  
  338. /******************************************************************************/
  339. class Cell{
  340. private:
  341. bool visit,
  342. active;
  343.  
  344. public:
  345. Cell();
  346. ~Cell();
  347. void fill();
  348.  
  349. };
  350.  
  351. Cell::Cell()
  352. {
  353. visit = 0;
  354. active = 0;
  355. }
  356.  
  357. Cell::~Cell()
  358. {
  359.  
  360. }
  361. //fill cell when visited
  362. void fill()
  363. {
  364.  
  365. }
  366.  
  367.  
  368. /*******************************************************************************/
  369. void main()
  370. {
  371. //Darray d;
  372. Grid g;
  373. Cell c;
  374. //d.getDimensions(depth, row, col);
  375. g.print();
  376.  
  377.  
  378. g.arrow_keys();
  379. //g.UsDsFunction(depth, row, col);
  380. g.print();
  381.  
  382. }
What's definitions.h?

Supply the file if it has changed from your previous post. Some of your for loops... the variable should be initialised as int c. You've missed that.

Change void main to int main.

What exactly do you mean have a cursor in the 3d array?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: moving around in an array with arrow keys

 
0
  #3
Mar 3rd, 2006
thats right i forgot about the definitions file

  1. #define M char (197);
  2. #define U_L char (218);
  3. #define L_L char (192);
  4. #define U_R char (191);
  5. #define L_R char (217);
  6. #define T_M char (194);
  7. #define L_MT char (193);
  8. #define L_SM char (195);
  9. #define R_SM char (180);
  10. #define VERT_LINE char (179);
  11. #define VISIT char (219);
  12. #define LINE char (196);
  13. #define ACTIVE char (248);

and i mean its like ur playing a video game where u have a player(cursor) and you move the player(cursor) around in the array
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: moving around in an array with arrow keys

 
0
  #4
Mar 3rd, 2006
This code has it's problems but it's the best I could come up with on the fly.

It doesn't check beyond the bounds of the grid, so be careful of overflow.

The letter 'P' indicates the player.


  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. #include <stdio.h>
  5.  
  6. //#include "Definitions.h"
  7. using namespace std;
  8. void clear_da_screen(void);
  9.  
  10. /* System dependent key codes */
  11. enum
  12. {
  13. KEY_ESC = 27,
  14. ARROW_UP = 256 + 72,
  15. ARROW_DOWN = 256 + 80,
  16. ARROW_LEFT = 256 + 75,
  17. ARROW_RIGHT = 256 + 77
  18. };
  19.  
  20. static int get_code ( void )
  21. {
  22. int ch = getch();
  23.  
  24. if ( ch == 0 || ch == 224 )
  25. ch = 256 + getch();
  26.  
  27. return ch;
  28. }
  29.  
  30. int main()
  31. {
  32.  
  33.  
  34. char crap[5][5];
  35. for(int i=0; i<5; i++)
  36. {
  37. for(int j=0; j<5; j++)
  38. {
  39. crap[i][j]='-';
  40. }
  41. }
  42.  
  43.  
  44. int x,y;
  45. x=0;
  46. y=0;
  47.  
  48. int ch;
  49.  
  50. while ( ( ch = get_code() ) != KEY_ESC ) {
  51. clear_da_screen();
  52. switch ( ch )
  53. {
  54. case ARROW_UP:
  55. printf ( "UP\n" );
  56. y=y-1;
  57. break;
  58. case ARROW_DOWN:
  59. printf ( "DOWN\n" );
  60. y=y+1;
  61. break;
  62. case ARROW_LEFT:
  63. printf ( "LEFT\n" );
  64. x=x-1;
  65. break;
  66. case ARROW_RIGHT:
  67. printf ( "RIGHT\n" );
  68. x=x+1;
  69. break;
  70.  
  71.  
  72. }
  73.  
  74. crap[y][x]='P';
  75. for(int i=0; i<5; i++)
  76. {
  77. for(int j=0; j<5; j++)
  78. {
  79. cout<<crap[i][j]<<" ";
  80. }cout<<"\n";
  81. }
  82. crap[y][x]='-';
  83. //break;
  84.  
  85.  
  86.  
  87. }
  88.  
  89. cin.get();
  90. cin.get();
  91.  
  92. }
  93.  
  94.  
  95. void clear_da_screen(void)
  96. {
  97. COORD coordScreen = { 0, 0 };
  98. DWORD cCharsWritten;
  99. CONSOLE_SCREEN_BUFFER_INFO csbi;
  100. DWORD dwConSize;
  101. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  102. GetConsoleScreenBufferInfo(hConsole, &csbi);
  103. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  104. FillConsoleOutputCharacter(hConsole, TEXT(' '),
  105. dwConSize, coordScreen, &cCharsWritten);
  106. GetConsoleScreenBufferInfo(hConsole, &csbi);
  107. FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
  108. dwConSize, coordScreen, &cCharsWritten);
  109. SetConsoleCursorPosition(hConsole, coordScreen);
  110. }

Use the arrow keys to move it up and down. Maybe?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,771
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 743
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: moving around in an array with arrow keys

 
0
  #5
Mar 3rd, 2006
>static int get_code ( void )
It's good to know that someone gets some use out of that function.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: moving around in an array with arrow keys

 
0
  #6
Mar 3rd, 2006
Originally Posted by Narue
>static int get_code ( void )
It's good to know that someone gets some use out of that function.
Lord knows I got that from somewhere else. Tee he

:cheesy:

[edit] Actually I think some of that directional key moving stuff
was written, or credited to you [/edit]
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,771
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 743
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: moving around in an array with arrow keys

 
0
  #7
Mar 3rd, 2006
>Lord knows I got that from somewhere else.
cprogramming.com, I imagine. Probably from the programming FAQ where some crazy person named Prelude wrote a HOWTO for using the directional keys in a console mode program.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: moving around in an array with arrow keys

 
0
  #8
Mar 3rd, 2006
ok so i tried rewriting it to fit what im trying to do but im gettin a linking error

error LNK2001: unresolved external symbol "public: void __thiscall Grid::clear_da_screen(void)" (?clear_da_screen@Grid@@QAEXXZ)

fatal error LNK1120: 1 unresolved externals

  1. void Grid::arrow_keys()
  2. {
  3. array[DEPTH][ROW][COL];
  4. for(int d=0; d<DEPTH; d++)
  5. {
  6. for(int r=0; r<ROW; r++)
  7. {
  8. for(int c=0; c<COL; c++)
  9. {
  10. array[d][r][c]=' ';
  11. }
  12. }
  13. }
  14.  
  15.  
  16. int r,c;
  17. r=0;
  18. c=0;
  19.  
  20.  
  21. int ch;
  22.  
  23. while ( ( ch = get_code() ) != KEY_ESC ) {
  24. clear_da_screen();
  25. switch ( ch )
  26. {
  27. case ARROW_UP:
  28. //printf ( "UP\n" );
  29. r=r-1;
  30. break;
  31. case ARROW_DOWN:
  32. //printf ( "DOWN\n" );
  33. r=r+1;
  34. break;
  35. case ARROW_LEFT:
  36. //printf ( "LEFT\n" );
  37. c=c-1;
  38. break;
  39. case ARROW_RIGHT:
  40. //printf ( "RIGHT\n" );
  41. c=c+1;
  42. break;
  43.  
  44.  
  45. }
  46.  
  47. array[d][r][c]=ACTIVE;
  48. for(int d=0; d<DEPTH; d++)
  49. {
  50. for(int r=0; r<ROW; r++)
  51. {
  52. for(int c=0; c<COL; c++)
  53. {
  54. cout<<array[d][r][c]<<" ";
  55. }
  56. }cout<<"\n";
  57. }
  58. array[d][r][c]=VISIT;
  59. //break;
  60.  
  61.  
  62.  
  63. }
  64.  
  65. cin.get();
  66. cin.get();
  67. }
  68.  
  69. void clear_da_screen(void)
  70. {
  71. COORD coordScreen = { 0, 0 };
  72. DWORD cCharsWritten;
  73. CONSOLE_SCREEN_BUFFER_INFO csbi;
  74. DWORD dwConSize;
  75. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  76. GetConsoleScreenBufferInfo(hConsole, &csbi);
  77. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  78. FillConsoleOutputCharacter(hConsole, TEXT(' '),
  79. dwConSize, coordScreen, &cCharsWritten);
  80. GetConsoleScreenBufferInfo(hConsole, &csbi);
  81. FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
  82. dwConSize, coordScreen, &cCharsWritten);
  83. SetConsoleCursorPosition(hConsole, coordScreen);
  84. }

thats all that u gave me and my attempt at rewriting it

[edit]
never mind stupid mistake on my part it compiles and links fine but it crashes now when i run it
[/edit]
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: moving around in an array with arrow keys

 
0
  #9
Mar 4th, 2006
it crashes when i hit one of the arrow keys i took out the function clear_da_screen too but i know thats not the problem
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: moving around in an array with arrow keys

 
0
  #10
Mar 5th, 2006
can you see what i am doing wrong??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC