Guest User

Untitled

a guest
Dec 24th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. // TablePrinter.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include<cstdlib>
  7.  
  8. #define ROWS 10
  9. #define COLUMNS 10
  10.  
  11. using namespace std;
  12.  
  13. struct sprite{
  14. int x;
  15. int y;
  16. int id;
  17. };
  18.  
  19. void PrintTable(void);
  20. struct sprite PlaceCharacter(void);
  21. struct sprite MoveCharacter(struct sprite pacman);
  22.  
  23.  
  24. int table[ROWS][COLUMNS] = {0};
  25.  
  26. int _tmain(int argc, _TCHAR* argv[])
  27. {
  28. struct sprite pacman;
  29.  
  30. PrintTable();
  31. system("PAUSE");
  32.  
  33. pacman = PlaceCharacter();
  34. system("CLS");
  35. PrintTable();
  36.  
  37. pacman = MoveCharacter(pacman);
  38. system("CLS");
  39. PrintTable();
  40. system("PAUSE");
  41. return 0;
  42. }
  43.  
  44. void PrintTable(void)
  45. {
  46. int i,j;
  47.  
  48. for (i=0;i<ROWS;i++)
  49. {
  50. for (j=0;j<COLUMNS;j++)
  51. {
  52. cout << table[i][j] << " ";
  53. }
  54. cout << endl;
  55. }
  56. }
  57.  
  58. struct sprite PlaceCharacter(void)
  59. {
  60. struct sprite pacman;
  61. int i,j;
  62.  
  63. do
  64. {
  65. cout << "Give me the row: " ;
  66. cin >> i;
  67. }while(i<0 || i>ROWS-1);
  68.  
  69. do
  70. {
  71. cout << "Give me the column: " ;
  72. cin >> j;
  73. }while(j<0 || j>COLUMNS-1);
  74.  
  75. pacman.x = i;
  76. pacman.y = j;
  77. pacman.id = 1;
  78.  
  79. table[pacman.x][pacman.y] = pacman.id;
  80.  
  81. return pacman;
  82. }
  83.  
  84. struct sprite MoveCharacter(struct sprite pacman)
  85. {
  86. int move;
  87. int i = pacman.x;
  88. int j = pacman.y;
  89. do
  90. {
  91. cout << "Give me the move using your numpad (5 to stay still): " ;
  92. cin >> move;
  93. }while(move<1 || move>9);
  94.  
  95. switch (move)
  96. {
  97. case 1:
  98. table[i][j] = 0;
  99. pacman.x = i+1;
  100. pacman.y = j-1;
  101. table[pacman.x][pacman.y] = pacman.id;
  102. break;
  103. case 2:
  104. table[i][j] = 0;
  105. pacman.x = i+1;
  106. pacman.y = j;
  107. table[pacman.x][pacman.y] = pacman.id;
  108. break;
  109. case 3:
  110. table[i][j] = 0;
  111. pacman.x = i+1;
  112. pacman.y = j+1;
  113. table[pacman.x][pacman.y] = pacman.id;
  114. break;
  115. case 4:
  116. table[i][j] = 0;
  117. pacman.x = i;
  118. pacman.y = j-1;
  119. table[pacman.x][pacman.y] = pacman.id;
  120. break;
  121. case 5:
  122. table[i][j] = pacman.id;
  123. break;
  124. case 6:
  125. table[i][j] = 0;
  126. pacman.x = i;
  127. pacman.y = j+1;
  128. table[pacman.x][pacman.y] = pacman.id;
  129. break;
  130. case 7:
  131. table[i][j] = 0;
  132. pacman.x = i-1;
  133. pacman.y = j-1;
  134. table[pacman.x][pacman.y] = pacman.id;
  135. break;
  136. case 8:
  137. table[i][j] = 0;
  138. pacman.x = i-1;
  139. pacman.y = j;
  140. table[pacman.x][pacman.y] = pacman.id;
  141. break;
  142. case 9:
  143. table[i][j] = 0;
  144. pacman.x = i-1;
  145. pacman.y = j+1;
  146. table[pacman.x][pacman.y] = pacman.id;
  147. break;
  148. default:
  149. cout << "Invalid Move!";
  150. break;
  151. }
  152. return pacman;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment