All pastes #819678 Raw Edit

pong

public c v1 · immutable
·published 2007-12-17 03:24 UTC
rendered paste body
/*################################################################################################################################################################ Pong,Clasico juego del pong                                               #### Copyright (C) <2007>  <Gora>                                              ####                                                                           ####   This program is free software: you can redistribute it and/or modify    ####   it under the terms of the GNU General Public License as published by    ####   the Free Software Foundation, either version 3 of the License, or       ####   (at your option) any later version.                                     ####                                                                           ####   This program is distributed in the hope that it will be useful,         ####   but WITHOUT ANY WARRANTY; without even the implied warranty of          ####   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           ####   GNU General Public License for more details.                            ####                                                                           ####   Software name: Pong                                                     ####   Date         : 12/11/2007                                               ####   Programmer   : Gora                                                     ####   Description  : Juega el divertido juego del pong                        ################################################################################################################################################################                          *///LIBRERIAS#include <stdio.h>#include <stdlib.h>#include <conio2.h>#include <time.h>#include <windows.h>#define MAXX 79#define MINX 2#define MAXY 23#define MINY 3#include <mmsystem.h>#pragma comment(lib, "winmm32.lib")//FUNCION introvoid intro(){          int j=0;     char op,resp;     char soundfile[] = "C:/Pong/intro2.wav";     PlaySound(soundfile,NULL,SND_FILENAME|SND_ASYNC);      for(j=0;j<=5;j++)     {       Sleep(200);       clrscr();         gotoxy(35,5);     textcolor(RED);     printf("\n                  ##########################################");     printf("\n                  ###           Gora & Danthux           ###");     printf("\n                  ###              Present...            ###");     printf("\n                  ##########################################");       Sleep(50);       printf("\n");       printf("\n");       printf("\n");       printf("\n");       printf("                      |||||||| |||||||| ||    || ||||||||     \n");       printf("                      ||    || ||    || |||   || ||           \n");       printf("                      ||    || ||    || || |  || ||  ||||     \n");       printf("                      |||||||| ||    || ||  | || ||    ||     \n");       printf("                      ||       |||||||| ||   ||| ||||||||     \n");       printf("                              R E V O L U T I O N             \n");       textcolor(LIGHTGRAY);             }}//ESTRUCTURA DE DATOSstruct datos {      char nombre[20];      int puntos;};//FUNCION GUARDAR ARCHVIO DE DATOSvoid recordal ( FILE *archivo, int punto){	struct datos a;	char resp;   archivo = fopen ("Record.txt", "ab");	if (archivo == NULL)    {        printf("Falla al abrir el archivo \n");        exit (EXIT_FAILURE);    }    do	{	        clrscr();        printf(" \n Escriba Su Nombre/Nick: ");		fflush(stdin);gets (a.nombre);        printf(" \n Su nombre de Usuario es: %s, Esta Correcto? [Enter]",a.nombre);        gotoxy(15,24);        printf("\n Si su nombre no es Correcto presione cualquier tecla");         resp=getch();}while(resp!=13);	fflush(stdin);    a.puntos=punto;    clrscr();    gotoxy(35,5);    printf("\n            Felicitaciones %s has marcado un nuevo record!",a.nombre);    printf("\n                          Tu Record es de %d",a.puntos);    Sleep(2000);    fwrite (&a, sizeof(a), 1, archivo);     fclose ( archivo );}//FUNCION MOSTRAR DATOS ARCHIVOvoid lectura ( FILE   *archivo ){	    struct datos a;	archivo = fopen ("Record.txt", "rb");		if (archivo == NULL)    {        printf("Falla al abrir el archivo \n");        exit (EXIT_FAILURE);    }    clrscr();    printf ( " \n                    Los record son: \n ");	while ( ! feof ( archivo ) )      //mientras no termine el archivo realice!	{		fread (&a, sizeof (a), 1, archivo );		if ( feof ( archivo ) )   break; //es un seguro po si el archivo esta corrupto		printf("\n");		printf("\n");        printf("\n        Nombre Jugador: %s",a.nombre);		printf("\n        Record        : %d",a.puntos);	       }	if(kbhit())	{    fclose ( archivo );    }getch();}//MENUint menu(int rm){  char op;  int x=32,y=9;   clrscr();  textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##          *   MENU PONG   *        ##");   printf("\n                     ##                                   ##");   printf("\n                     ##             Jugar Pong.           ##");   printf("\n                     ##                                   ##");      printf("\n                     ##            Instrucciones          ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Records             ##");   printf("\n                     ##                                   ##");   printf("\n                     ##                Salir              ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");                  gotoxy(x=x-2,y=y-2);textcolor(LIGHTGRAY);   printf("===>");  do{  op=getch();    if((op==72)&&(x>=32)&&(y>=9))  {   clrscr();textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##          *   MENU PONG   *        ##");   printf("\n                     ##                                   ##");   printf("\n                     ##             Jugar Pong.           ##");   printf("\n                     ##                                   ##");      printf("\n                     ##            Instrucciones          ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Records             ##");   printf("\n                     ##                                   ##");   printf("\n                     ##                Salir              ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");   gotoxy(x=x-2,y=y-2);textcolor(LIGHTGRAY);   printf("===>");      }  else  if((op==80)&&(x<=38)&&(y<=12))  {    clrscr();textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##          *   MENU PONG   *        ##");   printf("\n                     ##                                   ##");   printf("\n                     ##             Jugar Pong.           ##");   printf("\n                     ##                                   ##");      printf("\n                     ##            Instrucciones          ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Records             ##");   printf("\n                     ##                                   ##");   printf("\n                     ##                Salir              ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");   gotoxy(x=x+2,y=y+2);textcolor(LIGHTGRAY);   printf("===>");   }      }while(op!=13);fflush(stdin);rm=x;return (rm);}//FUNCION INSTRUCCIONESvoid ayuda(){  clrscr();  textcolor(RED);  printf("\n###############################################################################");  printf("\n###############################################################################");  printf("\n##                                                                           ##");  printf("\n##                               INSTRUCCIONES                               ##");  printf("\n##                   Copyright (C) <2007>  <Gora & Danthux>                  ##");  printf("\n##                                                                           ##");  printf("\n##      1) Para poder desplazarte con las barras o Paddles usted debe        ##");  printf("\n##         presionar la barra de direccion arriba o abajo asi tambien        ##");  printf("\n##         como en el Menu De juego.                                         ##");  printf("\n##                                                                           ##");  printf("\n##      2) La finalidad de este clasico juego llamado PONG es la de          ##");  printf("\n##         evitar que la pelota salga de los margenes del juego en           ##");  printf("\n##         este caso que la pelota este atras de las barras o paddles        ##");  printf("\n##                                                                           ##");  printf("\n##      3) Los puntos seran contados cada vez que la pelota golpe            ##");  printf("\n##         la pared opuesta a la barrita o Paddle, al llegar al maximo       ##");  printf("\n##         de puntos usted podra entrar al Salon de la Fama y su record      ##");  printf("\n##         sera exhibido para todos los usuarios.                            ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                Para volver al menu presione cualquier tecla               ##");  printf("\n###############################################################################");  printf("\n###############################################################################");  textcolor(LIGHTGRAY);getch();}//CREDITOSvoid creditos(){ textcolor(RED);  printf("\n###############################################################################");  printf("\n###############################################################################");  printf("\n##                                                                           ##");  printf("\n##                                  CREDITOS                                 ##");  printf("\n##                   Copyright (C) <2007>  <Gora & Danthux>                  ##");  printf("\n##                                                                           ##");  printf("\n##             Los agradecimientos seran totalmente para Usted por           ##");  printf("\n##         preferirnos y darnos la oportunidad de crear entretenimientos     ##");  printf("\n##                               para su familia.                            ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                              xxgoraxx@gmail.com                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                                                                           ##");  printf("\n##                     Gracias por jugar Pong Revolution                     ##");  printf("\n###############################################################################");  printf("\n###############################################################################");   textcolor(LIGHTGRAY);getch();}//LIMITES del area de JUEGovoid limites(){  int j,i;  for(i=MINX-1;i<=MAXX+1;i++)  {     for(j=MINY-1;j<=MAXY+1;j++)      {          gotoxy(i,j);          if(j==MINY-1||j==MAXY+1||i==MINX-1||i==MAXX+1)          {              //printf("%c",219);          }          else              printf(" ");      }  }}//Funcion Esperarvoid esperar(float temp){time_t t1;t1=clock();while((clock()-t1)<temp);}int barra(int a){  char key;char car=219;  if(kbhit())  {            key=getch();         if((key==72)&&(a!=MINY+2))      {            clrscr();            gotoxy(MINX+4,a=a-1);            printf("%c",car);            gotoxy(MINX+4,a=a-1);            printf("%c",car);            gotoxy(MINX+4,a=a-1);            printf("%c",car);            gotoxy(MINX+4,a=a-1);            printf("%c",car);                  }      if((key==80)&&(a!=MAXY-2))      {          clrscr();          gotoxy(MINX+4,a=a+1);          printf("%c",car);          gotoxy(MINX+4,a=a+1);          printf("%c",car);          gotoxy(MINX+4,a=a+1);          printf("%c",car);          gotoxy(MINX+4,a=a+1);          printf("%c",car);      }  }return(a);}//MOVIMIENTO DE LA PELOTAvoid movimiento(int mov,int vel){   FILE  *arch;    char car=219;   char soundfile[] = "C:/Pong/excelent.wav";   char soundfile1[] = "C:/Pong/start.wav";   char soundfile2[] = "C:/Pong/unstoppable.wav";   char soundfile3[] = "C:/Pong/dominating.wav";   char soundfile4[] = "C:/Pong/homer.wav";  int varx=1,vary=1,cont=0;  int x=40,y=13,punto=0;  int a=13,conta=3;   //LIMITES  limites();            textcolor(LIGHTGRAY);            gotoxy(6,13);            printf("%c",car);            gotoxy(6,14);            printf("%c",car);            gotoxy(6,15);            printf("%c",car);            gotoxy(6,16);            printf("%c",car);while(cont<mov)  {a=barra(a);    if (cont!=0)    {       gotoxy(x-varx,y-vary);       printf(" ");    }  //Paso a PASo x,y,a  //printf(" x=%d y=%d a=%d",x,y,a);  //getch();    cont++;    gotoxy(25,1);    printf("   vidas %d/3     Jugador  ==>   %d/10  ",conta,punto);    gotoxy(x,y);    textcolor(RED);    printf("%c",2);    textcolor(LIGHTGRAY);    esperar(vel);    if(x==MINX)      {      varx=1;      conta--;      PlaySound(soundfile4,NULL,SND_FILENAME|SND_ASYNC);      }else       if((y==a-1)||(y==a+1)||(y==a-2)||(y==a+2))           {            if(x==7)                          {             varx=1;             PlaySound(soundfile1,NULL,SND_FILENAME|SND_ASYNC);            }           }            if(conta==0)         {         clrscr();         gotoxy(25,9);         printf("Ouch... has perdido....");         gotoxy(21,23);         printf("***Para volver al menu presiona cualquier tecla***");         getch();         break;         }                 if(x==MAXX)         {         varx=-1;         PlaySound(soundfile1,NULL,SND_FILENAME|SND_ASYNC);         punto++;         }         if(punto==10)         {          clrscr();          gotoxy(29,9);          printf("Felicitaciones Has GANADO!!");          Sleep(2000);          recordal(arch,punto);          gotoxy(21,23);          printf("***Para volver al menu presiona cualquier tecla***");                    getch();          break;         }   if(y==MINY)         {         vary=1;         }    if(y==MAXY)         {         vary=-1;         }    x=x+varx;    y=y+vary;}}//FUNCION MENU DIFICULTADint menud(int rd){  char op;  int x=32,y=7;  char soundfile1[] = "C:/Pong/dificultad.wav";  char soundfile[] = "C:/Pong/destiny.wav";   clrscr();textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##       *   DIFICULTAD PONG   *     ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Papita              ##");   printf("\n                     ##                                   ##");      printf("\n                     ##               Normal              ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Peluo!!             ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");  PlaySound(soundfile,NULL,SND_FILENAME|SND_ASYNC);   do{  op=getch();    if((op==72)&&(y>7))  {   clrscr();textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##       *   DIFICULTAD PONG   *     ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Papita              ##");   printf("\n                     ##                                   ##");      printf("\n                     ##               Normal              ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Peluo!!             ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");   gotoxy(x,y=y-2);textcolor(LIGHTGRAY);   printf("===>");      }  else  if((op==80)&&(y<11))  {    clrscr();textcolor(RED);   printf("\n                     #######################################");   printf("\n                     #######################################");   printf("\n                     ##                                   ##");   printf("\n                     ##       *   DIFICULTAD PONG   *     ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Papita              ##");   printf("\n                     ##                                   ##");      printf("\n                     ##               Normal              ##");   printf("\n                     ##                                   ##");   printf("\n                     ##               Peluo!!             ##");   printf("\n                     ##                                   ##");   printf("\n                     #######################################");   printf("\n                     #######################################");   gotoxy(x,y=y+2);textcolor(LIGHTGRAY);   printf("===>");   }      }while(op!=13);fflush(stdin);rd=y;return (rd);}//FUNCION PRINCIPALint main(){ int rd,rm,aa,ad;  int vel,movi=1000000;      FILE  *arch;    intro();    do{aa=menu(rm);if(aa==30){                    ad=menud(rd);                      if(ad==7)            {             vel=120;            }           if(ad==9)           {             vel=75;           }            if(ad==11)           {           vel=40;           }              system("cls");            movimiento(movi,vel);}       if(aa==32)    {     ayuda();    }if(aa==34)    {     lectura(arch);    }}while(aa!=36);clrscr();creditos();getch();return(0);}