Vota por nosotros en el ranking web que participamos

Curso Hacker
Bienvenido(a), Visitante. Favor de ingresar o registrarse.
¿Perdiste tu email de activación? - Octubre 13, 2008, 08:16:15
Inicio Ayuda Ingresar Registrarse
Visita: Articulos - Juegos Gratis - Da Foros

Comunidad Underground Hispana  |  Programacion  |  Programación  |  Carbide C/C#/C++  |  Tema: Simulador de batalla para el guaranpis, por Ni0 0 Usuarios y 1 Visitante están viendo este tema. « anterior próximo »
Páginas: [1] Ir Abajo Imprimir
Autor Tema: Simulador de batalla para el guaranpis, por Ni0  (Leído 103 veces)
Ni0
Gran Colaborador
*****
Desconectado Desconectado

Mensajes: 1362


Ni0-inside the source code

Ni0@el-hacker.org
Ver Perfil WWW Email
« en: ſeptiembre 15, 2007, 07:42:06 »

hola, en la seccion pedidos de software, en el post hago programas, me pidieron que les haga un programa (un simulador de batalla para el guaranpis), pero por el problema con la web el post desaparecio, igualmente nos mantubimos en contacto, asique aca termine el programa y este es el codigo fuente:

Código:
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <Ni0.h>/*aca esta definido ROJO VERDE AZUL y BLANCO
#include "main.h" /*aca esta definido Leva, Arquero, etc, que es el poder de ataque*/


int ta[27];
int td[33];
long int resa = 0, resd = 0;
char edit[10];
HWND hEditA[27]; /*controles edit del atacante*/
HWND hEditD[30]; /*del defensor*/
HWND hwndBoton;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);


char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    int i = 0;
    HWND hwnd;               
    MSG messages;         
    WNDCLASSEX wincl;       


    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;     
    wincl.style = CS_DBLCLKS;             
    wincl.cbSize = sizeof (WNDCLASSEX);


    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;               
    wincl.cbClsExtra = 0;                     
    wincl.cbWndExtra = 0;                     
   
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if (!RegisterClassEx (&wincl))
        return 0;

 
    hwnd = CreateWindowEx ( /*la ventana principal*/
           0,                 
           szClassName,       
           "Simulador de batalla Guaranpis",     
           WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION,
           CW_USEDEFAULT,     
           CW_USEDEFAULT,     
           665,                 
           600,                 
           HWND_DESKTOP,       
           NULL,               
           hThisInstance,       
           NULL                 
           );

    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);
    while(i < 9){ /*crea los controles edit, aca uno de estos es una columna*/
         hEditA[i] = CreateWindow(                 
           "edit",       
           "0",     
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           70,     
           100 + (25 * i),       /*para que aparezca uno abajo del otro*/
           70,             
           20,               
           hwnd,       
           NULL,             
           hThisInstance,     
           NULL                 
           );
           i++;
    }
    while(i < 18){/*lo mismo que el anterior*/
         hEditA[i] = CreateWindow(                 
           "edit",       
           "0",       
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           140,     
           100 + (25 * (i - 9)),   /*idem*/   
           70,                 
           20,                 
           hwnd,       
           NULL,               
           hThisInstance,     
           NULL               
           );
           i++;
    }
    while(i < 27){
         hEditA[i] = CreateWindow(                 
           "edit",       
           "0",       
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           210,       
           100 + (25 * (i - 18)),     
           70,               
           20,               
           hwnd,       
           NULL,             
           hThisInstance,     
           NULL             
           );
           i++;
    }
    i = 0;
    while(i < 10){
         hEditD[i] = CreateWindow(                   
           "edit",       
           "0",     
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           360,     
           100 + (25 * i),       
           70,               
           20,                 
           hwnd,       
           NULL,               
           hThisInstance,       
           NULL               
           );
           i++;
    }
    while(i < 20){
         hEditD[i] = CreateWindow(                   
           "edit",       
           "0",       
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           430,     
           100 + (25 * (i - 10)),       
           70,                 
           20,               
           hwnd,       
           NULL,               
           hThisInstance,       
           NULL             
           );
           i++;
    }
    while(i < 30){
         hEditD[i] = CreateWindow(                   
           "edit",       
           "0",     
           ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
           500,       
           100 + (25 * (i - 20)),     
           70,               
           20,                 
           hwnd,       
           NULL,               
           hThisInstance,     
           NULL             
           );
           i++;
    }
    i = 0;
    hwndBoton = CreateWindow(     /*el boton que al ser pulsado hace la simunacion*/             
           "button",     
           "Simulacion",       
           WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
           250,     
           400,       
           100,             
           20,                 
           hwnd,       
           NULL,             
           hThisInstance,     
           NULL                 
           );

    while (GetMessage (&messages, NULL, 0, 0))
    {
       
        TranslateMessage(&messages);

        DispatchMessage(&messages);
    }

 
    return messages.wParam;
}




LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int i = 0;
    static HINSTANCE hInstance;
    static HBITMAP fondo;
    char mensaje[200];
    static HDC hDC;
    static HDC hcDC;
    PAINTSTRUCT ps;
    switch (message)             
    {
        case WM_CREATE:
            hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
            fondo = LoadBitmap(hInstance, "fondo");/*cagar la imagen de fondo del archivo/
            break;
        case WM_PAINT:/*dibuja la ventana*/
            hDC = BeginPaint(hwnd, &ps);
            hcDC = CreateCompatibleDC(hDC);
            SelectObject(hcDC, fondo);
            BitBlt(hDC, 0, 0, 665, 600, hcDC, 0, 0, SRCCOPY);/*pone la imgagen de fondo*/
            ReleaseDC(hwnd, hcDC);
            DeleteDC(hcDC);
            hDC = GetDC(hwnd);
            SetBkColor(hDC, NEGRO);
            SetTextColor(hDC, ROJO);
            TextOut(hDC, 100, 60, "Tropa atacante", 14);/*escribe*/
            TextOut(hDC, 70, 80, "Cantidad", 8);
            TextOut(hDC, 140, 80, "Perecia %", 9);
            TextOut(hDC, 210, 80, "Moral %", 7);
            SetTextColor(hDC, 0xff8888);/*azul claro*/
            TextOut(hDC, 400, 60, "Tropa defensora", 15);
            TextOut(hDC, 360, 80, "Cantidad", 8);
            TextOut(hDC, 430, 80, "Perecia %", 9);
            TextOut(hDC, 500, 80, "Moral %", 7);
            SetTextColor(hDC, VERDE);
            TextOut(hDC, 0, 100, "leva", 4);
            TextOut(hDC, 0, 125, "recluta", 7);
            TextOut(hDC, 0, 150, "soldado", 7);
            TextOut(hDC, 0, 175, "arquero", 7);
            TextOut(hDC, 0, 200, "lancero", 7);
            TextOut(hDC, 0, 225, "ballestero", 10);
            TextOut(hDC, 0, 250, "caballero", 9);
            TextOut(hDC, 0, 275, "oficiale", 8);
            TextOut(hDC, 0, 300, "guardia", 7);
            TextOut(hDC, 360, 350, "casa", 4);
            TextOut(hDC, 430, 350, "castillo", 8);
            TextOut(hDC, 500, 350, "gran castillo", 13);
            break;
        case WM_COMMAND:
            if (HIWORD(wParam) == BN_CLICKED){/*cuando se pulsa el unico boton que hay*/
                i = 0;
                while(i < 27){/*obtiene de los controles edit del acacante*/
                    GetWindowText(hEditA[i], edit, 10);
                    sscanf(edit, "%d", &ta[i]);
                    i++;
                }
                i = 0;
                while(i < 30){/*del defensor*/
                    GetWindowText(hEditD[i], edit, 10);
                    sscanf(edit, "%d", &td[i]);
                    i++;
                }
                i = 0;
/*se hace las cuentas para saber el poder de ataque del atacante*/
                resa = (ta[i] * Leva * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Recluta * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Soldado * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Arquero * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Lancero * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Ballestero * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Caballeros * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Oficiales * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i++;
                resa += (ta[i] * Guardia_Personal * ta[i + 9] * (100 + ta[i + 18])) / 10000;
                i = 0;
/*del defensor*/
                resd = (td[i] * Leva * td[i + 10] * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Recluta * (td[i + 10]) * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Soldado * (td[i + 10]) * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Arquero * (td[i + 10]) * (100 + td[i + 20]) * (td[9] != 0 ? td[9] * 1.5 : 1) * (td[19] != 0 ? td[19] * 3 : 1) * (td[29] != 0 ? td[29] * 5 : 1)) / 10000;
                i++;
                resd += (td[i] * Lancero * td[i + 10] * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Ballestero * td[i + 10] * (100 + td[i + 20]) * (td[9] != 0 ? td[9] * 1.5 : 1) * (td[19] != 0 ? td[19] * 3 : 1) * (td[29] != 0 ? td[29] * 5 : 1)) / 10000;
                i++;
                resd += (td[i] * Caballeros * td[i + 10] * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Oficiales * td[i + 10] * (100 + td[i + 20])) / 10000;
                i++;
                resd += (td[i] * Guardia_Personal * td[i + 10] * (100 + td[i + 20])) / 10000;
                i = 0;                   
                hDC = GetDC(hwnd);
                SetBkColor(hDC, NEGRO);
                SetTextColor(hDC, VERDE);
                sprintf(mensaje, "      El atacante tiene un poder de %d y el defensor de %d      ", resa, resd); /*escribe el poder de ataque de cada uno*/
                TextOut(hDC, 200, 500, mensaje, strlen(mensaje));
                if(resa == resd){ /*si tienen el mismo poder*/
                    sprintf(mensaje, "   Empate   ");
                    TextOut(hDC, 300, 530, mensaje, strlen(mensaje));
                }
                else if(resa < resd){/*si el defensor tiene mas poder*/
                    sprintf(mensaje, "   El defensor gana   ");
                    TextOut(hDC, 300, 530, mensaje, strlen(mensaje));
                }
                else{/*si elatacante tiene mas poder*/
                    sprintf(mensaje, "   El atacante gana   ");
                    TextOut(hDC, 300, 530, mensaje, strlen(mensaje));
                }
            }
        break;
        case WM_DESTROY:
            PostQuitMessage (0);     
            break;
        default:                   
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

si lo quieren descargar (con la imagen de fondo) vallan a pedidos de software al post hago programas y ahi esta el link.

salu2

modificado: como hubo problemas por los comentarios en ingles, los saco y los pongo en castellano
« Última modificación: ſeptiembre 17, 2007, 10:00:34 por swatnio » En línea

Inside The Source Code




Necesitas ser usuario para ver los enlaces Crear Usuario  Hacer Sesion
Linux Registred User #460377
Páginas: [1] Ir Arriba Imprimir 
Comunidad Underground Hispana  |  Programacion  |  Programación  |  Carbide C/C#/C++  |  Tema: Simulador de batalla para el guaranpis, por Ni0 « anterior próximo »
Ir a:  


Ranking-Hits
Powered by SMF 1.1.6 | SMF © 2006-2007, Simple Machines LLC