슬롯 머신 코드 분석이요

lemeraldl의 이미지

game_control 이부분이 돌아가는부분 같은데 잘모르겠어요

그리고 맨처음 특수 문자 넣는 부분이 [6][4] 로 범위를 자바준게 이해가 안가요

이소스를 보면 특수문자를 [0][] 1번줄 부터 초기화 해주고 뒤에서 다시 전체를 재초기화 하는데요

특별한 이유가 있는지 너무 궁금하네요

#include

#include

#include

#include

#include

void display_rule(void);

void draw_check02(int c, int r);

void reel_series(int r[][3]);

void gotoxy(int x, int y);

int game_progress(int money);

void display_reel(char rc[][4], int r[][3], int index);

void clear_text(void);

void game_control(char reel[][4], int reel_num[][3], int *money);

int return_money(int r[], int betting, int *case_num);

int main(void)

{

char reel[6][4]={"★","♠","◆","♥","♣","○"};

int i, reel_num[3][3];
int j;
int money=10000;

srand(time(NULL));
printf("reel[0][0]:%c\n",reel[0][0]);
reel_num[0][0]=reel[0][0];
//printf("reel[0][0]:%d\n",reel_num[0][0]);
printf(" 슬롯머신게임\n\n");

display_rule();

gotoxy(3, 5);

printf("릴1 릴2 릴3");

gotoxy(1, 6);

draw_check02(3, 3);

for(j=i=0;i<3;i++){
reel_num[0][i]=rand()%5;
//printf("reel_num[0][0]:%d\n",reel_num[0][i]);
printf("reel_num[0][%d]:%d\n",i,reel_num[0][i]);
//printf("reel[0][0]:%s\n",reel[0][0]);
//reel_num[0][0]=reel[0][0];
//printf("reel[0][0]:%s\n",reel_num[0][0]);
}
reel_series(reel_num);

do{

game_control(reel, reel_num, &money);

}while(money);

gotoxy(3,20);

return 0;

}

//당첨사례와사례금액을출력하는함수

void display_rule(void)

{

gotoxy(30, 3);

printf("릴1 릴2 릴3 사례금\n");

gotoxy(30, 4);

printf("----------------------------------\n");

gotoxy(30, 5);

printf("1: ★★★\t*10\n");

gotoxy(30, 6);

printf("2: ♠♠♠\t *7\n");

gotoxy(30, 7);

printf("3: ◆◆◆\t *5\n");

gotoxy(30, 8);

printf("4: ★★기타\t *4\n");

gotoxy(30, 9);

printf("5: ♠♠기타\t *3\n");

gotoxy(30, 10);

printf("6: ◆◆기타\t *3\n");

gotoxy(30, 11);

printf("7: ♥♥기타\t *3\n");

gotoxy(30, 12);

printf("8: ♣♣기타\t *2\n");

gotoxy(30, 13);

printf("9: ○○기타\t *1\n");

}

void draw_check02(int c, int r)

{

int i, j;

unsigned char a=0xa6;

unsigned char b[12];

for(i=1;i<12;i++)

b[i]=0xa0+i;

printf("%c%c", a, b[3]);

for(i=0;i

{

printf("%c%c", a, b[1]);

printf("%c%c", a, b[8]);

}

printf("%c%c", a, b[1]);

printf("%c%c", a, b[4]);

printf("\n");

for(i=0;i

{

printf("%c%c", a, b[2]);

for(j=0;j

{

printf(" ");

printf("%c%c", a, b[2]);

}

printf("\n");

printf("%c%c", a, b[7]);

for(j=0;j

{

printf("%c%c", a, b[1]);

printf("%c%c", a, b[11]);

}

printf("%c%c", a, b[1]);

printf("%c%c", a, b[9]);

printf("\n");

}

printf("%c%c", a, b[2]);

for(j=0;j

{

printf(" ");

printf("%c%c", a, b[2]);

}

printf("\n");

printf("%c%c", a, b[6]);

for(i=0;i

{

printf("%c%c", a, b[1]);

printf("%c%c", a, b[10]);

}

printf("%c%c", a, b[1]);

printf("%c%c", a, b[5]);

printf("\n");

}

//각릴에대한기호의순서를결정하는함수

void reel_series(int r[][3])

{

int i, j;

for(i=0;i<3;i++) {

for(j=0;j<3;j++) {

r[j][i]=(r[0][i]+j)%6;
printf("r[%d][%d]:%d\n",i,j,r[j][i]);
}
}

}

void gotoxy(int x, int y)

{

COORD Pos = { x-1, y-1 };

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);

}

//게임진행상황과배팅금액을입력받아반환하는함수

int game_progress(int money)

{

int bet;

gotoxy(43, 17);

printf("현재남은금액: %d원", money);

gotoxy(1, 17);

printf("배팅금액을입력하고 Enter키를누르면");

gotoxy(1, 19);

printf("0을입력하면종료합니다.");

gotoxy(1, 18);

printf("게임을시작합니다. 금액입력>");

gotoxy(30, 18);

scanf("%d", &bet);

if(bet==0)

exit(0);

gotoxy(1, 19);

printf("아무키나한번만키를누르면릴이멈춥니다.");

return bet;

}

//화면에표시된지시어들을지우는함수

void clear_text(void)

{

int i, j;

for(i=17;i<20;i++)

{

gotoxy(1, i);

for(j=0;j<42;j++)

printf(" ");

}

}

//회전순서에따라릴을화면에출력하는함수

void display_reel(char rc[][4], int r[][3], int index)

{

int i, j;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

{

gotoxy(3+j*4, 7+i*2);

printf("%s", rc[r[i][j]]);

}

}

//슬롯머신게임을제어하는함수

void game_control(char reel[][4], int reel_num[][3], int *money)

{

int i, j, bet, case_num=0, thank, num[3];

double pst;

clock_t start, end;

display_reel(reel, reel_num, 0);

bet=game_progress(*money);

for(i=0;i<3;i++)

{

start=clock();

do

{

for(j=i;j<3;j++)

reel_num[0][j]=reel_num[1][j];

reel_series(reel_num);

display_reel(reel, reel_num, i);

end=clock();

pst=(double)(end-start)/CLK_TCK;

}while(!kbhit() || (pst<1));

num[i]=reel_num[1][i];

}

getch();

thank=return_money(num, bet, &case_num);

if(thank==0)

*money-=bet;

else

*money+=thank;

if(case_num)

{

gotoxy(43, 18);

printf("사례:%d. 배팅:%d원, 사례금:%d", case_num, bet, thank);

}

clear_text();

}

//당첨사례따라배팅금액과사례금을계산하는함수

int return_money(int r[], int betting, int *case_num)

{

int total=0;

if(r[0]==r[1] && r[1]==r[2] && r[0]==r[2])

{

if(r[0]==0)

{

total=betting*10;

*case_num=1;

}

else if(r[0]==1)

{

total=betting*7;

*case_num=2;

}

else if(r[0]==2)

{

total=betting*5;

*case_num=3;

}

}

else if((r[0]==0 && r[1]==0) || (r[1]==0 && r[2]==0) || (r[0]==0 && r[2]==0))

{

total=betting*4;

*case_num=4;

}

else if((r[0]==1 && r[1]==1) || (r[1]==1 && r[2]==1) || (r[0]==1 && r[2]==1))

{

total=betting*3;

*case_num=5;

}

else if((r[0]==2 && r[1]==2) || (r[1]==2 && r[2]==2) || (r[0]==2 && r[2]==2))

{

total=betting*3;

*case_num=6;

}

else if((r[0]==3 && r[1]==3) || (r[1]==3 && r[2]==3) || (r[0]==3 && r[2]==3))

{

total=betting*3;

*case_num=7;

}

else if((r[0]==4 && r[1]==4) || (r[1]==4 && r[2]==4) || (r[0]==4 && r[2]==4))

{

total=betting*2;

*case_num=8;

}

else if((r[0]==5 && r[1]==5) || (r[1]==5 && r[2]==5) || (r[0]==5 && r[2]==5))

{

total=betting*1;

*case_num=9;

}

return total;

}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.