とりあえず実行してみろ
■ このスレッドは過去ログ倉庫に格納されています
0001デフォルトの名無しさん
NGNG#include <windows.h>
VC++6、default環境、コンソールプログラム
-------
↓以下本文
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
int i;
int aside;
int bside;
int attackflag=-1;// 0: aside ,1: bside
char asidename[16];
char bsidename[16];
char cBuf[256];
printf( "名前を入れてね。aside:" );
scanf("%s" , asidename );
printf( "名前を入れてね。bside:" );
scanf("%s" , bsidename );
printf( "お互いの体力を入れてね。POWER:" );
scanf("%d" , &aside);
bside = aside;
00021
NGNGattackflag = rand() % 2;
if( attackflag == 0 )
{
printf(" %s 先攻!! \n" , asidename );
}
else if( attackflag == 1 )
{
printf(" %s 先攻!! \n" , bsidename );
}
while( ( aside > 0 ) && ( bside > 0 ) )
{
sprintf(cBuf , "%s: %d \n %s: %d \n", asidename , aside ,
bsidename , bside );
MessageBox( NULL , cBuf , "状態" , MB_OK );
srand( (unsigned)time( NULL ) );
i = rand() % 6 + 1 ;
if( i == 5 )
{
MessageBox( NULL , "クリティカルヒット!!","!!!!!" , MB_OK );
i += rand() % 6 + 1;
}
if( attackflag == 0 )
{
bside -= i;
sprintf(cBuf , "%sは%sに%dダメージ! \n %s : %d" , asidename ,
bsidename , i , bsidename , bside );
}
else if( attackflag == 1 )
{
aside -= i;
sprintf(cBuf , "%sは%sに%dダメージ! \n %s : %d" , bsidename ,
asidename , i , asidename , aside );
}
MessageBox( NULL , cBuf , "攻撃" , MB_OK );
attackflag = ( attackflag+1 ) % 2;
}
if( aside <= 0 )
{
sprintf( cBuf , "%s の勝ち。\n" , bsidename );
}
if( bside <= 0 )
{
sprintf( cBuf , "%s の勝ち。\n" , asidename );
}
MessageBox( NULL , cBuf , "結果" , MB_OK );
printf("%s" , cBuf );
return 0;
}
00031
NGNG0004デフォルトの名無しさん
NGNG入社時のC言語研修(自由課題)で自分が作ったのにそっくりだ…。
0005デフォルトの名無しさん
NGNG0006デフォルトの名無しさん
NGNG0007デフォルトの名無しさん
NGNG:: とりあえず実行してみろ。
::
explorer
a
0008コンソール版
NGNG#include <stdlib.h>
#include <time.h>
typedef struct {
const char *name;
int power;
} player;
int
main(int argc, char *argv[])
{
int i;
player side[2];
int turn = -1; // 0: aside ,1: bside
if (argc != 4) {
printf("%s aside bside power\n", argv[0]);
return 1;
}
side[0].name = argv[1];
side[1].name = argv[2];
side[0].power = side[1].power = atoi(argv[3]);
srand((unsigned) time(NULL));
turn = rand() % 2;
printf("%s 先攻!! \n", side[turn].name);
while ((side[0].power > 0) && (side[1].power > 0)) {
for (i = 0; i < 2; ++i) {
printf("%s: %d\t", side[i].name, side[i].power);
}
i = rand() % 6 + 1;
if (i == 5) {
printf("クリティカルヒット!!");
i += rand() % 6 + 1;
}
if ((side[turn^1].power -= i) < 0) {
side[turn^1].power = 0;
}
printf("%sは%sに%dダメージ! \n", side[turn].name, side[turn^1].name, i);
turn ^= 1;
}
turn ^= 1;
printf("%s の勝ち。\n", side[turn].name);
return 0;
}
0009驚愕1
NGNG>attackflag = rand() % 2; //attackflag = rand()&1とせよ
>else if( attackflag == 1 ) //elseだけでOK
>srand( (unsigned)time( NULL ) ); //この行不要
>i = rand() % 6 + 1 ;
>attackflag = ( attackflag+1 ) % 2; //attackflag = !attackflagとせよ
0010驚愕2
NGNG<HEAD><TITLE>_</TITLE></HEAD>
<BODY>
<SCRIPT>
function _click()
{
var e = document.forms[0].elements;
var n = new Array( 2 );
var p = new Array( 2 );
for ( var i = 0, j; i < 2; i++ ) { n[i] = e[i].value; p[i] = e[2].value; }
e = e[4];
alert( e.value = n[i = Math.round( Math.random() )] + "が先行です。\n" );
for ( ; p[i] > 0; )
{
e.value += n[0] + ":" + p[0] + "\t" + n[1] + ":" + p[1] + "\n";
j = Math.ceil( Math.random() * 6 );
if ( j == 5 ) { e.value += "クリティカルヒット!\n"; j += Math.ceil( Math.random() * 6 ); }
p[i ^= 1] -= j;
e.value += n[i ^ 1] + "が" + n[i] + "に" + j + "ダメージ\t" + n[i] + ":" + p[i] + "\n";
}
e.value += n[i ^ 1] + "の勝利です。\n";
}
</SCRIPT>
<FORM>
名前A<INPUT></INPUT><BR>
名前B<INPUT></INPUT><BR>
両力量<INPUT></INPUT><BR>
<INPUT ONCLICK="_click()" TYPE="BUTTON" VALUE="開始"></INPUT><BR>
<TEXTAREA COLS="50" ROWS="20"></TEXTAREA><BR>
</FORM>
</BODY>
</HTML>
0011デフォルトの名無しさん
NGNG00121
NGNG不特定多数に楽しんでもらうスレです。
もちろんネタコードで結構だす。
以上。かきにげ・・・
0013デフォルトの名無しさん
NGNGおもしろそうだから、逃げんな。
0014デフォルトの名無しさん
NGNGLANGUAGE属性かTYPE属性を指定しろ。
0015プログラムその1
NGNG#include <string.h>
#include "resource.h"
#include <time.h>
#include <tchar.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <commctrl.h>
#define CONT 0.4125
#define ACCELLIMIT 8
#define BREAKLIMIT 16
#define THREADTIME 0.1
#define IDM_DIALOG1 100
#define IDM_DIALOG2 101
#define IDM_EXIT 102
#define IDM_HELP 103
#define IDD_ACCEL 104
#define IDD_BREAK 105
#define IDD_IDLE 106
#define IDM_THREAD 107
#define IDM_THREAD2 108
BOOL CALLBACK DialogFunc(HWND hwnd , UINT message ,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK OnOK ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnCancel ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnAccel ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnIdle ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnBreak ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnInitDialog ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
BOOL CALLBACK OnSuspend ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam );
DWORD WINAPI MyThread1(LPVOID param);/* Threads */
DWORD WINAPI MyThread2(LPVOID param);
DWORD Tid1,Tid2; /* Thread ID */
HWND hValue; /* handle */
double dDis; /* 残り距離 */
double dVel = 0.0; /* 速度 */
int iStartDis = 0; /* 初期設定の距離*/
clock_t clStart,clEnd; /* messure play time */
0016プログラムその2
NGNGLPSTR lpszArgs,int nWinMode )
{
DialogBox(hThisInst , MAKEINTRESOURCE(IDD_DIALOG1) ,
NULL , DialogFunc);
return 0;
}
0017プログラムその3
NGNG/* Dialog Procedure */
/********************/
BOOL CALLBACK DialogFunc(HWND hwnd , UINT message ,WPARAM wParam,LPARAM lParam)
{
BOOL bRet = FALSE;
int iDis , iVel;
char cRet[64]; // inside messagebox
double elapse ,minelapse ; // elapsed time
double dPoint; // evaluation
double dTemp = 50.0;
switch(message)
{
case WM_INITDIALOG:
bRet = OnInitDialog ( hwnd , message , wParam , lParam );
break;
case WM_TIMER:
iDis = GetDlgItemInt( hValue , ID_EB4 , NULL , TRUE );
iVel = GetDlgItemInt( hValue , ID_EB3 , NULL , TRUE );
if(( iDis > 5 ) || ( dVel > 0) )
{
CreateThread(NULL , 0 , (LPTHREAD_START_ROUTINE)MyThread1 ,
(LPVOID) hwnd , 0 , &Tid1);
CreateThread(NULL , 0 , (LPTHREAD_START_ROUTINE)MyThread2 ,
(LPVOID) hwnd , 0 , &Tid2);
}
else
{
KillTimer(hwnd , 1);
clEnd = clock();
elapse = (double)(clEnd - clStart) / CLOCKS_PER_SEC;
dPoint = 50.0 - 0.4 * pow( iDis , 2 );
if(dPoint < 1.0 ) dPoint = 1.0;
if(iStartDis != 0 )
dTemp = 50.0 - pow(elapse , 2 ) * log( 1000.0 )/ (double) 360.0 / log( iStartDis );
if(dTemp >= 1.0)
dPoint += dTemp;
else dPoint += 1.0;
minelapse = floor( elapse / 60 );
elapse -= minelapse*60 ;
if((iDis <= 5 ) && (iDis >= -5))
{
sprintf(cRet , "到着! \n %.3f メートル \n かかった時間 %.0f 分 %.3f 秒" ,
dDis , minelapse , elapse);
MessageBox(hValue , cRet ,"正常終了" , MB_OK);
}
else if(iDis < -5)
{
sprintf(cRet , "オーバーラン! \n %.3f メートル \n かかった時間 %.0f 分 %.3f 秒",
dDis , minelapse , elapse);
MessageBox(hValue , cRet ,"暴走!" , MB_OK);
}
sprintf( cRet , "貴方の得点:\n (100点満点で)\n %.2f " , dPoint );
MessageBox( hValue , cRet , "結果発表" ,MB_OK );
}
bRet = TRUE;
break;
0018プログラムその4
NGNGswitch(LOWORD(wParam))
{
case IDOK:
hValue = hwnd;
bRet = OnOK ( hwnd , message , wParam , lParam );
break;
case IDCANCEL:
bRet = OnCancel ( hwnd , message , wParam , lParam );
break;
case IDD_ACCEL:
hValue = hwnd;
bRet = OnAccel ( hwnd , message , wParam , lParam );
break;
case IDD_IDLE:
hValue = hwnd;
bRet = OnIdle ( hwnd , message , wParam , lParam );
break;
case IDD_BREAK:
hValue = hwnd;
bRet = OnBreak ( hwnd , message , wParam , lParam );
break;
case IDD_SUSPEND:
hValue = hwnd;
bRet = OnSuspend ( hwnd , message , wParam , lParam );
break;
default:
break;
}
break;
default:
break;
}
return bRet;
}
0019プログラムその5
NGNG/* Set timer */
/*************/
DWORD WINAPI MyThread1(LPVOID param)
{
time_t t;
tm* newtime;
char* buf;
t = time(NULL);
newtime = localtime(&t);
buf = asctime(newtime);
SetDlgItemText( hValue , ID_EB1 , buf );
return 0;
}
/******************************/
/* Thread between TimeThreads */
/******************************/
DWORD WINAPI MyThread2(LPVOID param)
{
int iStatus;
iStatus = GetDlgItemInt( hValue , ID_EB2 , NULL , TRUE );
if(( dVel > 0.0 ) || ((dVel <= 0.0 ) && ( iStatus > 0)))
{
dVel = dVel + CONT * (double)iStatus * THREADTIME;
dDis = dDis - (0.5 * (double)iStatus * CONT * pow( THREADTIME , 2 ) +
THREADTIME * dVel);
}
else if(( dVel <= 0.0 ) && ( iStatus <= 0 ))
{
dVel = 0.0;
}
if( dVel > 0.0 ) SetDlgItemInt( hValue , ID_EB3 , dVel , TRUE );
else SetDlgItemInt( hValue , ID_EB3 , 0 , TRUE );
SetDlgItemInt( hValue , ID_EB4 , dDis , TRUE );
return 0;
}
0020プログラムその6
NGNG/* Handler when ok is pressed */
/******************************/
BOOL CALLBACK OnOK ( HWND hWnd , UINT uMsg ,
WPARAM wParam , LPARAM lParam )
{
int iDis;
BOOL bRet;
bRet = SetDlgItemInt ( hWnd , ID_EB2 , 0 , TRUE) ;
bRet = bRet && SetDlgItemInt ( hWnd , ID_EB3 , 0 , TRUE) ;
if (bRet == FALSE )
{
//Check whether SetDlgItemInt worked.
MessageBox( hValue , "editboxes initialize failed." ,
"error" , MB_OK);
return FALSE;
}
clStart = clock();
dVel = 0.0;
bRet = SetTimer(hWnd , 1 , THREADTIME*1000 , NULL );
if ( bRet == FALSE )
{
//Check whether SetTimer worked.
MessageBox( hValue , "settimer failed." ,
"error" , MB_OK );
KillTimer(hValue , 0);
return FALSE;
}
iDis = GetDlgItemInt(hWnd , ID_EB4 , NULL , TRUE );
iStartDis = iDis;
if(iDis <= 5 )
{
//Check whether GetDlgItemInt worked.
MessageBox( hValue , "Bad distance number." ,
"error" , MB_OK );
return FALSE;
}
dDis = (double)iDis;
return TRUE;
}
/**********************************/
/* Handler when cancel is pressed */
/**********************************/
BOOL CALLBACK OnCancel ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
int iRet;
iRet = KillTimer( hValue , 1 );
iRet *= TerminateThread( hValue , 0 );
iRet *= EndDialog( hWnd , 0 );
return iRet;
}
0021プログラムその7
NGNG/* Initialize a dialog */
/***********************/
BOOL CALLBACK OnInitDialog ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
BOOL bRet;
/************************************/
/* Set a default value at editboxes */
/************************************/
bRet = SetDlgItemInt ( hWnd , ID_EB2 , 0 , TRUE) ;
bRet = bRet && SetDlgItemInt ( hWnd , ID_EB3 , 0 , TRUE) ;
bRet = bRet && SetDlgItemInt ( hWnd , ID_EB4 , 1000 , TRUE );
return bRet;
}
/*********************************/
/* Handler when accel is pressed */
/*********************************/
BOOL CALLBACK OnAccel ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
int iStatus;
BOOL bRet;
iStatus = GetDlgItemInt( hValue , ID_EB2 , NULL , TRUE );
if( iStatus < ACCELLIMIT )
{
iStatus += 2;
}
if(( iStatus > ACCELLIMIT ) || ( iStatus < (-1) * BREAKLIMIT))
{
//Check whether status is illegal.
MessageBox(hWnd , "Operation Error!" , "error" ,MB_OK );
KillTimer(hValue , 1);
return FALSE;
}
bRet = SetDlgItemInt ( hWnd , ID_EB2 , iStatus , TRUE ) ;
return bRet;
}
0022プログラムその8
NGNG/* Handler when idle is pressed */
/********************************/
BOOL CALLBACK OnIdle ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
int iStatus;
BOOL bRet;
iStatus = 0;
bRet = SetDlgItemInt ( hWnd , ID_EB2 , iStatus , TRUE) ;
return bRet;
}
/*********************************/
/* handler when break is pressed */
/*********************************/
BOOL CALLBACK OnBreak ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
int iStatus;
BOOL bRet;
iStatus = GetDlgItemInt( hValue , ID_EB2 , NULL , TRUE );
if(BREAKLIMIT*(-1) < iStatus)
iStatus -= 2;
bRet = SetDlgItemInt ( hWnd , ID_EB2 , iStatus , TRUE ) ;
if(( iStatus > ACCELLIMIT ) || ( iStatus < (-1) * BREAKLIMIT))
{
//Check whether status is illegal.
MessageBox(hWnd , "Operation Error!" , "error" ,MB_OK );
KillTimer(hValue , 1);
return FALSE;
}
return bRet;
}
0023プログラム最後
NGNG/* Suspend Threads */
/*******************/
BOOL CALLBACK OnSuspend ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
int iRet;
iRet = KillTimer(hValue , 1);
iRet *= TerminateThread(hValue , 0 );
return iRet;
}
ふうう、厨房書き込み。
VC++6.0SP5、うぃん32API。
出荷状態のライブラリで、ダイアログリソースは
自分で作ってね。
0024デフォルトの名無しさん
NGNG0025デフォルトの名無しさん
NGNG0026デフォルトの名無しさん
NGNG0027デフォルトの名無しさん
NGNG0028デフォルトの名無しさん
NGNGttp://choco.2ch.net/test/read.cgi/news7/1009233792/
0029デフォルトの名無しさん
NGNG言い過ぎました。謝罪します。責任取って辞職します。
閉鎖します。鎖国します。
0031デフォルトの名無しさん
NGNGint main()
{
for(;;)
{
printf(" 終了!!");
}
return 0;
}
0032デフォルトの名無しさん
NGNGhttp://game.2ch.net/test/read.cgi/gamedev/1005038280/34-36
■ このスレッドは過去ログ倉庫に格納されています