June 15, 2024, 08:21:50 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Keno (conversion)

Started by Ionic Wind Support Team, January 02, 2006, 11:22:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

January 02, 2006, 11:22:57 AM Last Edit: January 02, 2006, 12:14:55 PM by Ionic Wizard
Another converted example program.  I originally wrote this program to prove to a friend that he was wasting his money on keno. Pick any ten numbers and run it thousands of times, the odds of hitting a ten ball keno are about the same as learning how to teleport ones self to mars ;)


//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"):
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;
}

Ionic Wind Support Team

Ionic Wind Support Team

The above was modified to check for nNotifyCode=0 in OnControl.  Just in case anyone uses XP themes with the app.

Ionic Wind Support Team

Parker

QuoteI originally wrote this program to prove to a friend that he was wasting his money on keno. Pick any ten numbers and run it thousands of times, the odds of hitting a ten ball keno are about the same as learning how to teleport ones self to mars ;)

No wonder I could never win when I tried it back with IBStd ;)

Ionic Wind Support Team

Vegas has 12 ball keno.  And no in has ever hit it, in any of the casinos, and they never expect anyone to.  Yet people still sit there and waste their time on it.
Ionic Wind Support Team

Parker

Well someday I'm going to be the first one ::)

It's all about that though, although it's horrible how people will just sit and waste their money. But it's everyone's individual choice.

ThadMiller

eh... some people would say that computers are a waste of time and money.    ;)

Zen

Yes my girlfriend quite frequently says "Why do you spend all that money on a computer? Whats wrong with the one you had before?" Sighhhhhhhh!

Lewis

Parker

Well then you have a problem, don't you. Your job now is to get the most resource-consuming game and a win95 computer with like 200MHz, a horrible graphics card, etc. Then have her play the game ;)

Zen

Ha Ha. Fat chance of that happening. She wont even play on my playstation. To be honest i dont even know how she has stayed with me these last 2 years. Whenever im not with her im either playing around with Aurora and IBasic (even at work). When i am with her im talking about what i did with it. She is very anit-computer but im determine to make something she will get hooked on... Muha ha ha

Lewis

ThadMiller

Heh... Lewis, we should start a club!   :)