watzee.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 662 行 · 第 1/2 页
C
662 行
{
HBITMAP hbm;
if( GotTimer ) {
KillTimer( hwnd, ID_TIMER );
}
for( i = 0; i < 6; i++ ) {
hbm = (HBITMAP)GetWindowLong( hwnd, i * sizeof( DWORD ) );
DeleteObject( hbm );
}
PostQuitMessage( 0 );
return( 0 );
}
}
return( DefWindowProc( hwnd, message, wparam, lparam ) );
}
/*
* DoScore -- update the score card after a score selection
*/
static void DoScore( HDC hdc, WORD selection )
/********************************************/
{
HFONT hfont;
short score;
score = 0;
if( LastScoreSelection ) {
Player[CurrentPlayer][LastScoreSelection] = UNDEFINED;
WriteScore( hdc, CurrentPlayer, LastScoreSelection );
DoScoreTotals( hdc );
}
LastScoreSelection = selection;
switch( selection ) {
case ACES :
case TWOS :
case THREES :
case FOURS :
case FIVES :
case SIXES :
score = DiceInfo.count[selection] * selection;
break;
case THREE_KIND :
if( DiceInfo.got_three_kind ) {
score = DiceInfo.sum;
}
break;
case FOUR_KIND :
if( DiceInfo.got_four_kind ) {
score = DiceInfo.sum;
}
break;
case FULL_HOUSE :
if( DiceInfo.got_full_house ) {
score = 25;
}
break;
case SMALL_STRAIGHT :
if( DiceInfo.got_small_straight ) {
score = 30;
}
break;
case LARGE_STRAIGHT :
if( DiceInfo.got_large_straight ) {
score = 40;
}
break;
case WATZEE :
if( DiceInfo.got_watzee ) {
score = 50;
}
break;
case WATZEE_BONUS :
score = Player[CurrentPlayer][WATZEE_BONUS];
if( score == UNDEFINED ) {
score = 100;
} else {
score += 100;
}
break;
case CHANCE :
score = DiceInfo.sum;
break;
}
Player[CurrentPlayer][selection] = score;
hfont = SelectObject( hdc, CreateFontIndirect( &SmallBoldFont ) );
WriteScore( hdc, CurrentPlayer, selection );
DeleteObject( SelectObject( hdc, hfont ) );
DoScoreTotals( hdc );
}
/*
* DoScoreTotals -- update the current player's Upper Total, Bonus, Lower Total
* and Grand Total
*/
static void DoScoreTotals( HDC hdc )
/**********************************/
{
short upper_total;
short lower_total;
short i;
upper_total = 0;
lower_total = 0;
for( i = ACES; i <= SIXES; i++ ) {
if( Player[CurrentPlayer][i] != UNDEFINED ) {
upper_total += Player[CurrentPlayer][i];
}
}
if( upper_total >= 63 ) {
upper_total += 35;
Player[CurrentPlayer][BONUS] = 35;
}
Player[CurrentPlayer][UPPER_TOTAL] = upper_total;
for( i = THREE_KIND; i <= WATZEE_BONUS; i++ ) {
if( Player[CurrentPlayer][i] != UNDEFINED ) {
lower_total += Player[CurrentPlayer][i];
}
}
Player[CurrentPlayer][LOWER_TOTAL] = lower_total;
Player[CurrentPlayer][GRAND_TOTAL] = upper_total + lower_total;
SelectObject( hdc, GetStockObject( SYSTEM_FONT ) );
for( i = BONUS; i <= GRAND_TOTAL; i++ ) {
WriteScore( hdc, CurrentPlayer, i );
}
}
/*
* GetDieCheck -- determine where on the score card the user just clicked,
* and decide whether the user just checked one of the die;
* return a value between 1 and 5 indicating which die, or
* zero if a die was not clicked
*/
static WORD GetDieCheck( HWND hwnd, POINT point )
/***********************************************/
{
BITMAP bm;
RECT rect;
WORD die_checked;
short dy;
short i;
HBITMAP hbm;
die_checked = 0;
hbm = (HBITMAP)GetWindowLong( hwnd, 0 );
GetObject( hbm, sizeof( BITMAP ), (LPSTR) &bm );
rect.top = CharHeight * 2;
rect.bottom = rect.top + bm.bmHeight;
rect.left = CharWidth * 24;
rect.right = rect.left + bm.bmWidth;
dy = bm.bmHeight + bm.bmHeight / 7;
for( i = 0; i < 5; i++ ) {
if( PtInRect( &rect, point ) ) break;
rect.top += dy;
rect.bottom += dy;
}
if( i < 5 ) {
die_checked = IDW_DICE1 + i;
}
return( die_checked );
}
/*
* GetScoreCheck -- determine where on the score card the user just clicked,
* and decide whether the user just made a valid score
* selection; return the score option that was chosen, or
* zero if a score option was not clicked
*/
static WORD GetScoreCheck( POINT point )
/**************************************/
{
short x;
short y;
short char_height;
short char_width;
short score_option_vline;
short left_column;
short right_column;
short score_selection;
x = point.x;
y = point.y;
score_selection = 0;
char_height = CharHeight;
char_width = CharWidth;
score_option_vline = char_width * SCORE_OPTIONS_WIDTH + char_width;
left_column = score_option_vline + CurrentPlayer * char_width * 3;
right_column = left_column + char_width * 3;
if( ( x < score_option_vline && x > char_width )
|| ( x > left_column && x < right_column ) ) {
if( y < char_height * 9 && y > char_height * 3 ) {
if( y < char_height * 6 ) {
if( y < char_height * 4 ) {
score_selection = ACES;
} else if( y < char_height * 5 ) {
score_selection = TWOS;
} else {
score_selection = THREES;
}
} else {
if( y < char_height * 7 ) {
score_selection = FOURS;
} else if( y < char_height * 8 ) {
score_selection = FIVES;
} else {
score_selection = SIXES;
}
}
} else if( y > char_height * 12 && y < char_height * 19 ) {
if( y < char_height * 16 ) {
if( y < char_height * 14 ) {
if( y < char_height * 13 ) {
score_selection = THREE_KIND;
} else {
score_selection = FOUR_KIND;
}
} else if( y < char_height * 15 ) {
score_selection = FULL_HOUSE;
} else {
score_selection = SMALL_STRAIGHT;
}
} else if( y < char_height * 17 ) {
score_selection = LARGE_STRAIGHT;
} else if( y < char_height * 18 ) {
score_selection = WATZEE;
} else {
score_selection = CHANCE;
}
}
}
return( score_selection );
}
/*
* InitializeGameData -- initialize the scores, the player's initials, and
* other global variables
*/
static void InitializeGameData( void )
/************************************/
{
short i;
short j;
NumberOfPlayers = 0;
PlayingGameYet = FALSE;
CurrentTurn = 0;
CurrentPlayer = 0;
CurrentRoll = 0;
DieCheckMeansRoll = TRUE;
ResetDieChecks = TRUE;
GotTimer = FALSE;
LastScoreSelection = 0;
PCTurn = FALSE;
for( i = 0; i < MAX_PLAYERS; i++ ) {
Player[i][IS_COMPUTER] = FALSE;
for( j = ACES; j < LOWER_TOTAL; j++ ) {
Player[i][j] = UNDEFINED;
}
Player[i][UPPER_TOTAL] = 0;
Player[i][LOWER_TOTAL] = 0;
Player[i][GRAND_TOTAL] = 0;
sprintf( PlayerName[i], " " );
}
for( i = 0; i < 5; i++ ) {
Dice[i].value = i+1;
Dice[i].is_checked = TRUE;
}
}
/*
* NextPlayer -- determine if the game is over; if not, reset the
* CurrentTurn counter for the next player and initialize
* the dice
*/
static void NextPlayer( HWND hwnd, HDC hdc )
/******************************************/
{
BOOL reset_value;
short i;
PCTurn = FALSE;
HighliteName( hdc, CurrentPlayer );
CurrentPlayer++;
if( CurrentPlayer == NumberOfPlayers ) {
CurrentPlayer = 0;
CurrentTurn++;
if( CurrentTurn == 13 ) {
SendMessage( hwnd, WMW_GAME_OVER, 0, 0 );
return;
}
}
HighliteName( hdc, CurrentPlayer );
WriteScoreOptions( hdc );
CurrentRoll = 0;
reset_value = FALSE;
if( DieCheckMeansRoll ) {
reset_value = TRUE;
}
for( i = 0; i < 5; i++ ) {
Dice[i].is_checked = reset_value;
CheckDlgButton( hwnd, IDW_DICE1+i, reset_value );
}
RollDice( hwnd, hdc );
GetDiceInfo();
EnableWindow( GetDlgItem( hwnd, IDW_OK ), FALSE );
if( Player[CurrentPlayer][IS_COMPUTER] ) {
PCTurn = TRUE;
EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), FALSE );
} else {
EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), TRUE );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?