Advertisement
ElooEminem

Untitled

Nov 13th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. class Thing{
  9. public:
  10. Thing(string name,int value){
  11. this->name=name;
  12. this->value=value;
  13. }
  14. string name;
  15. int value;
  16. };
  17.  
  18. class Node{
  19. public:
  20. Thing *item;
  21. Node(){
  22. this->item=NULL;
  23. }
  24. ~Node(){
  25. if(this->item)
  26. delete this->item;
  27. }
  28. };
  29.  
  30. class Graph{
  31. public:
  32. Node ***nodes;
  33. int x;
  34. int y;
  35. int width;
  36. int height;
  37. Graph(int width,int height,string *def){
  38. this->x=0;
  39. this->y=0;
  40. this->width=width;
  41. this->height=height;
  42. nodes=new Node **[height];
  43. for(int i=0;i<height;i++)
  44. for(int j=0;j<width;j++)
  45. if(def[i][j]=='X')
  46. nodes[i][j]=new Node();
  47. else
  48. nodes[i][j]=NULL;
  49. }
  50. void up(){
  51. if(this->x>0)
  52. this->x--;
  53. else
  54. cout<<"\nCannot move up.";
  55. return;
  56. }
  57. void down(){
  58. if(this->x<this->height-1)
  59. this->x++;
  60. else
  61. cout<<"\nCannot move down.";
  62. return;
  63. }
  64. void left(){
  65. if(this->y>0)
  66. this->y--;
  67. else
  68. cout<<"\nCannot move left.";
  69. return;
  70. }
  71. void right(){
  72. if(this->y<this->width-1)
  73. this->y++;
  74. else
  75. cout<<"\nCannot move right.";
  76. return;
  77. }
  78. ~Graph(){
  79. for(int i=0;i<height;i++)
  80. for(int j=0;j<width;j++)
  81. if(this->nodes[i][j])
  82. delete this->nodes[i][j];
  83. }
  84. };
  85.  
  86. int main(){
  87. srand(time(0));
  88.  
  89.  
  90.  
  91. getche();
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement