Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
// Head.h #ifndef HEAD_H #define HEAD_H #include <iostream> using namespace std; class Gra; class Gracz; class Gracz_cmp; class Gracz_user; class Interfejs; class Plansza; struct wspolrzedne { int x; int y; }; wspolrzedne konwertuj(string); #endif // HEAD_H // Funkcje.cpp #include "Head.h" wspolrzedne konwertuj(string pole) { wspolrzedne wynik; wynik.x = static_cast<int>(pole[0] - 65); wynik.y = static_cast<int>(pole[1] - 48); return wynik; } // main.cpp #include "Interfejs.h" using namespace std; int main() { Interfejs interfejs; interfejs.start(); return 0; } // Gra.h #ifndef GRA_H #define GRA_H #include "Head.h" class Gra { friend class Gracz_cmp; friend class Gracz_user; friend class Interfejs; public: Gra(Plansza*, Gracz*, Gracz*); void graj(); private: bool aktywna; Gracz* gracz1; Gracz* gracz2; Plansza* plansza; }; #endif // GRA_H // Gra.cpp #include <conio.h> #include <iostream> #include "Gra.h" #include "Gracz.h" #include "Plansza.h" using namespace std; /*class Gra { friend class Gracz_cmp; friend class Gracz_user; friend class Interfejs; public: Gra(Plansza*, Gracz*, Gracz*); void graj(); private: bool aktywna; Gracz* gracz1; Gracz* gracz2; Plansza* plansza; };*/ Gra::Gra(Plansza* board, Gracz* p1, Gracz* p2) : plansza(board), gracz1(p1), gracz2(p2), aktywna(true) { } void Gra::graj() { cout << "Uruchamiam gre\n"; while (aktywna) { plansza->wyswietl(); gracz1->ruch(); if (plansza->czy_koniec()) { aktywna = false; break; } plansza->wyswietl(); gracz2->ruch(); if (plansza->czy_koniec()) { aktywna = false; break; } cout << "Tura zostala wykonana, wcisnij dowolny klawisz...\n"; _getch(); } } // Gracz.h #ifndef GRACZ_H #define GRACZ_H #include "Head.h" class Gracz { public: Gracz(char); virtual void ruch() = 0; void set_gra(Gra*); protected: char symbol; Gra* gra; }; #endif // GRACZ_H // Gracz.cpp #include "Gracz.h" /*class Gracz { public: Gracz(char); virtual void ruch() = 0; void set_gra(Gra*); protected: char symbol; Gra* gra; };*/ Gracz::Gracz(char znak) : symbol(znak), gra(nullptr) { } void Gracz::set_gra(Gra* game) { gra = game; } // Gracz_cmp.h #ifndef GRACZ_CMP_H #define GRACZ_CMP_H #include "Gracz.h" #include "Head.h" class Gracz_cmp : public Gracz { public: Gracz_cmp(char); void ruch(); }; #endif // GRACZ_CMP_H // Gracz_cmp.cpp #include <conio.h> #include <ctime> #include <iostream> #include "Gra.h" #include "Gracz_cmp.h" #include "Plansza.h" using namespace std; /*class Gracz_cmp : public Gracz { public: Gracz_cmp(char); void ruch(); };*/ Gracz_cmp::Gracz_cmp(char znak) : Gracz(znak) { } void Gracz_cmp::ruch() { cout << "Komputer wykonuje ruch\n"; gra->plansza->lista_wolnych_pol(); //gra->plansza->wypisz_wolne_pola(); srand(static_cast<unsigned>(time(nullptr))); int wybor = rand() % gra->plansza->wolne_pola.size(); gra->plansza->zapelnij_pole(gra->plansza->wolne_pola[wybor], symbol); cout << "Ruch komputera wykonany, wcisnij dowolny klawisz...\n"; _getch(); } // Gracz_user.h #ifndef GRACZ_USER_H #define GRACZ_USER_H #include <iostream> #include "Gracz.h" #include "Head.h" using namespace std; class Gracz_user : public Gracz { public: Gracz_user(string, char); void ruch(); private: string imie; }; #endif // GRACZ_USER_H // Gracz_user.cpp #include "Gra.h" #include "Gracz_user.h" #include "Plansza.h" /*class Gracz_user : public Gracz { public: Gracz_user(string, char); void ruch(); private: string imie; };*/ Gracz_user::Gracz_user(string name, char znak) : Gracz(znak), imie(name) { } void Gracz_user::ruch() { cout << "Uzytkownik wykonuje ruch\n"; cout << "Podaj wspolrzedne, gdzie chcesz wstawic " << symbol << ": (np. B3)"; string pole; cin >> pole; // !!!! wpisaæ sprawdzenie wspó³rzêdnych! wspolrzedne xy = konwertuj(pole); gra->plansza->zapelnij_pole(xy, symbol); cout << "Ruch gracza wykonany, wcisnij dowolny klawisz...\n"; } // Interfejs.h #ifndef INTERFEJS_H #define INTERFEJS_H #include "Head.h" class Interfejs { public: Interfejs(); ~Interfejs(); void start(); private: Gra* gra; Gracz* gracz1; Gracz* gracz2; Plansza* plansza; }; #endif // INTERFEJS_H // Interfejs.cpp #include <conio.h> #include <iostream> #include "Gra.h" #include "Gracz_cmp.h" #include "Gracz_user.h" #include "Interfejs.h" #include "Plansza.h" using namespace std; /*class Interfejs { public: Interfejs(); ~Interfejs(); void start(); private: Gra* gra; Gracz* gracz1; Gracz* gracz2; Plansza* plansza; };*/ Interfejs::Interfejs() : plansza(nullptr), gra(nullptr), gracz1(nullptr), gracz2(nullptr) { } Interfejs::~Interfejs() { if (plansza) delete plansza; if (gra) delete gra; if (gracz1) delete gracz1; if (gracz2) delete gracz2; cout << "Intefejs usuniety\n"; } void Interfejs::start() { cout << "Wpisz swoje imie: "; string name; cin >> name; cout << "Kto ma zaczynac gre? (U - uzytkownik, K - komputer): "; char wybor; do { wybor = _getch(); } while (wybor != 'k' && wybor != 'K' && wybor != 'u' && wybor != 'U'); wybor = toupper(wybor); cout << wybor << endl; if (wybor == 'K') // zaczyna komputer { gracz1 = new Gracz_cmp('O'); gracz2 = new Gracz_user(name, 'X'); } else // zaczyna u¿ytkownik { gracz1 = new Gracz_user(name, 'O'); gracz2 = new Gracz_cmp('X'); } cout << "Okresl jak duza ma byc plansza (minimum 5, maksimum 26): "; int rozmiar; cin >> rozmiar; while (rozmiar < 5 || rozmiar > 26) { cout << "Podany przez Ciebie rozmiar nie jest prawidlowy, wpisz jeszcze raz: "; cin >> rozmiar; } // tworzymy planszę plansza = new Plansza(rozmiar); // tworzymy grę gra = new Gra(plansza, gracz1, gracz2); gracz1->set_gra(gra); gracz2->set_gra(gra); gra->graj(); } // Plansza.h #ifndef PLANSZA_H #define PLANSZA_H #include <vector> #include "Head.h" using namespace std; class Plansza { friend class Gracz_cmp; friend class Gracz_user; private: char** tablica; int rozmiar; vector<wspolrzedne> wolne_pola; public: Plansza(int); ~Plansza(); bool czy_koniec(); bool czywolne(wspolrzedne); void lista_wolnych_pol(); void wypisz_wolne_pola(); void wyswietl(); void zapelnij_pole(wspolrzedne, char); }; #endif // PLANSZA_H // Plansza.cpp #include <iostream> #include "Plansza.h" using namespace std; /*class Plansza { friend class Gracz_cmp; friend class Gracz_user; private: char** tablica; int rozmiar; vector<wspolrzedne> wolne_pola; public: Plansza(int); ~Plansza(); bool czy_koniec(); bool czywolne(wspolrzedne); void lista_wolnych_pol(); void wypisz_wolne_pola(); void wyswietl(); void zapelnij_pole(wspolrzedne, char); };*/ Plansza::Plansza(int wielkosc) : rozmiar(wielkosc) { tablica = new char* [rozmiar]; for (int i = 0; i < rozmiar; ++i) { tablica[i] = new char[rozmiar]; for (int j = 0; j < rozmiar; ++j) tablica[i][j] = ' '; } } Plansza::~Plansza() { for (int i = 0; i < rozmiar; ++i) { delete[] tablica[i]; } delete[] tablica; cout << "Plansza zostala usunieta" << endl; } bool Plansza::czy_koniec() { cout << "Sprawdzam czy gra ma byc kontynuowana\n"; return false; } bool Plansza::czywolne(wspolrzedne xy) { if (tablica[xy.x][xy.y] == ' ') return true; return false; } void Plansza::lista_wolnych_pol() { wspolrzedne xy; for (int i = 0; i < rozmiar; ++i) for (int j = 0; j < rozmiar; ++j) { xy.x = i; xy.y = j; if (czywolne(xy)) wolne_pola.push_back(xy); } } void Plansza::wypisz_wolne_pola() { for (int i = 0; i < wolne_pola.size(); ++i) { cout << "(" << wolne_pola[i].x << "," << wolne_pola[i].y << "), "; } cout << endl; } void Plansza::wyswietl() { for (int i = 0; i < rozmiar + 2; ++i) cout << '_'; cout << endl; for (int i = 0; i < rozmiar; ++i) { cout << '|'; for (int j = 0; j < rozmiar; ++j) cout << tablica[i][j]; cout << '|' << endl; } for (int i = 0; i < rozmiar + 2; ++i) cout << '_'; cout << endl; } void Plansza::zapelnij_pole(wspolrzedne xy, char symbol) { tablica[xy.x][xy.y] = symbol; }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
alias.txt
Lua | 1 hour ago | 1.66 KB
jobsites
JSON | 1 hour ago | 0.03 KB
PROMPT VIDEO
JSON | 2 hours ago | 2.41 KB
2D Pool C++ D2D (Semi-Circle Pockets+Felt Tex...
C++ | 4 hours ago | 225.58 KB
FoxPort with RU locale
Lua | 5 hours ago | 11.66 KB
2D StickPool C++ D2D (Pockets Are Semi-Circle...
C++ | 6 hours ago | 240.67 KB
Last_kmsg
Bash | 6 hours ago | 131.12 KB
Dmesg
Bash | 6 hours ago | 190.62 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!