Example Aurora Program


//keno example program for Aurora
//Green = selected, yellow = miss, red = hit
//the balls are represented in an integer array
//values for the array are:
//0 = not selected, 1 = selected, 2 = hit, 3 = miss
//Compile as a WINDOWS target
#autodefine "off"

int run;
int selected,hit,miss,playing;

class kenowin:window
{

//overridden virtual methods
declare OnClose(),int;
declare OnCreate(),int;
declare OnPaint(),int;
declare OnLButtonDown(int x,int y, int flags),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare OnChar(unsigned int nChar,INT nRepCnt),int;
declare OnTimer(int nIDEvent),int;
//other methods
declare DrawBalls();
declare SelectBall(int mx,int my);
declare StartPlay();
declare EndPlay();
declare ClearBoard();
declare PickBall();
//class variables
int balls[80];
int hitcount,selectcount,picked;

}

global sub main()
{
kenowin playwin;
CButton startbtn;
CButton clearbtn;


//The balls colors
selected = RGB(0,255,0);
hit = RGB(255,0,0);
miss = RGB(255,255,0);

//the play window
playwin.Create(0,0,410,400,AWS_VISIBLE|AWS_CAPTION|AWS_SYSMENU|AWS_MINIMIZEBOX,0,"Keno",0);
playwin.SetWindowColor(RGB(0,0,255));
//the buttons
startbtn.Create(0,340,70,20,AWS_VISIBLE,1,"START",playwin);
clearbtn.Create(80,340,70,20,AWS_VISIBLE,2,"CLEAR",playwin);

run = 1;
playing = 0;
do{ wait();}until run = 0;
playwin.Destroy();
return 0;

}

//The kenowin window handler methods
//Center the window on creation.
//Process the left mouse button to select/unselect balls.
//Process the timer to pick random balls.
//Start and clear the board in response to our two buttons

kenowin::OnClose(),int
{

run = 0;
return true;

}

kenowin::OnCreate(),int
{

CenterWindow();
ClearBoard();
return true;

}

kenowin::OnPaint(),int
{

DrawBalls();
return true;

}

kenowin::OnLButtonDown(int x,int y, int flags),int
{

SelectBall(x,y);
return true;

}

kenowin::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{

if(nNotifyCode = 0)
{

select nID
{

CASE 1:

StartPlay();

CASE 2:

ClearBoard();

}
SetFocus();

}
return true;

}

kenowin::OnChar(unsigned int nChar,INT nRepCnt),int
{

select nChar
{

CASE ASC("s"):

StartPlay();

CASE ASC("c"):
CASE& ASC("C"):

ClearBoard();

}
return true;

}

kenowin::OnTimer(int nIDEvent),int
{

if picked < 20
{

PickBall();
picked = picked + 1;
DrawBalls();

}
else
{

EndPlay();
playing = 0;

}
return true;

}


//------------------- DRAWBALLS ---------------
//Draw 80 balls and the status text
//Balls are colored depending on the value of
//the balls array.
//0 = not selected, 1 = selected, 2 = hit, 3 = miss
//---------------------------------------------
kenowin::DrawBalls()
{

int x,y,num;
unsigned int cacheDC,colorball;
string strball,strstat;
cacheDC = GetHDC();
DrawMode(TRANSPARENT);
num = 1;
for( y = 0; y < 8;y++)
{

for( x = 0; x < 10; x++)
{

colorball = 0xFFFFFF;
if balls[num-1] = 1 colorball = selected;
if balls[num-1] = 2 colorball = hit;
if balls[num-1] = 3 colorball = miss;
Circle( (x*40)+20,(y*40)+20,20,0,colorball );
strball = ltrim$(str$(num,0));
if num < 10 strball = "0" + strball;
WriteText( (x*40) + 10, (y*40) + 10,strball );
num = num + 1;

}

}
DrawMode(OPAQUE);
strstat = "Drawn: " + ltrim$(str$(picked,0));
strstat = strstat + " / Hit: " + ltrim$(str$(hitcount,0));
strstat = strstat + " out of " + ltrim$(str$(selectcount,0)) + " ";
WriteText( 155,342,strstat);
ReleaseHDC(cacheDC);
return;

}
//------------------- SELECTBALL ---------------
//The mouse coordinates are converted to a ball number
//Balls can be deselected by clicking a second time
//Only a maximum of 10 balls can be selected in standard keno
//----------------------------------------------
kenowin::SelectBall(int mx,int my)
{

int x,y,num;
if playing return;
x = (mx - 10) / 40.0;
y = (my - 10) / 40.0;
num = x + (y * 10);
if ((num > 79) OR (num < 0)) return;
select balls[num]
{

CASE 3:
CASE& 0:

IF selectcount < 10
{

balls[num] = 1;
selectcount = selectcount + 1;

}

CASE 1:
CASE& 2:

balls[num] = 0;
selectcount = selectcount - 1;

}
DrawBalls();
return;

}
//---------------- STARTPLAY -----------------
//The previous draws are cleared and a timer is
//started. One ball will be randomly picked every
//time the timer expires
//The two buttons are disabled until play completes
//--------------------------------------------
kenowin::StartPlay()
{

int x;
if selectcount > 0
{

playing = 1;
picked = 0;
hitcount = 0;
for( x = 0; x < 80; x++)
{

if(balls[x]=3) balls[x] = 0;
if(balls[x]=2) balls[x] = 1;

}
DrawBalls();
StartTimer(100);
EnableControl(m_hWnd,1,0);
EnableControl(m_hWnd,2,0);

}
return;

}

//----------------- ENDPLAY ------------------
//After 20 balls are generated the timer is stopped
//The two buttons are re-enabled
//--------------------------------------------
kenowin::EndPlay()
{

StopTimer();
EnableControl(m_hWnd,1,1);
EnableControl(m_hWnd,2,1);
return;

}
//---------------- CLEARBOARD ----------------
//Clears all the selected balls and resets the counters
//--------------------------------------------
kenowin::ClearBoard()
{

int x;
for( x = 0; x< 80; x++) { balls[x] = 0; }
selectcount = 0;
picked = 0;
hitcount = 0;
DrawBalls();
return;

}

//---------------- PICKBALL -----------------
//Generates a random number between 0 and 79
//if the number has already been drawn then
//continues generating a random number until
//a non drawn ball is found
//-------------------------------------------
kenowin::PickBall()
{

int x,done;
done = 0;
do
{

x = rnd(80);
if ((balls[x] <> 3) AND (balls[x] <> 2)) done = 1;

}
until done;
//If its a selected ball then set it to 'hit'
if balls[x] = 1
{

balls[x] = 2;
hitcount = hitcount + 1;

}
//If its a non selected ball then set it to 'miss'
if balls[x] = 0 balls[x] = 3;
return;

}

//quick sub to enable/disable a control since controls don't have a method yet.
DECLARE IMPORT,GetDlgItem(hParent as int,id as int),int;
DECLARE IMPORT,EnableWindow(hwnd as int,bEnable as int),int;
SUB EnableControl(int hParent,int id,int bEnable)
{

int hControl = GetDlgItem(hParent,id);
if(hControl)

EnableWindow(hControl,bEnable);

return;

}

Disclaimer:

Any information you may receive related to this web site is provided merely as friendly suggestions, not as expert opinion, testimony or advice. Neither Rock Ridge Farms nor myself endorses or sponsors any information, products or methodologies you may find herein. Rock Ridge Farms, The Florida Tractor Connection, myself, subscribers nor contributors can not be held liable for any use of the information you might receive.

Last Updated: 1/26/2006