تور لحظه آخری
امروز : شنبه ، 31 شهریور 1403    احادیث و روایات:  پیامبر اکرم (ص):خير دنيا و آخرت با دانش است و شرّ دنيا و آخرت با نادانى.
سرگرمی سبک زندگی سینما و تلویزیون فرهنگ و هنر پزشکی و سلامت اجتماع و خانواده تصویری دین و اندیشه ورزش اقتصادی سیاسی حوادث علم و فناوری سایتهای دانلود گوناگون شرکت ها

تبلیغات

تبلیغات متنی

تریدینگ ویو

لمینت دندان

لیست قیمت گوشی شیائومی

صرافی ارکی چنج

صرافی rkchange

دزدگیر منزل

تشریفات روناک

اجاره سند در شیراز

قیمت فنس

armanekasbokar

armanetejarat

صندوق تضمین

طراحی کاتالوگ فوری

Future Innovate Tech

پی جو مشاغل برتر شیراز

لوله بازکنی تهران

آراد برندینگ

وکیل کرج

خرید تیشرت مردانه

وام لوازم خانگی

نتایج انتخابات ریاست جمهوری

خرید ابزار دقیق

خرید ریبون

موسسه خیریه

خرید سی پی کالاف

واردات از چین

دستگاه تصفیه آب صنعتی

حمية السكري النوع الثاني

ناب مووی

دانلود فیلم

بانک کتاب

دریافت دیه موتورسیکلت از بیمه

خرید نهال سیب سبز

قیمت پنجره دوجداره

بازسازی ساختمان

طراحی سایت تهران سایت

دیوار سبز

irspeedy

درج اگهی ویژه

ماشین سازان

تعمیرات مک بوک

دانلود فیلم هندی

قیمت فرش

درب فریم لس

شات آف ولو

تله بخار

شیر برقی گاز

شیر برقی گاز

خرید کتاب رمان انگلیسی

زانوبند زاپیامکس

بهترین کف کاذب چوبی

پاد یکبار مصرف

روغن بهران بردبار ۳۲۰

قیمت سرور اچ پی

بلیط هواپیما

 






آمار وبسایت

 تعداد کل بازدیدها : 1817440500




هواشناسی

نرخ طلا سکه و  ارز

قیمت خودرو

فال حافظ

تعبیر خواب

فال انبیاء

متن قرآن



اضافه به علاقمنديها ارسال اين مطلب به دوستان آرشيو تمام مطالب
archive  refresh

بازی tic tac toe به زبان c++


واضح آرشیو وب فارسی:پی سی سیتی: بازی tic tac toe به زبان c++

سایت مهدی_جم_پور


سورس و فایل پروژه و فایل exe رو از TicTacToc.zip (http://p30city.net/attachment.php?attachmentid=59&stc=1&d=1229190646) بگیرید



#include <graphics.h> //
#include <stdlib.h> //
#include <string.h> //
#include <stdio.h> //
#include <conio.h> //
#include <dos.h> //
#define n 9 //
//============================================================ ============
struct Node
{
short int Dim[n];
short int Value;
short int Index;
short int Max;
Node *Link[n];
Node *Parent;
};

Node *first,*source;
int depth=0,buttom=0,select;
long maxobject=0,objectcounter=0,search=0;
int selected[n]={0},bestindex,step=0;
int clickdown,clickup,xmouse=320,ymouse=400;
//============================================================ ============
void OpenMouse()
{
asm{
MOV AX,0x01 // { OPEN MOUSE }
INT 0x33

MOV CX,xmouse
MOV DX,ymouse // { SET DEFULT X,Y FOR MOUSE }
MOV AX,0x04
INT 0x33
}
}
//****************************************************
void CloseMouse()
{
asm{
MOV AX,0x03
INT 0x33
MOV xmouse,CX
MOV ymouse,DX

MOV AX,0x02 // { INIT MOUSE }
INT 0x33
}
}
//****************************************************
void TestMouse() //push 1 click
{
asm{
MOV AX,0x03
INT 0x33
MOV clickdown,BX
MOV xmouse,CX
MOV ymouse,DX
}
}
//****************************************************
void TestMouse2() //push 1 click
{
asm{
MOV AX,0x06
INT 0x33
MOV clickup,BX
}
}
//****************************************************
void MouseLimit()
{
asm{
MOV AX,0X07
MOV CX,0
MOV DX,630
INT 0X33

MOV AX,0X08
MOV CX,0
MOV DX,470
INT 0X33
}
}
//****************************************************
int Isinbox(int x1,int y1,int x2,int y2)
{
if ( (xmouse>x1)&&(xmouse<x2) &&(ymouse>y1)&&(ymouse<y2))
return 1;
else return 0;
}
//****************************************************
void DetectVga(void)
{
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s ", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
delay(1000);
}
//****************************************************
void CLS(void)
{
setfillstyle(1,0);
bar(0,0,639,479);
setcolor(9);
rectangle(258,178,382,302);
rectangle(260,180,380,300);
line(260,220,380,220);
line(260,260,380,260);
line(300,180,300,300);
line(340,180,340,300);

setcolor(14); outtextxy(10,10,"Click on Box & try to win...");
setcolor(1); outtextxy(570,10,"jampour");
}
//****************************************************
void tic(int a)
{
int x,y,z;
z=a/3;
a=a%3;
x=280+ a*40;
y=200+ z*40;
CloseMouse();
setcolor(12);
line(x-7,y-7,x+7,y+7);
line(x-7,y+7,x+7,y-7);
OpenMouse();
}
//****************************************************
void tac(int a)
{
int x,y,z;
z=a/3;
a=a%3;
x=280+ a*40;
y=200+ z*40;
CloseMouse();
setcolor(14);
circle(x,y,7);
OpenMouse();
}
//****************************************************
int Status(Node *obj)
{
if(((obj->Dim[0]==-1)&&(obj->Dim[1]==-1)&&(obj->Dim[2]==-1) )
||( (obj->Dim[3]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[5]==-1) )
||( (obj->Dim[6]==-1)&&(obj->Dim[7]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[0]==-1)&&(obj->Dim[3]==-1)&&(obj->Dim[6]==-1) )
||( (obj->Dim[1]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[7]==-1) )
||( (obj->Dim[2]==-1)&&(obj->Dim[5]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[0]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[2]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[6]==-1)))
return -1;
else
if(((obj->Dim[0]==-2)&&(obj->Dim[1]==-2)&&(obj->Dim[2]==-2) )
||( (obj->Dim[3]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[5]==-2) )
||( (obj->Dim[6]==-2)&&(obj->Dim[7]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[0]==-2)&&(obj->Dim[3]==-2)&&(obj->Dim[6]==-2) )
||( (obj->Dim[1]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[7]==-2) )
||( (obj->Dim[2]==-2)&&(obj->Dim[5]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[0]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[2]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[6]==-2)))
return 1;
else
return 0;
}
//****************************************************
void Verify(Node *obj,int depth)
{ int i,max=-128,min=128;
for(i=0;i<n;i++)
{ Node *child=obj->Link[i];
if( (obj->Link[i]!=NULL) && (depth%2==1) && (child->Value > max) )
{
obj->Value=child->Value;
max=child->Value;
obj->Index=i;
}
if( (obj->Link[i]!=NULL) && (depth%2==0) && (child->Value < min) )
{
obj->Value=child->Value;
min=child->Value;
obj->Index=i;
}
}
for(i=0;i<n;i++) //delete used memory
{ Node *child=obj->Link[i];
if(obj->Link[i]!=NULL)
{
obj->Link[i]=NULL;
delete child;
objectcounter--;
}
}
}
//****************************************************
void Test(Node *obj,int depth)
{
if( ( (obj->Dim[0]==-1)&&(obj->Dim[1]==-1)&&(obj->Dim[2]==-1) )
||( (obj->Dim[3]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[5]==-1) )
||( (obj->Dim[6]==-1)&&(obj->Dim[7]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[0]==-1)&&(obj->Dim[3]==-1)&&(obj->Dim[6]==-1) )
||( (obj->Dim[1]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[7]==-1) )
||( (obj->Dim[2]==-1)&&(obj->Dim[5]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[0]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[8]==-1) )
||( (obj->Dim[2]==-1)&&(obj->Dim[4]==-1)&&(obj->Dim[6]==-1) ) )
{ obj->Value=-1*(n+1-depth);
for(int i=0;i<n;i++)
obj->Link[i]=NULL;
}
else
if( ( (obj->Dim[0]==-2)&&(obj->Dim[1]==-2)&&(obj->Dim[2]==-2) )
||( (obj->Dim[3]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[5]==-2) )
||( (obj->Dim[6]==-2)&&(obj->Dim[7]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[0]==-2)&&(obj->Dim[3]==-2)&&(obj->Dim[6]==-2) )
||( (obj->Dim[1]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[7]==-2) )
||( (obj->Dim[2]==-2)&&(obj->Dim[5]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[0]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[8]==-2) )
||( (obj->Dim[2]==-2)&&(obj->Dim[4]==-2)&&(obj->Dim[6]==-2) ) )
{ obj->Value=1*(n+1-depth);
for(int i=0;i<n;i++)
obj->Link[i]=NULL;
}
else obj->Value=0;
}
//****************************************************
void DLS(Node *point,int depth)
{
int i,j,exitcondition,game,next=0;
Node *object;
search++; depth++;

if (maxobject < objectcounter) maxobject=objectcounter;
Test(point,depth);

for(i=0;i<n+1;i++)
{
if (i==n)
Verify(point,depth);
else
if(point->Link[i]!=NULL)
{
if (!(object=new Node))
{ printf(" Erorr! memory is full."); getch(); exit (1);}
objectcounter++;
for(j=0;j<n;j++)
{
object->Dim[j]=point->Dim[j];
object->Link[j]=point->Link[j];
}
object->Value=-96; object->Max=-96;
point->Link[i]=object; object->Parent=point;

if( (depth%2)==0 ) buttom=-1; else buttom=-2;

for(j=next;j<n;j++)
if(!object->Dim[j])
{
object->Dim[j]=buttom;
object->Link[j]= NULL;
next=j+1; break;
}
DLS(point->Link[i],depth);
}//end if
}//end for
}
//****************************************************
void UserSelection()
{
if( (Isinbox(260,180,300,220)) && (!selected[0]) ) // 0
{ tic(0); selected[0]=1; select=1;
first->Dim[0]=-1; first->Link[0]=NULL; depth++;}
else
if( (Isinbox(300,180,340,220)) && (!selected[1]) ) //1
{ tic(1); selected[1]=1; select=1;
first->Dim[1]=-1; first->Link[1]=NULL; depth++; }
else
if( (Isinbox(340,180,380,220)) && (!selected[2]) ) //2
{ tic(2); selected[2]=1; select=1;
first->Dim[2]=-1; first->Link[2]=NULL; depth++; }
else
if( (Isinbox(260,220,300,260)) && (!selected[3]) ) //3
{ tic(3); selected[3]=1; select=1;
first->Dim[3]=-1; first->Link[3]=NULL; depth++; }
else
if( (Isinbox(300,220,340,260)) && (!selected[4]) ) //4
{ tic(4); selected[4]=1; select=1;
first->Dim[4]=-1; first->Link[4]=NULL; depth++; }
else
if( (Isinbox(340,220,380,260)) && (!selected[5]) ) //5
{ tic(5); selected[5]=1; select=1;
first->Dim[5]=-1; first->Link[5]=NULL; depth++; }
else
if( (Isinbox(260,260,300,300)) && (!selected[6]) ) //6
{ tic(6); selected[6]=1; select=1;
first->Dim[6]=-1; first->Link[6]=NULL; depth++; }
else
if( (Isinbox(300,260,340,300)) && (!selected[7]) ) //7
{ tic(7); selected[7]=1; select=1;
first->Dim[7]=-1; first->Link[7]=NULL; depth++; }
else
if( (Isinbox(340,260,380,300)) && (!selected[8]) ) //8
{ tic(8); selected[8]=1; select=1;
first->Dim[8]=-1; first->Link[8]=NULL; depth++; }
}
//****************************************************
void ComputerSelection(int depth)
{
source=new Node;
for(int i=0;i<n;i++)
{
source->Dim[i]=first->Dim[i];
source->Link[i]=first->Link[i];
}
bestindex=0;
DLS(source,depth); bestindex=source->Index;
tac(bestindex); selected[bestindex]=1;

source->Dim[bestindex]=-2; source->Link[bestindex]=NULL;
first->Dim[bestindex]=-2; first->Link[bestindex]=NULL;
gotoxy(1,1); printf(".: Maximum search = %ld :. ",search);
gotoxy(1,2); printf(".: Memory used = %ld Byte :. ",maxobject*(4*n+8));
gotoxy(1,3); printf(".: objcet used = %ld :. ",maxobject);
maxobject=0; search=0;
}
//****************************************************
void main(void)
{
DetectVga(); CLS();
MouseLimit(); OpenMouse();

first=new Node;
for(int i=0;i<9;i++)
{
first->Dim[i]=0;
first->Link[i]=first; //because should Not equal than NULL
}

int game; int depth=0; step=depth/2;
do
{
select=0; TestMouse2(); //for get click up of mouse
if((Isinbox(260,180,380,300))&&(clickup))
{
UserSelection();
step++;
}

game=Status(source);
if( (step>n/2)||(game) )
break;

if( select)
{
ComputerSelection(depth);
clickdown=0; depth+=2;
}
game=Status(source);
if(game) break;

TestMouse(); //for get click down of mouse
}while( (!Isinbox(550,435,630,470)) || (!clickdown) );

setcolor(14); rectangle(10,400,200,470);

if(game==1)
{ setcolor(4); outtextxy(35,420,"<<< You Lose ! >>>"); }
else
if(game==-1)
{ setcolor(10); outtextxy(35,420,"<<< You Win >>>"); }
else
{ setcolor(15); outtextxy(35,420,"<<< Game Equal >>>"); }

setcolor(12); outtextxy(20,450,"Click here to exit.");
do
TestMouse(); //for get click down of mouse
while( (!Isinbox(10,400,200,470)) || (!clickdown) );

CloseMouse();
closegraph();
}

کد بازی دوز (تیک تاک توی) tic tac toe در سی پلاس پلاس C++

دوستان و همکلاسی های عزیز گفتن که نمونه قبلی که گذاشته ام کار نمیکنه....

مد گرافیکی اونرو توی برلند نمیتونین داشته باشین اما اگر نسخه کامپایل شده و اجرایی اونرو

از

TicTacToc.zip (http://p30city.net/attachment.php?attachmentid=59&stc=1&d=1229190646)

دانلود کنید میتونین خروجی رو ببین و با کامپایلر مناسب سورس رو هم خودتون کامپایل کنید نسخه گرافیکی قشنگی هست که آقای جم پور نوشته اند

2 نسخه دیگه رو هم براتون میگذارم که در دات نت میتونین کامپایل کنین
من در مایکروسافت ویژوال سی پلاس پلاس 6 اونرو کامپایل کردم کار کرد...

دانلود کنید :

Basic Tic Tac Toe.zip (http://p30city.net/attachment.php?attachmentid=81&stc=1&d=1241278192)
C++ConsoleLesson9.zip (http://p30city.net/attachment.php?attachmentid=82&stc=1&d=1241278192)






این صفحه را در گوگل محبوب کنید

[ارسال شده از: پی سی سیتی]
[مشاهده در: www.p30city.net]
[تعداد بازديد از اين مطلب: 921]

bt

اضافه شدن مطلب/حذف مطلب




-


گوناگون

پربازدیدترینها
طراحی وب>


صفحه اول | تمام مطالب | RSS | ارتباط با ما
1390© تمامی حقوق این سایت متعلق به سایت واضح می باشد.
این سایت در ستاد ساماندهی وزارت فرهنگ و ارشاد اسلامی ثبت شده است و پیرو قوانین جمهوری اسلامی ایران می باشد. لطفا در صورت برخورد با مطالب و صفحات خلاف قوانین در سایت آن را به ما اطلاع دهید
پایگاه خبری واضح کاری از شرکت طراحی سایت اینتن