zzosawi.exe
gotoxy같은 함수를 이용하지 않고 순수하게 노가다로(ㅋㅋㅋ) 출력한 주사위 게임 입니다.
주사위 수십개도 하면 할 수 있는데, 화면 길이의 압박으로 -_-; 밸런스가 적당(?)한 1~8개를 던지는 것으로 하였습니다.
이를 이용해 부루마블 게임을 만들면 재밌지 않을까 생각하고 있습니다. ^ㅂ^
이하 소스~
#include< stdio.h > #include< windows.h > #include< stdlib.h > #include< time.h >
void SetDice( int* _dice ); void DrawDice( int i, int _number );
int main() { char m_input = 'r'; int m_dice = 0; int i; int j; int m_diceNumber[ 8 ]; int m_sum = 0;
SetConsoleTitle( "ZZOSAWI" ); system( "mode con lines=7 cols=81" ); system( "color F0" );
srand( time( NULL ) );
while( m_input != 27 ) { system( "cls" ); if( m_input == 'r' ) { m_dice = 0; SetDice( &m_dice ); } for( i=1; i<=m_dice; i++ ) { m_diceNumber[i-1] = ( rand() % 6 ) + 1; } for( i=1; i<=5; i++ ) { for( j=1; j<=m_dice; j++ ) { DrawDice( i, m_diceNumber[j-1] ); } putchar( '\n' ); } for( i=1; i<=m_dice; i++ ) { m_sum = m_sum + m_diceNumber[i-1]; printf( "%d번:%d ", i, m_diceNumber[i-1] ); } printf( "총 %d입니다.\n", m_sum ); printf( "되돌아 가려면 R 키, 끄려면 ESC 키, 주사위를 다시 돌리려면 아무 키나 눌려주세요." ); m_input = getch(); m_sum = 0; } }
void SetDice( int* _dice ) { while( ( *_dice<=0 ) && ( *_dice<=8 ) ) { system( "cls" ); printf( "주사위 몇개?\n(1~8) : " ); scanf( "%1d", _dice ); } }
void DrawDice( int _i, int _number ) { switch( _i ) { case 1: printf( "┌───┐" ); break; case 2: switch( _number ) { case 1: case 2: printf( "│ │" ); break; case 3: printf( "│ ●│" ); break; case 4: case 5: case 6: printf( "│● ●│" ); break; } break; case 3: switch( _number ) { case 1: case 3: case 5: printf( "│ ● │" ); break; case 2: case 6: printf( "│● ●│" ); break; case 4: printf( "│ │" ); break; } break; case 4: switch( _number ) { case 1: case 2: printf( "│ │" ); break; case 3: printf( "│● │" ); break; case 4: case 5: case 6: printf( "│● ●│" ); break; } break; case 5: printf( "└───┘" ); break; } }
|