Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. //in parameterized constructor
  2. a = new char*[height+3];
  3. for(int i = 0; i < height+3; i++)
  4. {a[i] = new char[width+2];}
  5. ~destructor
  6. for (int i = 0; i < height+3; ++i)
  7. delete [] a[i];
  8. delete [] a;
  9. //elsewhere
  10. piece *current_piece; //both initialized to nullptr
  11. piece *next_piece;
  12.  
  13. void Game::update()
  14. {
  15. if(current_piece==nullptr && next_piece==nullptr)
  16. {
  17. switch (randPieceType())
  18. {
  19. case PIECE_I:
  20. current_piece=new I();// make the next piece an I piece
  21. break;
  22. case PIECE_L:
  23. current_piece=new L(); // make the next piece an L piece
  24. break;
  25. case PIECE_J:
  26. current_piece=new J(); // make the next piece an L piece
  27. break;
  28. case PIECE_T:
  29. current_piece=new T(); // make the next piece an L piece
  30. break;
  31. case PIECE_O:
  32. current_piece=new O(); // make the next piece an L piece
  33. break;
  34. case PIECE_S:
  35. current_piece=new S(); // make the next piece an L piece
  36. break;
  37. case PIECE_Z:
  38. current_piece=new Z(); // make the next piece an L piece
  39. break;
  40. }
  41.  
  42. }
  43. else
  44. { delete current_piece;
  45. current_piece=next_piece;
  46. }
  47. if(!next_piece)
  48. {
  49. delete next_piece;
  50. }
  51. switch (randPieceType())
  52. {
  53. case PIECE_I:
  54. next_piece=new I();// make the next piece an I piece
  55. break;
  56. case PIECE_L:
  57. next_piece=new L(); // make the next piece an L piece
  58. break;
  59. case PIECE_J:
  60. next_piece=new J(); // make the next piece an L piece
  61. break;
  62. case PIECE_T:
  63. next_piece=new T(); // make the next piece an L piece
  64. break;
  65. case PIECE_O:
  66. next_piece=new O(); // make the next piece an L piece
  67. break;
  68. case PIECE_S:
  69. next_piece=new S(); // make the next piece an L piece
  70. break;
  71. case PIECE_Z:
  72. next_piece=new Z(); // make the next piece an L piece
  73. break;
  74. }
  75. }
  76. //destructor
  77. ~Game(){delete next_piece; delete current_piece;}
  78.  
  79. // transition between levels
  80. delete current_piece; delete next_piece; incode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement