home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
TicTacToe_Computer.sru
< prev
next >
Wrap
Text File
|
1997-09-30
|
3KB
|
146 lines
$PBExportHeader$tictactoe_computer.sru
$PBExportComments$Generated by ObjectTeam
forward
global type tictactoe_computer from nonvisualobject
end type
end forward
shared variables
// User defined attributes
// Non modeled user defined attributes
end variables
global type tictactoe_computer from nonvisualobject
end type
global tictactoe_computer tictactoe_computer
type variables
// User defined attributes
string id = ''
// Association attributes
private tictactoe_game game
public tictactoe_gui gui
// Non modeled user defined attributes
// Control to class mappings
// tictactoe_computer --> TicTacToe_Computer
end variables
forward prototypes
public subroutine checkTurn ()
public subroutine selectCell ()
public function integer getMaxValue (integer x)
public subroutine setGame (tictactoe_game newGame)
public function tictactoe_game getGame ()
public subroutine removeGui ()
public subroutine setGui (tictactoe_gui newGui)
public function tictactoe_gui getGui ()
end prototypes
public subroutine checkTurn ();//
IF (id = (game.getactiveplayer())) THEN
selectCell()
END IF
end subroutine
public subroutine selectCell ();//
integer i, temp
integer maxI = 0
integer selection = -1
tictactoe_cell cell
FOR i = 1 TO 9
cell = game.getboard(i)
IF cell.contents = ' ' THEN
temp = getMaxValue(i)
IF ((maxI < temp) OR (selection = -1)) THEN
maxI = temp
selection = i
END IF
END IF
NEXT
IF (selection <> -1) THEN
gui.cellButtonClick(selection)
END IF
end subroutine
public function integer getMaxValue (integer x);//
integer i, temp
integer retValue = -1
tictactoe_cell cell
cell = game.getboard(x)
FOR i = 1 TO Len(game.players)
cell.contents = Mid(game.players, i, 1)
temp = cell.getMaxLine()
IF ((retValue < temp) OR (retValue = -1)) THEN
retValue = temp
END IF
NEXT
cell.contents = ' '
return retValue
end function
public subroutine setGame (tictactoe_game newGame);// Association accessor method
if isNull(newGame) then
return
end if
game = newGame
end subroutine
public function tictactoe_game getGame ();// Association accessor method
return game
end function
public subroutine removeGui ();// Association accessor method
if not isNull(gui) then
setNull(gui.computer)
end if
setNull(gui)
end subroutine
public subroutine setGui (tictactoe_gui newGui);// Association accessor method
if not isNull(gui) then
setNull(gui.computer)
end if
if not isNull(newGui) then
TicTacToe_Computer nullRef
setNull(nullRef)
newGui.setComputer(nullRef)
newGui.computer = this
end if
gui = newGui
end subroutine
public function tictactoe_gui getGui ();// Association accessor method
return gui
end function
on tictactoe_computer.create
TriggerEvent( this, "constructor" )
end on
on tictactoe_computer.destroy
TriggerEvent( this, "destructor" )
end on
event constructor;setNull(game)
setNull(gui)
// Start user code section
// End user code section
end event
event destructor;// Start user code section
// End user code section
setNull(game)
if not isNull(gui) then
setNull(gui.computer)
end if
setNull(gui)
end event