Total members 11894 |It is currently Sat Nov 23, 2024 3:29 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






* Project Name:   Tic_Tac_Toc
* Programmer:   Miklo4ever
* Type:   Game
* Technology:  C++
* IDE:   Any
* Description:   Tic Tac Toe game ---------------- This simple, yet useful/nice logic game is made for 2 players, can be ran in full screen or console view, and its fully customizable and can be edited with ease and allmost none knowlege of C++. I hope you like it, and i will upload an english version in coming future, for sure. This is my first upload to any database, so please, if i did anything wrong, take it easy on me :))), and let me know about it. Happy playing/programming!!

cpp code
/*
****************************************
**********KRIZCI IN KROZCI**************
*************Tic Tac Toe****************
**********(C) Matic Miklavcic***********
*******[email protected]*********
*+*+*+*+*All Rights Reserved!!!*+*+*+*+*
****************************************
Programirano v DevC++, 10. OKT 2009 ----
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
char A,B,C;
char D,E,F;
char G,H,I;
bool Player1win,Player2win;
string ime1,ime2;
//Maksimiranje Konzole
BOOL NT_SetConsoleDisplayMode(HANDLE hOutputHandle, DWORD dwNewMode)
{
typedef BOOL (WINAPI *SCDMProc_t) (HANDLE, DWORD, LPDWORD);
SCDMProc_t SetConsoleDisplayMode;
HMODULE hKernel32;
BOOL bFreeLib = FALSE, ret;
const char KERNEL32_NAME[] = "kernel32.dll";

hKernel32 = GetModuleHandleA(KERNEL32_NAME);
if (hKernel32 == NULL)
{
hKernel32 = LoadLibraryA(KERNEL32_NAME);
if (hKernel32 == NULL)
return FALSE;

bFreeLib = true;
}

SetConsoleDisplayMode =
(SCDMProc_t)GetProcAddress(hKernel32, "SetConsoleDisplayMode");
if (SetConsoleDisplayMode == NULL)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
ret = FALSE;
}
else
{
DWORD dummy;
ret = SetConsoleDisplayMode(hOutputHandle, dwNewMode, &dummy);
}

if (bFreeLib)
FreeLibrary(hKernel32);

return ret;
}
void KonecIgre()//Zaigraj zalostno melodijo :((
{
Beep(784,500);
Beep(738,500);
Beep(684,500);
Beep(644,1000);
}
void Pesmica()//Zaigraj melodijo ob zmagi :))
{
Beep(523,200);//Uporabi Beep(frekvenca,cas); za predvajanje zvoka na internem zvocniku
Sleep(1);//Ustavi program(cas)
Beep(523,200);
Sleep(1);
Beep(523,200);
Sleep(1);
Beep(659,700);
Beep(784,500);
Beep(523,200);
Sleep(1);
Beep(523,200);
Sleep(1);
Beep(523,200);
Sleep(1);
Beep(659,700);
Beep(784,500);
Sleep(800);
Beep(784,400);
Beep(884,200);
Beep(784,200);
Beep(687,200);
Beep(659,200);
Beep(579,200);
Beep(519,400);
}


//izpisi Pomoc
int Help()
{
system("CLS");
cout<<"Pomoc\n-----\nIzmenicno vpisujta crke od A do I, dokler nekdo ne zmaga ali so vsa polja zapolnjena.\n-------\nBy Mickey\n(Zaslon zgine v 7 sekundah)";
}


//izpisi Menu
int Menu()
{
zacetek:
int izbira;
cout<<"Zivjo!\n-----\n1.Zacni Igro\n2.Pomoc\n3.Izhod\n\n>> ";
cin>>izbira;
switch(izbira)
{
case 1:
goto point;
break;
case 2:
Help();
Sleep(7000);
system("CLS");
goto zacetek;
break;
case 3:
exit(1);
break;
point:
system("CLS");
}
}



//zrisi tabelo, klicano tudi po vsaki igri
void Izrisi()
{
system("CLS");
A=toupper(A);
B=toupper(B);
C=toupper(C);
D=toupper(D);
E=toupper(E);
F=toupper(F);
G=toupper(G);
H=toupper(H);
I=toupper(I);
cout<<"|---|---|---|"<<endl
<<"| "<<A<<" | "<<B<<" | "<<C<<" |"<<endl
<<"|---|---|---|"<<endl
<<"| "<<D<<" | "<<E<<" | "<<F<<" |"<<endl
<<"|---|---|---|"<<endl
<<"| "<<G<<" | "<<H<<" | "<<I<<" |"<<endl
<<"|---|---|---|"<<endl<<endl;
}
//zrisi zvezdice ob zmagi
void Zvezdice()
{
cout<<"\n* * * * * *"
<<" * * * * * *"
<<" * * * * * *"
<<" * * * * * * * * * *"
<<"* * * ** * * *\n\n";
}


//izpisi zmagovalca
void Zmaga(int pNumb=0)
{
switch(pNumb)
{
case 1://ce je zmagal igralec 1
cout<<ime1<<" Zmaga!!!!!! Cestitam!\n";
Zvezdice();
Pesmica();
break;
case 2://ce je zmagal igralec 2
cout<<ime2<<" Zmaga!!!!!! Cestitam!\n";
Zvezdice();
Pesmica();
break;
}
}





//preveri zmagovalca
int PreveriZmag()
{
//PREVERI ZA X-e
//Horizontalno
if(A=='X'&&B=='X'&&C=='X')
{
Player1win=true;
}
if(D=='X'&&E=='X'&&F=='X')
{
Player1win=true;
}
if(G=='X'&&H=='X'&&I=='X')
{
Player1win=true;
}
//Vertikalno
if(A=='X'&&D=='X'&&G=='X')
{
Player1win=true;
}
if(B=='X'&&E=='X'&&H=='X')
{
Player1win=true;
}
if(C=='X'&&F=='X'&&I=='X')
{
Player1win=true;
}
//Posevno
if(A=='X'&&E=='X'&&I=='X')
{
Player1win=true;
}
if(G=='X'&&E=='X'&&C=='X')
{
Player1win=true;
}
/* ZACETEK O-jev
preveri vse se enkrat
_-_-_-_-_-_-_-_-_-_-_-*/
//Vertikalno
if(A=='O'&&B=='O'&&C=='O')
{
Player2win=true;
}
if(D=='O'&&E=='O'&&F=='O')
{
Player2win=true;
}
if(G=='O'&&H=='O'&&I=='O')
{
Player2win=true;
}
//Vertikalno
if(A=='O'&&D=='O'&&G=='O')
{
Player2win=true;
}
if(B=='O'&&E=='O'&&H=='O')
{
Player2win=true;
}
if(C=='O'&&F=='O'&&I=='O')
{
Player2win=true;
}
//Posevno
if(A=='O'&&E=='O'&&I=='O')
{
Player2win=true;
}
if(G=='O'&&E=='O'&&C=='O')
{
Player2win=true;
}
/*Preveri ce sta oba Bool-a TRUE,
ce sta, izpisi Brez Zmagovalca,
ce nista, izpisi zmagovalca*/


if (Player1win==true)
{//igralec 1 zmaga
system("CLS");
Zmaga(1);
return 1;



}
else
{//ce ni zmagal igralec 1, preveri ce igr. 2 zmaga
if (Player2win==true)//ce ne, nadaljuj
{
system("CLS");
Zmaga(2);

return 1;
}
}



}





//napacna lokacija x ali o, poskusi se enkrat, ce tam ze obstaja x ali O
void Napaka()
{
system("CLS");
cout<<"Ups, tam je ze krizec ali krozec.\nPoskusi znova!";
Sleep(2000);
system("CLS");
Izrisi();
}
//igralec 1 : igraj!
void Igralec1()
{//GLAVNA FUNKCIJA IGRALCA 1!!!!
char choice;
start:
cout<<ime1<<" (X): ";
cin>>choice;
choice=toupper(choice);
switch(choice)
{
case 'A':
if(A!='O')A='X';
else
{
Napaka();
goto start;
}
break;
case 'B':
if(B!='O')B='X';
else
{
Napaka();
goto start;
}
break;
case 'C':
if(C!='O')C='X';
else
{
Napaka();
goto start;
}
break;
case 'D':
if(D!='O')D='X';
else
{
Napaka();
goto start;
}
break;
case 'E':
if(E!='O')E='X';
else
{
Napaka();
goto start;
}
break;
case 'F':
if(F!='O')F='X';
else
{
Napaka();
goto start;
}
break;
case 'G':
if(G!='O')G='X';
else
{
Napaka();
goto start;
}
break;
case 'H':
if(H!='O')H='X';
else
{
Napaka();
goto start;
}
break;
case 'I':
if(I!='O')I='X';
else
{
Napaka();
goto start;
}
break;
default:
system("CLS");
cout<<"Ups, napacna crka. Poskusi znova!\n";
Sleep(2000);
Izrisi();
goto start;
break;
}
Izrisi();
}
//igralec 2: igraj!
void Igralec2()
{//GLAVNA FUNKCIJA IGRALCA 2!!!!
char choice;
start:
cout<<ime2<<" (O): ";
cin>>choice;
choice=toupper(choice);
switch(choice)
{
case 'A':
if(A!='X')A='O';
else
{
Napaka();
goto start;
}
break;
case 'B':
if(B!='X')B='O';
else
{
Napaka();
goto start;
}
break;
case 'C':
if(C!='X')C='O';
else
{
Napaka();
goto start;
}
break;
case 'D':
if(D!='X')D='O';
else
{
Napaka();
goto start;
}
break;
case 'E':
if(E!='X')E='O';
else
{
Napaka();
goto start;
}
break;
case 'F':
if(F!='X')F='O';
else
{
Napaka();
goto start;
}
break;
case 'G':
if(G!='X')G='O';
else
{
Napaka();
goto start;
}
break;
case 'H':
if(H!='X')H='O';
else
{
Napaka();
goto start;
}
break;
case 'I':
if(I!='X')I='O';
else
{
Napaka();
goto start;
}
break;
default://ce igralec vpise napacno crko - ni od A do G, ga opozori in vrni na zacetek
system("CLS");
cout<<"Ups, napacna crka. Poskusi znova!\n";
Sleep(2000);
Izrisi();
goto start;
break;
}
Izrisi();
}









//Main funkcija igre, poveze vse podfunkcije->MAIN!!!
int main()
{
int celZas;
cout<<"Zazenem v celozaslonskem nacinu?\n1.Ja\n2.Ne\n>>";
cin>>celZas;
if(celZas==1)
{//CEL ZASLON DA
NT_SetConsoleDisplayMode( GetStdHandle( STD_OUTPUT_HANDLE ), 1 );
}
system("CLS");
cout<<"Krizci In Krozci\n";
Menu();
cout<<"Ime igralca 1: ";
cin>>ime1;
cout<<"Ime igralca 2: ";
cin>>ime2;
int retPreveri;
Player1win=false;
Player2win=false;
char choice;
A='A';//Ponastavi osnovne vrednosti spremenljivk
B='B';
C='C';
D='D';
E='E';
F='F';
G='G';
H='H';
I='I';
Izrisi();
Igralec1();//Igra!!!
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec2();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec1();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec2();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec1();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec2();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec1();
retPreveri=PreveriZmag();
if(retPreveri==1)goto end;
Igralec2();
retPreveri=PreveriZmag();//------
if(retPreveri==1)goto end;
system("CLS");
cout<<ime1<<", "<<ime2<<", igra je koncana!!! Nihce ni zmagal! Vec srece prihodnic."<<endl<<endl;//ce nihce ne zmaga
KonecIgre();//zaigraj zalostno pesmico :((
end://Konec
system("PAUSE");
}





Attachments:
Tic_Tac_Toc.zip [3.01 KiB]
Downloaded 1557 times

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 




Topic Tags

C++ Projects







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com