Problem_all_the_time

game.cc

Feb 13th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include "game.h"
  3. #include <cstring>
  4. #include <vector>
  5. #include <iostream>
  6.  
  7. void DrawPiece(int row, int col, int player);
  8.  
  9. void InitializeBoard(int board[6][7]) {
  10. // Initialize board
  11. int row,col;
  12. for (row = 0; row < 6; ++row) {
  13. for (col = 0; col < 7; ++col) {
  14. board[row][col] = 0; // this makes the boards have slots of 0. But also is now A pointer because it is an array
  15. } // Nested for loop is doing what is it suppose to do
  16. }
  17. }
  18.  
  19. void DrawBoard(const int board[6][7], int column) {
  20. clear();
  21. int i,j;
  22. // Draw column lines
  23. for (j = 1; j < (6 * 4) + 1; ++j) {
  24. for (i = 0; i <= 7; ++i) {
  25. mvaddch(j, 10 * i, '|');
  26. }
  27. }
  28.  
  29. // Draw Row lines
  30. for (i = 4; i < 26; i += 4) {
  31. for (j = 1; j < 70; ++j) {
  32. if (j % 10 == 0) {
  33. continue;
  34. }
  35. mvaddch(i, j, '-');
  36. }
  37. }
  38.  
  39. // Draw pieces
  40. for (int row = 0; row < 6; row++) {
  41. for (int col = 0; col < 7; col++) {
  42. if (board[row][col] != 0) {
  43. DrawPiece(row, col, board[row][col]);
  44. }
  45. }
  46. }
  47.  
  48. int col_pos = 5 + (10 * column);
  49. mvaddch(0, col_pos, '!'); // This is the little icon at the top of the board. You use the right key and left key to move it around
  50. // press q to quit the game
  51. refresh();
  52. }
  53.  
  54. void DrawPiece(int row, int col, int player) {
  55. int start_row = (row * 4) + 1; // 25 and maybe + 42
  56. int start_col = (col * 10) + 1; //
  57.  
  58. char ch;
  59. if (player == 1) {ch = '#';} // The ## will fill up the block up, thus taking that spot
  60. else if (player == 2) {ch = ':';}
  61.  
  62. for (int r = start_row; r < start_row + 3; r++) {
  63. for (int c = start_col; c < start_col + 9; c++) {
  64. mvaddch(r, c, ch);
  65. }
  66. }
  67. }
  68.  
  69. bool Drop(int board[6][7], int player, int column) {
  70. // rows are 6
  71. // columns are 7
  72. // Recrusive functions take a copy of the discarded frame stack and if it gets called from main, it will be updated basically
  73. int playerMoves,Aimoves,rows;
  74. int* player_1;
  75. int* player_2;
  76. if (player == 1) {
  77. player_1 = &player; // Initializing the address of along with my pointy
  78. playerMoves = *player_1; // Storing the variable's address inside playerMoves.
  79. }else if (player == 2) {
  80. player_2 = &player;
  81. Aimoves = *player_2; // dereference my pointer.
  82. }
  83. //const int NUM_ELES = 42;
  84. for (rows = 7; rows >= 0; rows--) {
  85. if (board[rows][column] == 0 && playerMoves == 1) {
  86. board[rows][column] += playerMoves; // rows and columns are pointers pointing to playerMoves which was dereferenced
  87. DrawPiece(rows,column,playerMoves);
  88. return true; // Adding the break line or returning true makes it so the user cannot fill up the whole column
  89. }
  90. if (board[rows][column] == 0 && Aimoves == 2) {
  91. board[rows][column] += Aimoves;
  92. DrawPiece(rows,column,Aimoves);
  93. return true; // Adding the break line or returning true makes it so the user cannot fill up the whole column
  94. }
  95. } // Line 73 - 97 is copying the whole frame stack along with the true statement
  96. Drop(board,player,column); // Doing this copies the whole frame stack!
  97. return true;
  98. /*
  99. maxMiles = milesTracker[0][0];
  100. minMiles = milesTracker[0][0];
  101. for(i = 0; i < NUM_ROWS; i++){
  102. for(j = 0; j < NUM_COLS; j++){
  103. if(milesTracker[i][j] < minMiles){
  104. minMiles = milesTracker[i][j];
  105. }else if(milesTracker[i][j] > maxMiles){
  106. maxMiles = milesTracker[i][j];
  107. }
  108. }
  109. }*/
  110. }
  111.  
  112. int Winner(const int board[6][7]) {
  113. // Write a function that determines if the game is over, and if so which player won. This is the empty Winner function.
  114. //int playerMoves,Aimoves; // This is used to incrementing peices
  115. int player1_set = 1;
  116. int Ai_set = 2;
  117. //int Board[6][7];
  118. //Board[6][7] = board[6][7];
  119. //InitializeBoard(Board);
  120. int* set_1;
  121. int* set_2;
  122. //
  123. int& set1_ref = player1_set;
  124. int& set2_ref = Ai_set;
  125. //
  126. set_1 = &set1_ref;
  127. set_2 = &set2_ref; // Done setting up player 1 and two
  128.  
  129. for (int row = 0; row < 6; row++) {
  130. for (int col = 0; col < 7; col++) {
  131. if (board[*set_1][*set_1] >= 4) {
  132. std::cout << "Testing";
  133. }
  134. else if (board[*set_2][*set_2] >= 4) {
  135. std::cout << "Testing";
  136. }
  137. }
  138. }
  139.  
  140. return 0;
  141.  
  142. }
Add Comment
Please, Sign In to add comment