Sunday 21 August 2011

Baan Racing Game


Need a break while working......Try this.

A Racing game developed in baan. 

This game is currently under development, but it is in playable condition.



|******************************************************************************
|* Race
|* Shashank S Shrivastava
|* 25-07-11 [16:53]
|******************************************************************************
|* Script Type: 0
|******************************************************************************

long main.win, menu.win, grap.win, list.win, car.win, fp, CAR.CEN.X, CAR.CEN.Y, ctrl.win, sldr.win
long mode, ply1.win, ply2.win, tick1.win, tick2.win, a, b, c, b1, b2, b3, b4
long arr.X.O(16), cpu.x, cpu.y, points(16,2), color.code, car.pos(4,2), block.x, block.y.1, block.y.2
string filename(100)
domain tcbool player1, lan.started, skip.lines, my.lan.turn
string string.p1(10), string.p2(10), box.filled(100)
string ply1.name(12), ply2.name(30)
string opponent1(30), opponent2(30)
string win.array(4,8)
domain tcbool blocked
domain tcbool game.inprogress
long timer_id, timer_id_1

#define     COMMAND.ABORT      10
#define     COMMAND.EXIT       11
#define     COMMAND.FIRST      20
#define     COMMAND.LAST       21
#define     COMMAND.PREV       22
#define     COMMAND.NEXT       23
#define     GAME.START         24
#define     ABOUT.GAME         25
#define     GAME.HELP          26
#define     GAME.MAX.DIM       300
#define     GAME.DIM           300


function main()
{
CAR.CEN.X = 113
CAR.CEN.Y = 250
main.win = create.object( DsCmwindow, 0,
DsNtitle,         "F1 Racing",
DsNprocessgroup,  get.pgrp(pid),
DsNminWidth,      GAME.MAX.DIM,
DsNmaxWidth,      GAME.MAX.DIM,
DsNminHeight,     GAME.DIM*2+2,
DsNmaxHeight,     GAME.DIM*2+2)
menu.win = create.pulldown.menu(main.win)
change.object( main.win, DsNbarMenu, menu.win )
create.game.window(main.win)
create.control.window(main.win)
update.object(ctrl.win)
update.object(sldr.win)
update.object(grap.win)
make.car.body()
update.object(grap.win)
map.object(grap.win)
raise.object(grap.win)
update.object(main.win)
capture.event()
}

function long create.pulldown.menu(long mwin)
{
long barmenu, size
string menudata(1) based
alloc.mem(menudata, 3000)
size = 1
store.long(1, menudata(size))      | version is 1
size = size + 4
store.long(20, menudata(size))      | menu contains 20 entries
size = size + 4
| create the File submenu
write.menu.entry(menudata, size, 1, 0, "&File", 0)
write.menu.entry(menudata, size, 2, COMMAND.EXIT, "E&xit  Alt+F4", 0)
write.menu.entry(menudata, size, 1, GAME.START, "&Start F1 RACE", 0)
| create the View submenu
write.menu.entry(menudata, size, 1, 0, "&Help", 0)
write.menu.entry(menudata, size, 2, GAME.HELP, "HELP", 0)
write.menu.entry(menudata, size, 2, -1, "-", 0)      | separator
write.menu.entry(menudata, size, 2, ABOUT.GAME, "About Game", 0)
barmenu = create.object(DsCbarMenu, mwin,
DsNmenuData,   menudata, size-1,
DsNsetState,   DSRAISE)
return(barmenu)
}

function write.menu.entry(ref string menudata(), ref long size,
      long level, long id, const string name(), long flags)
{
      store.long(level, menudata(size))
      size = size + 4
      store.long(id, menudata(size))
      size = size + 4
      menudata(size) = name
      size = size + len(name)
      store.byte(0, menudata(size))   | terminate string with 0 char.
      size = size + 1
      store.long(flags, menudata(size))
      size = size + 4
}

function create.game.window(ref long mwin)
{
long x.line, y.line, i
grap.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.DIM*3/4,
DsNheight, GAME.DIM*2-8,
| DsNgridHeight, 10,
| DsNgridWidth, 10,
| DsNgridColor, 6054755,
DsNborderWidth, 5,
DsNeventMask, EVTALLEVENTMASK)
}

function create.control.window(ref long mwin)
{
long x.line, y.line, i
ctrl.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.DIM*1/4-5,
DsNheight, GAME.DIM*2,
DsNx, GAME.DIM*3/4+2,
| DsNy, 10,
| DsNgridColor, 6054755,
DsNeventMask, EVTALLEVENTMASK)
sldr.win = create.object( DsCslider, ctrl.win,
DsNeventMask, EVTKEYPRESS,
DsNincrement, 10,
DsNmaximum, 100,
DsNminimum, 0,
DsNorientation, DSVERTICAL,
DsNpageIncrement, 10,
DsNsliderValue, 0,
DsNwidth, 30,
DsNheight, 400,
DsNx, 20,
DsNy, 10)
}

function make.car.body()
{
long i
i = 1
a = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, CAR.CEN.X-5*1*i,
DsNy, CAR.CEN.Y+5*4*i,
DsNheight, 5*12*i,
DsNwidth, 5*2*i,
DsNgcFillColor, 255)
b = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, CAR.CEN.X-5*3*i,
DsNy, CAR.CEN.Y+5*7*i,
DsNheight, 5*2*i,
DsNwidth, 5*6*i,
DsNgcFillColor, 255)
c = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, CAR.CEN.X-5*3*i,
DsNy, CAR.CEN.Y+5*13*i,
DsNheight, 5*2*i,
DsNwidth, 5*6*i,
DsNgcFillColor, 255)
}

function update.car.position()
{
long i
i = 1
change.sub.object( grap.win, a, 
DsNx, CAR.CEN.X-5*1*i,
DsNy, CAR.CEN.Y+5*4*i)
change.sub.object( grap.win, b, 
DsNx, CAR.CEN.X-5*3*i,
DsNy, CAR.CEN.Y+5*7*i)
change.sub.object( grap.win, c, 
DsNx, CAR.CEN.X-5*3*i,
DsNy, CAR.CEN.Y+5*13*i)
car.pos(1,1) = CAR.CEN.X-5*3*i
car.pos(2,1) = CAR.CEN.X-5*3*i
car.pos(3,1) = CAR.CEN.X-5*3*i + 5*6*i
car.pos(4,1) = CAR.CEN.X-5*3*i + 5*6*i
car.pos(1,2) = CAR.CEN.Y+5*4*i
car.pos(2,2) = CAR.CEN.Y+5*4*i + 5*12*i
car.pos(3,2) = CAR.CEN.Y+5*4*i
car.pos(4,2) = CAR.CEN.Y+5*4*i + 5*12*i
update.object(grap.win)
}

function capture.event()
{
long event(EVTMAXSIZE)
long j, block.id, k
string block.str
domain tcbool acc.deacc
timer_id = set.timer(50)
timer_id_1 = set.timer(100)
block.id = 0
game.inprogress = FALSE
while TRUE
if pending.events() > 0 then
next.event(event)
on case evt.type(event)
case EVTTIMEREVENT:
if game.inprogress then
if (evt.timer.id(event) = timer_id ) then
j = j + 1
if j > 60 then
j = 0
block.str = str$(random()*random())
color.code = random()
if block.str >= "0" and block.str < "3" then
block.id = b1
k = 1
endif
if block.str >= "3" and block.str < "5" then
block.id = b2
k = 2
endif
if block.str >= "5" and block.str < "8" then
block.id = b3
k = 3
endif
if block.str >= "8" and block.str <= "9" then
block.id = b4
k = 4
endif
endif
update.block(block.id, j, k)
endif
endif
if (evt.timer.id(event) = timer_id_1 ) then
acc.deacc = TRUE
endif
break
case EVTBUTTONRELEASE:
break
case EVTKEYPRESS:
on case evt.keypress.key(event)
case KEY_ESC:
| message("Thank You!!")
end()
break
case COMMAND.ABORT:
| message("Thank You!!!!")
end()
break
case 512: |* DOWN
if CAR.CEN.Y < GAME.DIM*2 - 130 then
CAR.CEN.Y = CAR.CEN.Y + 40
else
CAR.CEN.Y = GAME.DIM*2 - 90
endif
update.car.position()
break
case 513: |* UP
if CAR.CEN.Y > -20 then
CAR.CEN.Y = CAR.CEN.Y - 10
endif
update.car.position()
break
case 514: |* LEFT
if CAR.CEN.X > 25 then
CAR.CEN.X = CAR.CEN.X - 15
else
CAR.CEN.X = 15
endif
update.car.position()
break
case 515: |* RIGHT
if CAR.CEN.X < 200 then
CAR.CEN.X = CAR.CEN.X + 15
else
CAR.CEN.X = 210
endif
update.car.position()
break
case 65:
case 97:
if acc.deacc then
change.speed.and.slider(1)
acc.deacc = FALSE
endif
break
case 68:
case 100:
if acc.deacc then
change.speed.and.slider(-1)
acc.deacc = FALSE
endif
endcase
break
case EVTBUTTONSELECT:
if ( evt.button.return(event) = COMMAND.ABORT ) then
return
endif
break
case EVTMENUSELECT:
on case evt.menu.return(event) 
case GAME.START:
create.blocks()
block.id = b1
game.inprogress = TRUE
k = 1
break
endcase
endcase
if game.inprogress then
check.crash(k)
endif
endif
endwhile

}

function create.blocks()
{
|********    *************|1
|     ********************|2
|     *************       |3
|******************       |4
|       ******************|5
| **    ** ** ** ** **  **|6
| ** ** **    ** ** **  **|7
| ** **  ** ** ** **    **|8
|**    ****      ****   **|9
b1 = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, 0,
DsNy, -35,
DsNheight, 30,
DsNwidth, GAME.DIM*3/4 - 30,
DsNgcFillColor, 0)
b2 = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, 25,
DsNy, -35,
DsNheight, 30,
DsNwidth, GAME.DIM*3/4 - 60,
DsNgcFillColor, 0)
b3 = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, 35,
DsNy, -35,
DsNheight, 30,
DsNwidth, GAME.DIM*3/4 - 60,
DsNgcFillColor, 0)
b4 = create.sub.object( grap.win, DsCgpRectangle, 
DsNx, 30,
DsNy, -35,
DsNheight, 30,
DsNwidth, GAME.DIM*3/4 - 30,
DsNgcFillColor, 0)
}

function update.block(long block.id, long i, long j)
{
change.sub.object( grap.win, block.id,
DsNy, 10*i,
DsNgcFillColor, color.code)
on case j
case 1:
block.x = GAME.DIM*3/4 - 30
break
case 2:
block.x = GAME.DIM*3/4 - 35
break
case 3:
block.x = 35
break
case 4:
block.x = 30
break
endcase
block.y.1 = 10*i
block.y.2 = 10*i + 30
update.object(grap.win)
}

| function domain tcbool check.crash(long block.id, long i)
function check.crash(long i)
{
if block.y.2 >= car.pos(1,2) and block.y.1 <= car.pos(2,2) and car.pos(3,1) <> 0 then
on case i
case 1:
block.x = GAME.DIM*3/4 - 30
if car.pos(1,1) < GAME.DIM*3/4 - 30 then
game.inprogress = FALSE
message("Crash!!!")
set.mem(car.pos, 0)
block.x = 0
block.y.1 = 0
block.y.2 = 0
destroy.sub.object(grap.win, b1)
destroy.sub.object(grap.win, b2)
destroy.sub.object(grap.win, b3)
destroy.sub.object(grap.win, b4)
endif
break
case 2:
block.x = GAME.DIM*3/4 - 35
if car.pos(1,1) < GAME.DIM*3/4 - 35 then
game.inprogress = FALSE
message("Crash!!!")
set.mem(car.pos, 0)
block.x = 0
block.y.1 = 0
block.y.2 = 0
destroy.sub.object(grap.win, b1)
destroy.sub.object(grap.win, b2)
destroy.sub.object(grap.win, b3)
destroy.sub.object(grap.win, b4)
endif
break
case 3:
block.x = 35
if car.pos(3,1) > 35 then
game.inprogress = FALSE
message("Crash!!!")
set.mem(car.pos, 0)
block.x = 0
block.y.1 = 0
block.y.2 = 0
destroy.sub.object(grap.win, b1)
destroy.sub.object(grap.win, b2)
destroy.sub.object(grap.win, b3)
destroy.sub.object(grap.win, b4)
endif
break
case 4:
block.x = 30
if car.pos(3,1) > 30 then
game.inprogress = FALSE
message("Crash!!!")
set.mem(car.pos, 0)
block.x = 0
block.y.1 = 0
block.y.2 = 0
destroy.sub.object(grap.win, b1)
destroy.sub.object(grap.win, b2)
destroy.sub.object(grap.win, b3)
destroy.sub.object(grap.win, b4)
endif
break
endcase
endif
}

function change.speed.and.slider(long mode)
{
long sldr.val
get.object(sldr.win,  DsNsliderValue, sldr.val)
change.object(sldr.win,  DsNsliderValue, sldr.val + 10*mode)
update.object(sldr.win)
kill.timer(timer_id)
if (50 - (sldr.val + 40*mode)/10 ) < 10 then
timer_id = set.timer(10)
return
endif
if (50 - (sldr.val + 40*mode)/10 ) > 50 then
timer_id = set.timer(50)
return
endif
timer_id = set.timer(50 - (sldr.val + 40*mode)/10)
}





:) Just copy and run as 3gl and enjoy!!!!!!!

Auto Increment logic

Many times we face the challenge to develop a logic for auto incremental of a field and achieve it by doing many permutations and combinations.


Here is my attempt to build a common logic.


Before going to the logic we should have the knowledge of following variables:-


1) filled.occ   (It is number of filled occurrences or the count of records displayed on a form at a time.) 
2) actual.occ (It is the occurrence number currently selected on form.)


The Code.



extern domain tcsrnb temp.seqn, new.seqn1, new.seqn2

choice.add.set:
before.choice:
temp.seqn = 0
new.seqn1 = get.next.seqn() - 1
new.seqn2 = filled.occ



field.<FieldName>:
before.input:
if filled.occ = 1 then
temp.seqn = 0
new.seqn1 = get.next.seqn() - 1
new.seqn2 = filled.occ - 1
endif

<FieldName> = new.seqn1 + actual.occ - new.seqn2


function domain tcsrnb get.next.seqn()
{
if temp.seqn = 0 then
select max sequence of field
from         table
where Condition
selectdo
temp.seqn = (max sequence of field) + 1
return(temp.seqn)
endselect
temp.seqn = 1
return(1)
else
if <FieldValue> <> 0 then
return(<FieldValue>)
else
temp.seqn = temp.seqn + 1
return(temp.seqn)
endif
endif
}





:) Just do these and enjoy!!!!!!!

Monday 15 August 2011

First Line meaning of .bpf file


Baan provides the client based utility called BWPRINT.EXE for printing and which makes use of file having extension as .bpf.

When the files viewed using this and saved (as .bpf) and then opened as a normal text file. We see first line of the text similar to this:

@ -p "" -c 1 -f      1 -t 999999 -l  48 -m   0 -L ISO-8859-1 -a      1 -r reportname -w 120 -d P -a 1 -B "WIN"@

What this line represents?


-p is for printing device

-c is for font name as per registry

-f & -t means from - to page

-l is for lines per page

-m is for left margin

-L is for character set

-r is for report name

-w is for paper width

-d is fopr Orientation (Landscape  L or Portrait P)

-a is for number of copies

-B is for baan device name


Using this we can make our own bwprint file having the features we need. Like no. of lines per page, paper orientation, left margin, top margin....etc


:) Just do these and enjoy!!!!!!!

Baan Function with variable number of arguments.

Baan provides the mechanism to define functions with variable number of arguments in two basic ways.


a) Max argument count is fixed.

The syntax for it is as follows.


function_name(long arg1, [long arg2], [long arg3])


This function defined as above can be called in 3 ways
1) function_name(val1)
2) function_name(val1, val2)
3) function_name(val1, val2, val3)


Usage:
function sample(long arg1, [long arg2], [long arg3])
{
        long val2, val3

        val2 = get.long.arg(2)
        val3 = get.long.arg(3)
        ......
        ......
}



b) Argument count is not fixed.

The syntax for it is as follows.


function_name(long arg1, ... )


This function defined as above can be called in 3 ways
1) function_name(val1)
2) function_name(val1, val2)
.....
.....
.....
n) function_name(val1, val2, ......., valn)


Usage:
function sample(long arg1, ... )
{
        long long_value
        dounble double_value
        string string_value

        for i = 2 to get.argc()
                on case get.arg.type(i)
                case DB.LONG:
                        long_value = get.long.arg(i)
                        ......
                        break
                        case DB.DOUBLE:
                        double_value = get.double.arg(i)
                        ......
                        break
                        default:
                        string_value = get.string.arg(i)
                         ......
                        break
                endcase
        endfor
}


:) Just do these and enjoy!!!!!!!

Monday 27 June 2011

Baan Tic-Tac-Toe Game


Need a break while working......Try this.

A Tic-Tac-Toe game developed in baan. It has basically two mode:-
i) Two player mode(Game between two players on same bshell and pid, by sharing the control).
ii) Lan mode(Game between two players on different bshell).

"For Lan Play just create a directory as tictac in $BSE/tmp"


This game is currently under development, but it is in playable condition.


|******************************************************************************
|* Tic Tac Toe game
|* Shashank. S. Shrivastava
|* 23-06-11 [09:07]
|******************************************************************************
|* Script Type: 3gl
|******************************************************************************
long main.win, menu.win, grap.win, list.win, ctrl.win, fp
long mode, ply1.win, ply2.win, tick1.win, tick2.win
long arr.X.O(16), cpu.x, cpu.y
string filename(100)
domain tcbool player1, lan.started, skip.lines, my.lan.turn
string string.p1(10), string.p2(10), box.filled(100)
string ply1.name(12), ply2.name(30)
string opponent1(30), opponent2(30)
string win.array(4,8)
domain tcbool blocked

#define COMMAND.ABORT 10
#define COMMAND.EXIT 11
#define COMMAND.FIRST 20
#define COMMAND.LAST 21
#define COMMAND.PREV 22
#define COMMAND.NEXT 23
#define GAME.START 24
#define ABOUT.GAME 25
#define GAME.HELP 26
#define TWO.PLAYER 27
#define CPU.VS.PLAYER 28
#define LAN.PLAY 29
#define LAN.PLAY.INIT 30
#define LAN.PLAY.JOIN 31
#define GAME.DIM 300
#define GAME.MAX.DIM 450
#pragma used dll ottdllbw
#pragma used dll ottdllinputstr
function main()
{
win.array(1,1) = "123"
win.array(1,2) = "456"
win.array(1,3) = "789"
win.array(1,4) = "147"
win.array(1,5) = "258"
win.array(1,6) = "369"
win.array(1,7) = "159"
win.array(1,8) = "357"

main.win = create.object( DsCmwindow, 0,
DsNtitle, "TIC-TAC-TAO",
DsNprocessgroup, get.pgrp(pid),
DsNminWidth, GAME.MAX.DIM,
DsNmaxWidth, GAME.MAX.DIM,
DsNminHeight, GAME.DIM+2,
DsNmaxHeight, GAME.DIM+2)
menu.win = create.pulldown.menu(main.win)
change.object( main.win, DsNbarMenu, menu.win )
create.game.control.window(main.win)
create.game.window(main.win)
update.object(grap.win)
update.object(main.win)
capture.event()
}
function create.game.control.window(long mwin)
{
ctrl.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.MAX.DIM-GAME.DIM-10,
DsNheight, GAME.DIM/4,
DsNx, GAME.DIM+5,
DsNy, 0,
DsNborderWidth, 2)
ply1.win = create.sub.object(ctrl.win, DsCgpText ,
DsNx, (GAME.MAX.DIM-GAME.DIM-10)/3,
DsNy, (GAME.DIM/4)/3,
DsNwidth, 80,
DsNgcForeground, 44800)
ply2.win = create.sub.object(ctrl.win, DsCgpText ,
DsNx, (GAME.MAX.DIM-GAME.DIM-10)/3,
DsNy, (GAME.DIM/4)*2/3,
DsNwidth, 80,
DsNgcForeground, RGB.BLACK)
update.object(ctrl.win)
}
function create.current.ply.mark(long mwin, double y, string name1(20), string name2(20) )
{
if mode = 1 or mode = 2 then
tt.user(name1, name1)
tt.user(name2, name2)
endif
tick1.win = create.sub.object (mwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, (GAME.MAX.DIM-GAME.DIM-10)/9,
DsNxn, (GAME.MAX.DIM-GAME.DIM-10)/8,
DsNyo, (GAME.DIM/4)/y-5,
DsNyn, (GAME.DIM/4)/y+1,
DsNgcForeground, 44800)
tick2.win = create.sub.object (mwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, (GAME.MAX.DIM-GAME.DIM-10)/8,
DsNxn, (GAME.MAX.DIM-GAME.DIM-10)/6,
DsNyo, (GAME.DIM/4)/y+1,
DsNyn, (GAME.DIM/4)/y-10,
DsNgcForeground, 44800)
change.sub.object(ctrl.win, ply1.win ,
DsNstring, name1,
DsNgcForeground, ((y=3.0)?44800 : RGB.BLACK))
change.sub.object(ctrl.win, ply2.win ,
DsNstring, name2,
DsNgcForeground, ((y=1.5)?44800 : RGB.BLACK))
}
function long create.pulldown.menu(long mwin)
{
long barmenu, size
string menudata(1) based
alloc.mem(menudata, 3000)
size = 1
store.long(1, menudata(size)) | version is 1
size = size + 4
store.long(20, menudata(size)) | menu contains 20 entries
size = size + 4
| create the File submenu
write.menu.entry(menudata, size, 1, 0, "&File", 0)
write.menu.entry(menudata, size, 2, COMMAND.EXIT, "E&xit Alt+F4", 0)

write.menu.entry(menudata, size, 1, 0, "&Start Game", 0)
write.menu.entry(menudata, size, 2, TWO.PLAYER, "&Two Player Game", 0)
write.menu.entry(menudata, size, 2, CPU.VS.PLAYER, "&Player vs CPU", 0)
write.menu.entry(menudata, size, 2, LAN.PLAY.INIT, "&Initiate LAN Play", 0)
write.menu.entry(menudata, size, 2, LAN.PLAY.JOIN, "&Join LAN Play", 0)

| create the View submenu
write.menu.entry(menudata, size, 1, 0, "&Help", 0)
write.menu.entry(menudata, size, 2, GAME.HELP, "HELP", 0)
write.menu.entry(menudata, size, 2, -1, "-", 0) | separator
write.menu.entry(menudata, size, 2, ABOUT.GAME, "About Game", 0)
barmenu = create.object(DsCbarMenu, mwin,
DsNmenuData, menudata, size-1,
DsNsetState, DSRAISE)
return(barmenu)
}
function write.menu.entry(ref string menudata(), ref long size,
long level, long id, const string name(), long flags)
{
store.long(level, menudata(size))
size = size + 4
store.long(id, menudata(size))
size = size + 4
menudata(size) = name
size = size + len(name)
store.byte(0, menudata(size)) | terminate string with 0 char.
size = size + 1
store.long(flags, menudata(size))
size = size + 4
}
function create.game.window(ref long mwin)
{
long x.line, y.line, i
grap.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.DIM,
DsNheight, GAME.DIM,
DsNgridHeight, 10,
DsNgridWidth, 10,
DsNgridColor, 6054755,
DsNeventMask, EVTALLEVENTMASK)
for i = 1 to 2
x.line = create.sub.object (grap.win, DsCgpLine,
DsNgcLineWidth, 2,
DsNxo, (GAME.DIM/3)*i,
DsNxn, (GAME.DIM/3)*i,
DsNyo, 0,
DsNyn, GAME.DIM)
y.line = create.sub.object (grap.win, DsCgpLine,
DsNgcLineWidth, 2,
DsNxo, 0,
DsNxn, GAME.DIM,
DsNyo, (GAME.DIM/3)*i,
DsNyn, (GAME.DIM/3)*i)
endfor

}
function create.O(ref long gwin, long x, long y)
{
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpArc,
DsNangle, 0,
DsNgcLineWidth, 3,
DsNheight, 70,
DsNwidth, 70,
DsNx, x-36,
DsNy, y-36,
DsNrotation, 360,
DsNgcForeground, 7433637)
}
function create.X(ref long gwin, long x, long y)
{
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, x-35,
DsNxn, x+35,
DsNyo, y-35,
DsNyn, y+35,
DsNgcForeground, 255)
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, x-35,
DsNxn, x+35,
DsNyo, y+35,
DsNyn, y-35,
DsNgcForeground, 255)
}
function capture.event()
{
long event(EVTMAXSIZE)
long timer_id
string.p1 = ""
string.p2 = ""
player1 = TRUE
box.filled = ""
mode = -1
while TRUE
if pending.events() > 0 then
next.event(event)
on case evt.type(event)
case EVTBUTTONRELEASE:
if my.lan.turn or mode = 0 or mode = 3 then
on case evt.button.button( event )
case EVTBUTTON1:
game.play(get.x.value(evt.button.x( event )),
get.y.value(evt.button.y( event )))
if mode = 3 then
player1 = FALSE
player.vs.computer()
game.play(cpu.x, cpu.y)
player1 = TRUE
endif
break
endcase
endif
| if evt.button.return(event) = ABORT.BUTTON then
| end()
| endif
break
case EVTKEYPRESS:
on case evt.keypress.key(event)
case KEY_ESC:
| message("Thank You!!")
end()
break
case COMMAND.ABORT:
| message("Thank You!!!!")
end()
break
case 55:
game.play(50,50)
break
case 56:
game.play(150,50)
break
case 57:
game.play(250,50)
break
case 52:
game.play(50,150)
break
case 53:
game.play(150,150)
break
case 54:
game.play(250,150)
break
case 49:
game.play(50,250)
break
case 50:
game.play(150,250)
break
case 51:
game.play(250,250)
break
endcase
break
case EVTBUTTONSELECT:
if ( evt.button.return(event) = COMMAND.ABORT ) then
return
endif
break
case EVTMENUSELECT:
on case evt.menu.return(event)
case TWO.PLAYER:
mode = 0
box.filled = ""
string.p1 = ""
string.p2 = ""
player1 = TRUE
refresh.game.window()
break
case CPU.VS.PLAYER:
mode = 3
box.filled = ""
string.p1 = ""
string.p2 = ""
player1 = TRUE
refresh.game.window()
break
case LAN.PLAY.INIT:
mode = 1
skip.lines = 0
lan.started = FALSE
refresh.game.window()
filename = strip$(bse.tmp.dir$())&"/tictac/"&dte$()&"."&logname$
fp = seq.open(filename, "w+")
seq.puts("1", fp)
seq.close(fp)
invite.a.player()
break
case LAN.PLAY.JOIN:
mode = 2
skip.lines = 0
refresh.game.window()
search.game()
break
case GAME.HELP:
message("HE HE TIC-TAC-TAO KHELNA NAHI AATA\n Ha hA He hE....\nClick ok for Googglliinngg")
app_start( "iexplore.exe http://en.wikipedia.org/wiki/Tic-tac-toe", "", "", "", "" )
break
case ABOUT.GAME:
message("MADE BY SHASHNAK S S")
break
case COMMAND.EXIT:
| message("Thank You!!")
end()

endcase
endcase
if mode = 1 or mode = 2 then
read.lan.file(filename)
endif
else
if mode = 1 or mode = 2 then
read.lan.file(filename)
endif
endif
endwhile
}
function long get.y.value(long y)
{
long temp.val
temp.val = (y/100)
on case temp.val
case 0:
y = (50)
break
case 1:
y = (150)
break
case 2:
y = (250)
endcase
return(y)
}
function long get.x.value(long x)
{
long temp.val
temp.val = (x/100)
on case temp.val
case 0:
x = (50)
break
case 1:
x = (150)
break
case 2:
x = (250)
endcase
return(x)
}
function get.index(long x, long y)
{
long index
on case str$(x)&str$(y)
case "5050":
index = 1
break
case "15050":
index = 2
break
case "25050":
index = 3
break
case "50150":
index = 4
break
case "150150":
index = 5
break
case "250150":
index = 6
break
case "50250":
index = 7
break
case "150250":
index = 8
break
case "250250":
index = 9
break
endcase
if player1 then
string.p1 = string.p1&str$(index)
else
string.p2 = string.p2&str$(index)
endif
}
function domain tcbool check.win(string text(10))
{
if pos(text, "1") > 0 and pos(text, "2") > 0 and pos(text, "3") > 0 then
return(TRUE)
endif
if pos(text, "4") > 0 and pos(text, "5") > 0 and pos(text, "6") > 0 then
return(TRUE)
endif
if pos(text, "7") > 0 and pos(text, "8") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "1") > 0 and pos(text, "4") > 0 and pos(text, "7") > 0 then
return(TRUE)
endif
if pos(text, "2") > 0 and pos(text, "5") > 0 and pos(text, "8") > 0 then
return(TRUE)
endif
if pos(text, "3") > 0 and pos(text, "6") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "1") > 0 and pos(text, "5") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "3") > 0 and pos(text, "5") > 0 and pos(text, "7") > 0 then
return(TRUE)
endif
return(FALSE)
}
function game.play(long x, long y)
{
long file.id

if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if pos(box.filled, ","&str$(x)&str$(y)&",") = 0 then
get.index(x, y)
if mode = 0 then
if player1 then
create.X(grap.win, x,y)
else
create.O(grap.win, x,y)
endif
endif
if mode = 3 then
if player1 then
create.X(grap.win, x,y)
else
create.O(grap.win, x,y)
endif
endif
if mode = 1 then
create.X(grap.win, x,y)
endif
if mode = 2 then
create.O(grap.win, x,y)
endif
update.object(grap.win)
box.filled = box.filled&","&str$(x)&str$(y)&","
if mode = 1 or mode = 2 then
file.id = seq.open(filename, "a+")
seq.puts(str$(x)&"."&str$(y), file.id)
seq.close(file.id)
endif
if player1 then
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif
player1 = FALSE
else
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif

player1 = TRUE
endif
update.game.status()
else
Message("Not allowed")
endif
endif
endif
}
function search.game()
{
long dir.id, file.id, a
string game.filename(200), value(10)
dir.id = dir.open(strip$(bse.tmp.dir$())&"/tictac/")
if dir.id <= 0 then message("Unable to find tic-tac-tao network") endif repeat game.filename = dir.entry( dir.id, TFILE, a, a, a ) if not isspace(game.filename) then file.id = seq.open(strip$(bse.tmp.dir$())&"/tictac/"&game.filename, "r") if file.id < 1 then else seq.gets(value, 1024, file.id) if strip$(value) = "1" then if pos(game.filename, ".") > 0 then
opponent1 = logname$
opponent2 = game.filename(pos(game.filename, ".")+1)
if ask.enum("tcgenquest", tcyesno.yes, "Request to play with "&opponent2) = tcyesno.yes then
seq.close(file.id)
file.id = seq.open(strip$(bse.tmp.dir$())&"/tictac/"&game.filename, "w+")
seq.puts("2", file.id)
seq.puts(logname$, file.id)
seq.close(file.id)
filename = strip$(bse.tmp.dir$())&"/tictac/"&game.filename
skip.lines = 1
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
endif
create.current.ply.mark(ctrl.win, 1.5, opponent1, opponent2)
update.object(ctrl.win)
endif
endif
endif
endif
seq.close(file.id)
value = "0"
endif
until (isspace(game.filename))
}
function read.lan.file(string game.filename(100))
{
long lan.file.id, i
string value(20)

lan.file.id = seq.open(game.filename, "r")
if lan.file.id < 1 then message("Disconnected from partner") mode = -1 refresh.game.window() else seq.gets(value, 1024, lan.file.id) if mode = 1 then if strip$(value) = "2" and skip.lines < 2 then seq.gets(value, 1024, lan.file.id) if ask.enum("tcgenquest", tcyesno.yes, "Approve request of "&value&" to play.") = tcyesno.yes then opponent1 = logname$ opponent2 = value | destroy.object(ctrl.win) destroy.sub.object(ctrl.win, tick1.win) destroy.sub.object(ctrl.win, tick2.win) create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2) update.object(ctrl.win) lan.started = TRUE skip.lines = 2 my.lan.turn = TRUE endif player1 = TRUE else if skip.lines >= 2 then
for i = 1 to skip.lines
seq.gets(value, 1024, lan.file.id)
endfor
if seq.gets(value, 1024, lan.file.id) = 0 then
my.lan.turn = TRUE
skip.lines = skip.lines + 2
if pos(value,".") <> 0 then
player1 = FALSE
get.index(lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
create.O(grap.win, lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
box.filled = box.filled&","&str$(lval(value(1;pos(value,".")-1)))&str$(lval(value(pos(value,".")+1)))&","
update.object(grap.win)
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
endif
update.object(ctrl.win)
endif
player1 = TRUE
endif
endif
endif
else
for i = 1 to skip.lines
seq.gets(value, 1024, lan.file.id)
endfor
if seq.gets(value, 1024, lan.file.id) = 0 then
my.lan.turn = TRUE
skip.lines = skip.lines + 2
if pos(value,".") <> 0 then
player1 = TRUE
get.index(lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
create.X(grap.win, lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
box.filled = box.filled&","&str$(lval(value(1;pos(value,".")-1)))&str$(lval(value(pos(value,".")+1)))&","
update.object(grap.win)
player1 = FALSE
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
update.object(ctrl.win)
endif
endif
endif
endif
endif
seq.close(lan.file.id)
value = "0"
}
function refresh.game.window()
{
long i
if mode = 1 then
shell("mkdir "&strip$(bse.tmp.dir$())&"/tictac/", 0)
shell("rm "&strip$(bse.tmp.dir$())&"/tictac/*."&logname$, 0)
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
endif
box.filled = ""
string.p1 = ""
string.p2 = ""
opponent1 = ""
opponent2 = ""
player1 = TRUE
my.lan.turn = FALSE
tick1.win = 0
tick2.win = 0
if mode = 0 then
opponent1 = "Player 1"
opponent2 = "Player 2"
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
if mode = 3 then
tt.user(logname$, opponent1)
opponent2 = "CPU"
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
if mode = 1 or mode = 2 then
opponent1 = logname$
opponent2 = ""
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
for i = 2 to arr.X.O(1)
destroy.sub.object(grap.win, arr.X.O(i))
endfor
set.mem(arr.X.O, 0)
arr.X.O(1) = 1
update.object(grap.win)
update.object(ctrl.win)
}
function update.game.status()
{
if mode = 0 or mode = 1 or mode = 2 or mode = 3 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if mode = 1 or mode = 2 then
my.lan.turn = FALSE
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
else
if player1 then
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, 1.5, opponent1, opponent2)
endif
endif
update.object(ctrl.win)
endif
}
function player.vs.computer()
{
blocked = FALSE
on case len(string.p1)
case 1:
if pos(string.p1, "1") > 0 or pos(string.p1, "3") > 0 or pos(string.p1, "7") > 0 or pos(string.p1, "9") > 0 then
read.cpu.x.y("5")
endif
if pos(string.p1, "5") > 0 then
read.cpu.x.y("1")
endif
if pos(string.p1, "2") > 0 or pos(string.p1, "4") > 0 or pos(string.p1, "6") > 0 or pos(string.p1, "8") > 0 then
read.cpu.x.y("5")
endif
break
case 2:
check.for.2(string.p1, string.p2)
if not blocked then
if string.p1(1;1) = "1" or string.p1(1;1) = "3" or string.p1(1;1) = "9" or string.p1(1;1) = "7" then
if string.p1(2;1) = "9" or string.p1(2;1) = "7" or string.p1(2;1) = "3" or string.p1(2;1) = "1" then
read.cpu.x.y("2")
blocked = TRUE
endif
if string.p1(2;1) = "6" or string.p1(2;1) = "4" then
read.cpu.x.y("2")
blocked = TRUE
endif
if string.p1(2;1) = "8" or string.p1(2;1) = "2" then
read.cpu.x.y("6")
blocked = TRUE
endif
else
if string.p1(1;1) = "4" or string.p1(1;1) = "6" then
if string.p1(2;1) = "9" or string.p1(2;1) = "7" then
read.cpu.x.y("8")
blocked = TRUE
endif
if string.p1(2;1) = "3" or string.p1(2;1) = "1" then
read.cpu.x.y("2")
blocked = TRUE
endif
endif
if string.p1(1;1) = "2" or string.p1(1;1) = "8" then
if string.p1(2;1) = "9" or string.p1(2;1) = "3" then
read.cpu.x.y("6")
blocked = TRUE
endif
if string.p1(2;1) = "7" or string.p1(2;1) = "1" then
read.cpu.x.y("4")
blocked = TRUE
endif
endif
if not blocked then
fill.for.2()
endif
if not blocked then
check.for.2(string.p2, string.p1)
endif
endif
endif
break
case 3:
check.for.2(string.p1, string.p2)
if not blocked then
check.for.2(string.p2, string.p1)
endif
if not blocked then
fill.for.2()
endif
break
case 4:
check.for.2(string.p1, string.p2)
if not blocked then
check.for.2(string.p2, string.p1)
endif
if not blocked then
fill.for.2()
endif
break
endcase
}
function check.for.2(string local.string1(10), string local.string2(10))
{
long local.i
string temp.win.array(4)
for local.i = 1 to 8
temp.win.array = win.array(1,local.i)
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(1;1),
temp.win.array(2;1),
temp.win.array(3;1)) then
return
endif
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(2;1),
temp.win.array(3;1),
temp.win.array(1;1)) then
return
endif
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(1;1),
temp.win.array(3;1),
temp.win.array(2;1)) then
return
endif
endfor

if len(local.string1) < len(local.string2) then for local.i = 1 to 8 temp.win.array = win.array(1,local.i) if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(1;1), temp.win.array(2;1), temp.win.array(3;1)) then return endif if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(2;1), temp.win.array(3;1), temp.win.array(1;1)) then return endif if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(1;1), temp.win.array(3;1), temp.win.array(2;1)) then return endif endfor endif } function long read.index(long x, long y) { long index on case str$(x)&str$(y) case "5050": index = 1 break case "15050": index = 2 break case "25050": index = 3 break case "50150": index = 4 break case "150150": index = 5 break case "250150": index = 6 break case "50250": index = 7 break case "150250": index = 8 break case "250250": index = 9 break endcase return(index) } function fill.for.2() { if pos(string.p1, "2") > 0 and pos(string.p1, "4") > 0 then
read.cpu.x.y("1")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "4") > 0 and pos(string.p1, "8") > 0 then
read.cpu.x.y("7")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "6") > 0 and pos(string.p1, "8") > 0 then
read.cpu.x.y("9")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "2") > 0 and pos(string.p1, "6") > 0 then
read.cpu.x.y("3")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif } function invite.a.player() { string login.id(16), command.string(100) if ask.enum("tcgenquest", tcyesno.yes, "Invite Specific person to play") = tcyesno.yes then input.string("Invite Person by Baan Login ID", "Baan Login ID", 16, 16, login.id) command.string = "bshcmd6.1 -u1 -w1 -M ""Hello"" `ps -eaf | grep bshell | grep "&login.id &" | awk '{ print $2 }'`" shell(command.string , 64) endif } function domain tcbool find.block.pos.for.cpu(string local.string1(10), string local.string2(10), string a(1), string b(1), string c(1)) { if pos(local.string1, a) > 0 and pos(local.string1, b) > 0 then
read.cpu.x.y(c)
if pos(local.string2, c) < 1 then blocked = TRUE return(TRUE) endif endif return(FALSE) } function domain tcbool find.win.pos.for.cpu(string local.string1(10), string local.string2(10), string a(1), string b(1), string c(1)) { if pos(local.string2, a) < 1 and pos(local.string2, b) < 1 and pos(local.string2, c) < 1 then if pos(local.string1, a) > 0 or pos(local.string1, b) > 0 or pos(local.string1, c) > 0 then
if pos(local.string1, a) < 1 then read.cpu.x.y(a) blocked = TRUE return(TRUE) endif if pos(local.string1, b) < 1 then read.cpu.x.y(b) blocked = TRUE return(TRUE) endif if pos(local.string1, c) < 1 then read.cpu.x.y(c) blocked = TRUE return(TRUE) endif endif endif return(FALSE) } function read.cpu.x.y(string c(1)) { on case lval(c) case 1: cpu.x = 50 cpu.y = 50 break case 2: cpu.x = 150 cpu.y = 50 break case 3: cpu.x = 250 cpu.y = 50 break case 4: cpu.x = 50 cpu.y = 150 break case 5: cpu.x = 150 cpu.y = 150 break case 6: cpu.x = 250 cpu.y = 150 break case 7: cpu.x = 50 cpu.y = 250 break case 8: cpu.x = 150 cpu.y = 250 break case 9: cpu.x = 250 cpu.y = 250 break endcase }



:) Just copy and run as 3gl and enjoy!!!!!!!