Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- #include <string>
- #include <Windows.h>
- using namespace std;
- const int Size = 10;
- const string symbol1[] = { "_|=|_", "(oxo)", "( o )", "(___)" };
- const string symbol2[] = { " A ", " /_\\ ", "/___\\", " |_| " };
- const string symbol3[] = { " | ", " _o_ ", "( )", " -w- " };
- const string symbol4[] = { " o ", " / \\ ", "/___\\", "[owo]" };
- /*
- _|=|_ A | o
- (oxo) /_\ _o_ / \
- ( o ) /___\ ( ) /___\
- (___) |_| -w- [owo]
- */
- HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
- const int HIGHLIGHT_COLOR = 10; //green
- //don't need
- /*void displayBoard(string board[Size][Size])
- {
- for (int row = 0; row < Size; row++)
- {
- for (int col = 0; col < Size; col++)
- {
- if (board[row][col] == "A")
- {
- cout << "A ";
- }
- else if (board[row][col] == "B")
- {
- cout << "B ";
- }
- else if (board[row][col] == "C")
- {
- cout << "C ";
- }
- else if (board[row][col] == "D")
- {
- cout << "D ";
- }
- }
- cout << endl;
- }
- }
- */
- //swap function
- void swapthem(string board[Size][Size], int x1, int y1, int x2, int y2)
- {
- string temp = board[y1][x1];
- board[y1][x1] = board[y2][x2];
- board[y2][x2] = temp;
- }
- //findMatching
- void findMatches(string board[Size][Size])
- {
- //rows
- for (int r = 0; r < Size; r++)
- {
- int amt = 1;
- string current = board[r][0];
- for (int c = 1; c < Size; c++)
- {
- if (board[r][c] == current)
- {
- amt++;
- }
- else
- {
- if (amt >= 3)
- {
- for (int x = c - 1; x >= c - amt; x--)
- board[r][x] = " ";
- }
- current = board[r][c];
- amt = 1;
- }
- }
- if (amt >= 3)
- {
- for (int x = Size - 1; x > Size -1 - amt; x--)
- board[r][x] = " ";
- }
- }
- //columns
- for (int c = 0; c < Size; c++)
- {
- int amt = 1;
- string current = board[0][c];
- for (int r = 1; r < Size; r++)
- {
- if (current == board[r][c])
- amt++;
- else
- {
- if (amt > 2)
- {
- for (int y = r - 1; y >= r - amt; y--)
- board[y][c] = " ";
- }
- current = board[r][c];
- amt = 1;
- }
- if (amt > 2)
- {
- for (int y = Size - 1; y > Size - 1 - amt; y--)
- {
- board[y][c] = " ";
- }
- }
- }
- }
- }
- /*
- bool gravity(string arr[Size][Size])
- {
- bool move = false;
- for (int y = 0; y < Size - 1; y++)
- {
- for (int j = 0; j < Size; j++)
- {
- if (arr[y][j] == " ")
- continue;
- //if you are floating
- if (arr[y + 1][j] == " ")
- {
- move = true;
- arr[y + 1][j] = arr[y][j];
- arr[y][j] = " ";
- }
- }
- }
- return move;
- }
- */
- void winCondition1()
- {
- cout << "1" << endl;
- }
- void winCondition2()
- {
- cout << "2" << endl;
- }
- void winCondition3()
- {
- cout << "3" << endl;
- }
- int main()
- {
- cout << "Welcome to the Puzzle Game" << endl;
- srand(time(NULL));
- /*------------------------------------------------------------*/
- string board[Size][Size];
- string possible[] = { "A", "B", "C", "D" }; //how to control <3 matches stand together after setting up randomly
- for (int row = 0; row < Size; row++)
- {
- for (int col = 0; col < Size; col++)
- board[row][col] = possible[rand() % 4]; //how many characters you gonna use
- }
- unsigned int row = 0; //no reason to have negative selections
- unsigned int col = 0;
- bool run = true;
- string result = "";
- while (run)
- {
- COORD pos;
- pos.X = 0;
- pos.Y = 0;
- SetConsoleCursorPosition(output, pos);
- SetConsoleTextAttribute(output, 15); //background
- system("cls");
- for (int i = 0; i < Size; i++)
- {
- for (int j = 0; j < Size; j++)
- {
- if (row == i && col == j)
- SetConsoleTextAttribute(output, 16 * HIGHLIGHT_COLOR + 8); //highlight color
- cout << board[i][j] << " ";
- SetConsoleTextAttribute(output, 15); //background
- }
- cout << endl;
- }
- findMatches(board);
- SetConsoleTextAttribute(output, 15);
- cout << endl;
- cout << result << endl;
- int x = 0;
- int y = 0;
- //using defindMatch to scan 4 direction whether it is a matche or not, put into all f 4
- if (GetAsyncKeyState(0x26) && row > 0)//UP
- {
- row--;
- Sleep(50);
- }
- else if (GetAsyncKeyState(0x28) && row < Size - 1) //DOWN
- {
- row++;
- Sleep(50);
- }
- else if (GetAsyncKeyState(0x25) && col > 0)//UP
- {
- col--;
- Sleep(50);
- }
- else if (GetAsyncKeyState(0x27) && col < Size - 1) //DOWN
- {
- col++;
- Sleep(50);
- }
- else if (GetAsyncKeyState(0x0D)) //Enter 1st character
- {
- x = col;
- y = row;
- Sleep(50);
- while (run)
- {
- if (GetAsyncKeyState(0x26) && row > 0)//UP
- {
- swapthem(board, x, y, x, y - 1);
- break;
- }
- else if (GetAsyncKeyState(0x28) && row < Size - 1) //DOWN
- {
- swapthem(board, x, y, x, y + 1);
- break;
- }
- else if (GetAsyncKeyState(0x25) && col > 0) //RIGHT
- {
- swapthem(board, x, y, x - 1, y);
- break;
- }
- else if (GetAsyncKeyState(0x27) && col < Size - 1) //LEFT
- {
- swapthem(board, x, y, x + 1, y);
- break;
- }
- }
- }
- Sleep(50);
- }
- system("Pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement