Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <ctime>
- #include <fstream>
- #include <Windows.h>
- using namespace std;
- class Square {
- friend class Blank;
- friend class Piece;
- friend class DoublePiece;
- friend class Checkers;
- bool P1;
- bool P2;
- bool DP;
- friend class P1;
- Square() {
- P1 = false;
- P2 = false;
- DP = false;
- }
- virtual void viewSquare() = 0;
- };
- class Blank : public Square {
- friend class Checkers;
- Blank() {}
- virtual void viewSquare() {
- cout << " ";
- }
- };
- class Piece : public Square {
- friend class Checkers;
- Piece(int Player) {
- if (Player == 1) {
- P1 = true;
- }
- else {
- P2 = true;
- }
- }
- virtual void viewSquare() {
- cout << " ţ ";
- }
- };
- class DoublePiece : public Square {
- friend class Checkers;
- DoublePiece(int Player) {
- if (Player == 1) {
- P1 = true;
- DP = true;
- }
- else {
- P2 = true;
- DP = true;
- }
- }
- virtual void viewSquare() {
- cout << "[ţ]";
- }
- };
- class Checkers {
- friend bool Game();
- Square ***Grid;
- Checkers() {
- Grid = new Square**[8];
- for (int i = 0; i < 8; i++) {
- Grid[i] = new Square*[8];
- }
- for (int y = 0; y < 8; y++) {
- for (int x = 0; x < 8; x++) {
- Grid[x][y] = new Blank;
- }
- }
- }
- void view() {
- cout << " ";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
- cout << " " << endl;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- for (int y = 0; y < 8; y++) {
- cout << " ";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
- cout << " ";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- for (int x = 0; x < 8; x++) {
- if (y % 2) {
- if (x % 2) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
- Grid[x][y]->viewSquare();
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- }
- else {
- if (Grid[x][y]->P1) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0B);
- }
- else if (Grid[x][y]->P2) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0E);
- }
- Grid[x][y]->viewSquare();
- }
- }
- else {
- if (x % 2) {
- if (Grid[x][y]->P1) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0B);
- }
- else if (Grid[x][y]->P2) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0E);
- }
- Grid[x][y]->viewSquare();
- }
- else {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
- Grid[x][y]->viewSquare();
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- }
- }
- }
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
- cout << " ";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- cout << endl;
- }
- cout << " ";
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
- cout << " " << endl;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
- }
- void setPieces() {
- for (int x = 1; x < 8; x+=2) {
- Grid[x][0] = new Piece(2);
- }
- for (int x = 0; x < 8; x += 2) {
- Grid[x][1] = new Piece(2);
- }
- for (int x = 1; x < 8; x += 2) {
- Grid[x][2] = new Piece(2);
- }
- for (int x = 0; x < 8; x += 2) {
- Grid[x][5] = new Piece(1);
- }
- for (int x = 1; x < 8; x += 2) {
- Grid[x][6] = new Piece(1);
- }
- for (int x = 0; x < 8; x += 2) {
- Grid[x][7] = new Piece(1);
- }
- }
- };
- bool Game() {
- system("cls");
- cout << "Warcaby" << endl << endl;
- Checkers Game;
- Game.setPieces();
- Game.view();
- return 1;
- /*cout << "[1] Zagraj" << endl << "[2] Wyswietl rezultaty ostatnich gier" << endl;
- unsigned char choice;
- choice = _getch();
- if (choice == 49) { system("cls"); }
- else if (choice == 50) {
- system("cls");
- cout << "Rezultaty ostatnich gier:" << endl << endl;
- fstream file;
- file.open("Statki.txt", ios::in);
- string result;
- while (getline(file, result)) {
- cout << result << endl;
- }
- file.close();
- cout << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- return 1;
- }
- else { return 1; }
- string Name1, Name2;
- cout << "Wpisz imiona graczy:" << endl;
- cout << "Gracz 1: ";
- cin >> Name1;
- cout << "Gracz 2: ";
- cin >> Name2;
- srand(time(0));
- int random = rand() % 2;
- if (random) {
- swap(Name1, Name2);
- }
- Player Player1(Name1);
- Player Player2(Name2);
- system("cls");
- cout << Player1.Name << " ustawia statki.";
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- Player1.setShips();
- cout << endl << "Gotowe";
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- system("cls");
- cout << Player2.Name << " ustawia statki.";
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- Player2.setShips();
- cout << endl << "Gotowe";
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- while (true) {
- system("cls");
- cout << "Ruch gracza: " << Player1.Name;
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- while (true) {
- system("cls");
- Player2.displayEnemysGrid();
- cout << endl;
- Player1.displayMyGrid();
- cout << endl << "Wybierz cel: ";
- string Point;
- cin >> Point;
- int pointX = Point[0] - 65;
- int pointY = Point[1] - 48;
- }
- system("cls");
- cout << "Ruch gracza: " << Player2.Name;
- cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
- _getch();
- while (true) {
- system("cls");
- Player1.displayEnemysGrid();
- cout << endl;
- Player2.displayMyGrid();
- cout << endl << "Wybierz cel: ";
- string Point;
- cin >> Point;
- int pointX = Point[0] - 65;
- int pointY = Point[1] - 48;
- }
- }*/
- }
- int main() {
- Game();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement