카페에서 심심해서 즉석으로 만든 프로그램이다.

하루동안 김대리가 제일 많이 하는 것 같다고 추정되는 문장을 샘플링 하여 시뮬레이팅 해 보았다.

자바와 스레드를 응용하였다.

다섯의 샘플 엽이가 랜덤 시간으로 랜덤 문장을 열심히 지껄이는 것을 그저 멍하니 바라보는 프로그램이다.


출력 예시


소스(이모티콘이 포함되어 있어 깨지는 것이 존재함)

import java.util.ArrayList;

public class Main {

    public static void main( String args[] )
    {
        ArrayList< Yeobi > m_alYeobi = new ArrayList();
        System.out.println( "나는 엽이다" );


        m_alYeobi.add( new Yeobi() );
        m_alYeobi.add( new Yeobi() );

        m_alYeobi.add( new Yeobi() );
        m_alYeobi.add( new Yeobi() );
        m_alYeobi.add( new Yeobi() );

        for( Yeobi y : m_alYeobi )

        {
            y.start();

        }
    }

}


import java.util.ArrayList;
import java.util.Random;

public class Yeobi extends Thread
{
    ArrayList< String > m_alComment = new ArrayList<String>();
    Random m_random = new Random();

    public Yeobi()
    {
        m_alComment.add( 
            "⊂_? \n" +
            "  \\ Λ_Λ \n" +
            "   \( ‘ㅅ' ) 두둠칫 \n" +
            "    > ⌒? \n" +
            "   /   へ\ \n" +
            "   /  / \\ \n" +
            "   ? ノ   ?_つ \n" +
            "  / /두둠칫 \n" +
            "  / /| \n" +
            " ( (? \n" +
            " | |、\ \n" +
            " | ? \ ⌒) \n" +
            " | |  ) / \n" +
            "\"`ノ )  L? \n"
        );
    m_alComment.add( "♥?( `Д' ?)" );
    m_alComment.add( "工エエェ(?ロ?)ェエエ工" );
    m_alComment.add( "우리 옥상가자!!(?▽?*)" );
    m_alComment.add( "우리 휴게실 가자!!(?▽?*)" );
    m_alComment.add( "얼음 홍차 마시러가자!!(?▽?*)" );
    m_alComment.add( "우리 먹을거 사러가자!!(?▽?*)" );
    m_alComment.add( "빵집 문 열었나?(?▽?*)" );
    m_alComment.add( "어이구 우리 쪼유~(?▽?*)" );
    m_alComment.add( "갈 수록 이뻐지는거같애!(?▽?*)" );
}

    public void run() {
        while( true )
        {
            System.out.println( m_alComment.get( m_random.nextInt( m_alComment.size() ) ) );
            try {
                sleep( m_random.nextInt( 10000 ) );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


'잉여 연구' 카테고리의 다른 글

[C]주사위 던지기  (0) 2013.03.29
C 숫자 퀴즈 예제  (0) 2013.03.13




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;
  }
}

'잉여 연구' 카테고리의 다른 글

엽이 시뮬레이터  (2) 2013.08.15
C 숫자 퀴즈 예제  (0) 2013.03.13



룰 : 20회 도전 기회가 주어지며, 세부 사항은 소스 참조.


내껀 아니고 성원오빠 껀데 버그 해결 도와드린거...


 //10 이상 차이나면 "차이가 너무 큽니다!"라고 뜸

//10 이하 차이나면 "가까이 있습니다!"라고 뜸
//5 이하 차이나면 "아깝다!"라고 뜸
//그 수를 맞출 시 "딩동댕!"이라고 뜸

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
  int cnt = 20;
  int i = 0//i는 사용자에게 입력받는 변수
  unsigned int fn;

  srand(time(NULL));
  fn = rand() % 21//0~20 사이 난수 생성

  while( cnt > 0 )
  {
    printf("총 %d회 남았습니다.\n", cnt );

    scanf( "%d"&i ); //사용자에게 입력받는 부분

    if( fn == i )
    {
      printf( "딩!동!댕!" );
    }
    else
    {
      if ( !( ( ((int)fn-10< i ) && ( i < ((int)fn+10) ) ) )
      {
        printf("차이가 너무큽니다!.\n");
      }
      else if ( ( ((int)fn-5<= i ) && ( i <= ((int)fn+5) ) )
      {
        printf("아깝다!.\n");
      }
      else
      {
        if( ( ((int)fn-10< i ) && ( i < ((int)fn+10) ) )
        {
          printf("가까이 있습니다!.\n");
        }

      }
    }
    cnt = cnt - 1;
  }
  

  return 0;
}


'잉여 연구' 카테고리의 다른 글

엽이 시뮬레이터  (2) 2013.08.15
[C]주사위 던지기  (0) 2013.03.29

+ Recent posts