Help in tic tac toe

Login to reply to this topic.
Mon, 2008-05-19 07:56
Joined: 2008-05-12
Forum posts: 16

hi ,
m beginner in Symbian and i am developing a game of Tic Tac Toe for Series 60 3rd edition in carbide 1.3.
my movements are working properly but its not checking for the winning
condition.actually I have taken two 2D array one for xpoint "X"&
another for opoint "0".I am doing movement by using xpos and ypos.
I need to check for winning condition .I want to assign the value of
two 2D array ie xpoint[3][3] and opoint[3][3] in one array as
cell[3][3]. Is that possible (as xpoint and ypoint works alternately
and all together they can store only 9 elements) to do so anh how.Can
you guide me for making a tic tac toe game if you do have that game
then plz share that with me.

in AppView:::

_LIT(KText," X ");
_LIT(KText1," 0 ");

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(xpoint[j])
gc.DrawText(KText,TPoint(40+i*35,48+j*30));
if(opoint[j])
gc.DrawText(KText1,TPoint(40+i*35,48+j*30));
}
}

if(flag)
gc.DrawText(KText,TPoint(xpos,ypos));
else
gc.DrawText(KText1,TPoint(xpos,ypos));

gc.UseFont( iCoeEnv->NormalFont() );
if(flag1)
gc.DrawText(_L("Current Player 1"),TPoint(10,160));
else
gc.DrawText(_L("Current Player 2"),TPoint(10,160));

in AppUi

TKeyResponse CToe1AppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
CWindowGc& gc = SystemGc();
TInt validcnt=0;
flag2=1;
_LIT(KText," X ");
_LIT(KText1," 0 ");

if(aType == EEventKeyDown)
{
if(flag2==1)
{
switch(aKeyEvent.iScanCode)
{
case EStdKeyLeftArrow:
if(iAppView->xpos<=40)
iAppView->xpos=110;
else
iAppView->xpos-=35;
break;

case EStdKeyRightArrow:
if(iAppView->xpos>=110)
iAppView->xpos=40;
else
iAppView->xpos+=35;
break;

case EStdKeyUpArrow:
if(iAppView->ypos<=48)
iAppView->ypos=108;
else
iAppView->ypos-=30;
break;

case EStdKeyDownArrow:
if(iAppView->ypos>=108)
iAppView->ypos=48;
else
iAppView->ypos+=30;
break;

case EStdKeyNkpEnter:
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
if((iAppView->xpoint[j]) && (iAppView->opoint[j]))
validcnt++;
}

if(validcnt > 2)
iAppView->valid=EFalse;
else
iAppView->valid=ETrue;

for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
{
if(iAppView->xpos==(40+i*35))
{
if(iAppView->ypos==(48+j*30))
{
if(!iAppView->flag)
{
if(iAppView->valid)
{
if(iAppView->opoint[j])
{
// Cell[j]=iAppView->opoint[j];
iAppView->opoint[j]=EFalse;
if(validcnt>=5)
iAppView->isWinner();
/* if(iAppView->xpoint[0] == iAppView->xpoint[1])
if(iAppView->xpoint[1] == iAppView->xpoint[2])
// if(iAppView->xpos == iAppView->xpos1)
// if(iAppView->xpos1 == iAppView->xpos2)
gc.DrawText(_L("winner Player 1"),TPoint(10,180));*/
}
else
{
// Cell[j]=iAppView->opoint[j];
iAppView->opoint[j]=ETrue;
if(validcnt>=5)
iAppView->isWinner();
/* if(iAppView->xpoint[0] == iAppView->xpoint[1])
if(iAppView->xpoint[1] == iAppView->xpoint[2])
// if(iAppView->xpos == iAppView->xpos1)
// if(iAppView->xpos1 == iAppView->xpos2)
gc.DrawText(_L("winner Player 1"),TPoint(10,180));*/

}
iAppView->flag=ETrue;
iAppView->flag1=EFalse;
}

}
else
{
if(iAppView->valid)
{
if(iAppView->xpoint[j])
{
// Cell[j]=iAppView->xpoint[j];
iAppView->xpoint[j]=EFalse;
if(validcnt>=5)
iAppView->isWinner();
/* // if(iAppView->xpoint[0] == iAppView->xpoint[1])
// if(iAppView->xpoint[1] == iAppView->xpoint[2])
// if(iAppView->xpos == iAppView->xpos1)
// if(iAppView->xpos1 == iAppView->xpos2)
gc.DrawText(_L("winner Player 1"),TPoint(10,180));

*/ }
else
{
// Cell[j]=iAppView->xpoint[j];
iAppView->xpoint[j]=ETrue;
if(validcnt>=5)
iAppView->isWinner();
/* // if(iAppView->xpoint[0] == iAppView->xpoint[1])
// if(iAppView->xpoint[1] == iAppView->xpoint[2])
// if(iAppView->xpos == iAppView->xpos1)
// if(iAppView->xpos1 == iAppView->xpos2)
gc.DrawText(_L("winner Player 1"),TPoint(10,180)); */

}
iAppView->flag=EFalse;
iAppView->flag1=ETrue;
}
}

}
flag2=0;
}

}

break;

}

iAppView->DrawNow();
Reply ASAP. Thanking you

lonely4u4ever@gmail.com

Amrish Singh

  • Login to reply to this topic.