BIG Function Help..

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

Join Date: Aug 2005
Posts: 29
Reputation: vartotojas is an unknown quantity at this point 
Solved Threads: 0
vartotojas vartotojas is offline Offline
Light Poster

BIG Function Help..

 
0
  #1
Sep 28th, 2005
So my problem is that my function isn't working properly. I realize that this is not efficient but I need it done in one fucntion.

It is supposed to be a function that draws a room and lets you walk around in it using the arrow keys in console mode.

The Problem lies in the movement..Something is very messed up and I just can't understand why! :eek:

Here is the code and if ANYONE can help Thank You!!!

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6. void MovementAndRoom(int height, int width){
  7. /*
  8.  
  9.   **corner - All refer to the corners ASCII code
  10.   *border - Refers to the border ASCII code
  11.   space - Refers to space ASCII code
  12.   o* - Refer to the original Values given to the function
  13.   //331 Left
  14. //333 right
  15. //328 UP
  16. //336 Down
  17.   */
  18. char tleftcorner = 201;
  19. char bleftcorner = 200;
  20. char trightcorner = 187;
  21. char brightcorner = 188;
  22. char hborder = 186;
  23. char vborder = 205;
  24. char space = 040;
  25. /*
  26.   int left = 331;
  27.   int right = 333;
  28.   int up = 328;
  29.   int down = 336;
  30.   */
  31. int oheight = height;
  32. int owidth = width;
  33. int currentLineNumber = 0;
  34. int currentRowNumber = 0;
  35. int rowNumber = 3;
  36. int lineNumber = 6;
  37. char move;
  38.  
  39. while(true){
  40. move;
  41. while(move = getch()){
  42. currentRowNumber = 0;
  43. currentLineNumber = 0;
  44. //Use of the Color Console Code to Color the Box
  45. cout << tleftcorner;
  46. //Makes the top bar - vborder is shown twice because a line break is
  47. //roughly twice as large as a space
  48. width = owidth;
  49. height = oheight;
  50. while(width > 0){
  51. cout << vborder << vborder;
  52. width--;
  53. }
  54. //Show the Right Corner
  55. cout << trightcorner << endl;
  56. //Resets Width
  57. width = owidth;
  58. //Makes the rows with spaces in betwen for future expansion
  59.  
  60. while(height > 0){
  61. //Shows Border
  62.  
  63.  
  64. cout << hborder;
  65. while(width > 0){
  66.  
  67. if(lineNumber == currentLineNumber && (rowNumber * currentLineNumber) == currentRowNumber){
  68. cout << "X" << space;
  69. } else{
  70. //Adds Spaces
  71. cout << space << space;
  72. }
  73.  
  74. currentRowNumber++;
  75. width--;
  76. }
  77.  
  78. //Shows Right Border
  79. cout << hborder << endl;
  80. currentLineNumber++;
  81. currentRowNumber = owidth;
  82. //Resets Width
  83. width = owidth;
  84. //Lowers Height for new Row
  85. height--;
  86. }
  87.  
  88. //Shows Bottom Left Corner
  89. cout << bleftcorner;
  90. //Shows the bottom Border
  91. while(width > 0){
  92. cout << vborder << vborder;
  93. width--;
  94. }
  95. //Shows Last Corner
  96. cout << brightcorner << endl;
  97. move;
  98. move = getch();
  99.  
  100. switch(move){
  101. case 331:
  102. if(rowNumber == 1){
  103. break;
  104. }
  105. rowNumber--;
  106. move;
  107. break;
  108.  
  109. case 333:
  110. if(rowNumber == width - 1){
  111. break;
  112. }
  113. rowNumber++;
  114. move;
  115. break;
  116.  
  117. case 328:
  118. if(lineNumber == height - 1){
  119. break;
  120. }
  121. move = 'a';
  122. lineNumber--;
  123. break;
  124.  
  125. case 336:
  126. if(lineNumber == 1){
  127. break;
  128. }
  129. move = 'a';
  130. lineNumber++;
  131. break;
  132. }
  133.  
  134. }
  135. }
  136. }
  137.  
  138. int main(int argc, char *argv[])
  139. {
  140. int width = 5,height = 5;
  141.  
  142. //Calls room function
  143. cout << "How Wide do you want to the room to be? ";
  144. cin >> width;
  145. cout << "How High do you want to the room to be? ";
  146. cin >> height;
  147.  
  148. MovementAndRoom(height,width);
  149.  
  150. system("PAUSE");
  151. return EXIT_SUCCESS;
  152. }

This is in Dev-C++ on a windows machine.
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