Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ncurses.h>
- #include "game.h"
- #include <cstring>
- #include <vector>
- #include <iostream>
- void DrawPiece(int row, int col, int player);
- void InitializeBoard(int board[6][7]) {
- // Initialize board
- int row,col;
- for (row = 0; row < 6; ++row) {
- for (col = 0; col < 7; ++col) {
- board[row][col] = 0; // this makes the boards have slots of 0. But also is now A pointer because it is an array
- } // Nested for loop is doing what is it suppose to do
- }
- }
- void DrawBoard(const int board[6][7], int column) {
- clear();
- int i,j;
- // Draw column lines
- for (j = 1; j < (6 * 4) + 1; ++j) {
- for (i = 0; i <= 7; ++i) {
- mvaddch(j, 10 * i, '|');
- }
- }
- // Draw Row lines
- for (i = 4; i < 26; i += 4) {
- for (j = 1; j < 70; ++j) {
- if (j % 10 == 0) {
- continue;
- }
- mvaddch(i, j, '-');
- }
- }
- // Draw pieces
- for (int row = 0; row < 6; row++) {
- for (int col = 0; col < 7; col++) {
- if (board[row][col] != 0) {
- DrawPiece(row, col, board[row][col]);
- }
- }
- }
- int col_pos = 5 + (10 * column);
- 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
- // press q to quit the game
- refresh();
- }
- void DrawPiece(int row, int col, int player) {
- int start_row = (row * 4) + 1; // 25 and maybe + 42
- int start_col = (col * 10) + 1; //
- char ch;
- if (player == 1) {ch = '#';} // The ## will fill up the block up, thus taking that spot
- else if (player == 2) {ch = ':';}
- for (int r = start_row; r < start_row + 3; r++) {
- for (int c = start_col; c < start_col + 9; c++) {
- mvaddch(r, c, ch);
- }
- }
- }
- bool Drop(int board[6][7], int player, int column) {
- // rows are 6
- // columns are 7
- // Recrusive functions take a copy of the discarded frame stack and if it gets called from main, it will be updated basically
- int playerMoves,Aimoves,rows;
- int* player_1;
- int* player_2;
- if (player == 1) {
- player_1 = &player; // Initializing the address of along with my pointy
- playerMoves = *player_1; // Storing the variable's address inside playerMoves.
- }else if (player == 2) {
- player_2 = &player;
- Aimoves = *player_2; // dereference my pointer.
- }
- //const int NUM_ELES = 42;
- for (rows = 7; rows >= 0; rows--) {
- if (board[rows][column] == 0 && playerMoves == 1) {
- board[rows][column] += playerMoves; // rows and columns are pointers pointing to playerMoves which was dereferenced
- DrawPiece(rows,column,playerMoves);
- return true; // Adding the break line or returning true makes it so the user cannot fill up the whole column
- }
- if (board[rows][column] == 0 && Aimoves == 2) {
- board[rows][column] += Aimoves;
- DrawPiece(rows,column,Aimoves);
- return true; // Adding the break line or returning true makes it so the user cannot fill up the whole column
- }
- } // Line 73 - 97 is copying the whole frame stack along with the true statement
- Drop(board,player,column); // Doing this copies the whole frame stack!
- return true;
- /*
- maxMiles = milesTracker[0][0];
- minMiles = milesTracker[0][0];
- for(i = 0; i < NUM_ROWS; i++){
- for(j = 0; j < NUM_COLS; j++){
- if(milesTracker[i][j] < minMiles){
- minMiles = milesTracker[i][j];
- }else if(milesTracker[i][j] > maxMiles){
- maxMiles = milesTracker[i][j];
- }
- }
- }*/
- }
- int Winner(const int board[6][7]) {
- // Write a function that determines if the game is over, and if so which player won. This is the empty Winner function.
- //int playerMoves,Aimoves; // This is used to incrementing peices
- int player1_set = 1;
- int Ai_set = 2;
- //int Board[6][7];
- //Board[6][7] = board[6][7];
- //InitializeBoard(Board);
- int* set_1;
- int* set_2;
- //
- int& set1_ref = player1_set;
- int& set2_ref = Ai_set;
- //
- set_1 = &set1_ref;
- set_2 = &set2_ref; // Done setting up player 1 and two
- for (int row = 0; row < 6; row++) {
- for (int col = 0; col < 7; col++) {
- if (board[*set_1][*set_1] >= 4) {
- std::cout << "Testing";
- }
- else if (board[*set_2][*set_2] >= 4) {
- std::cout << "Testing";
- }
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment