Created
January 18, 2015 01:50
-
-
Save zrobit/88c7e83be592ce472e09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PONG.cpp : main project file. | |
| #include "stdafx.h" | |
| #include <conio.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| #include <windows.h> | |
| using namespace System; | |
| void intro(){ | |
| int n,x=0,y=0; | |
| while(!_kbhit()) | |
| { | |
| Console::SetCursorPosition(x,y++); | |
| n=Random::Random().Next(1,5); | |
| Sleep(30); | |
| if(n==1) | |
| Console::ForegroundColor=ConsoleColor::Red; | |
| if(n==2) | |
| Console::ForegroundColor=ConsoleColor::Green; | |
| if(n==3) | |
| Console::ForegroundColor=ConsoleColor::Yellow; | |
| if(n==4) | |
| Console::ForegroundColor=ConsoleColor::Blue; | |
| printf(" \n"); | |
| printf(" \n"); | |
| printf(" PPPPPPP OOOOOOO NNNNNN GGGGGG \n"); | |
| printf(" PPPPPPPP OOOOOOOOO NNNNNNNN GGGGGGG \n"); | |
| printf(" PPPPPPPPP OOOOOOOOOOO NNNNNNNNNN GGGGGGGG \n"); | |
| printf(" PPP PPP OOOO OOOO NNN NNN GGGG \n"); | |
| printf(" PPP PPP OOOO OOOO NNN NNN GGGG \n"); | |
| printf(" PPP PPP OOO OOO NNN NNN GGG \n"); | |
| printf(" PPPPPPPPP OOO OOO NNN NNN GGG \n"); | |
| printf(" PPPPPPPP OOO OOO NNN NNN GGG GGGG \n"); | |
| printf(" PPPPPPP OOO OOO NNN NNN GGG GGGG \n"); | |
| printf(" PPP OOO OOO NNN NNN GGG GGGG \n"); | |
| printf(" PPP OOOO OOOO NNN NNN GGGG GGG \n"); | |
| printf(" PPP OOOO OOOO NNN NNN GGGG GGG \n"); | |
| printf(" PPP OOOOOOOOOOOO NNN NNN GGGGGGGG \n"); | |
| printf(" PPP OOOOOOOOOO NNN NNN GGGGGGG \n"); | |
| printf(" PPP OOOOOOOO NNN NNN GGGGGG \n"); | |
| printf(" \n"); | |
| Console::SetCursorPosition(9,18); | |
| printf("PRESIONE LA TECLA S(START GAME) PARA COMENZAR A JUGAR!!"); | |
| printf("\n\n\n\n"); | |
| printf(" %c 2009 UPC Peru, all rights reserved%c\n",184,169); | |
| printf(" Created By Gerardo Miranda and Javier Kometter\n"); | |
| } | |
| } | |
| char user(){ | |
| char inicial; | |
| printf("INGRESA TU NOMBRE DE USUARIO: "); | |
| flushall(); | |
| scanf("%c",&inicial); | |
| return inicial; | |
| } | |
| void escenario(){ | |
| int x=0, y=0, dx,dy; | |
| Console::SetWindowSize(80,40); | |
| Console::SetWindowPosition(0,0); | |
| Console::BackgroundColor=ConsoleColor::White; | |
| Console::Clear(); | |
| Console::ForegroundColor=ConsoleColor::Black; | |
| while(1){ | |
| Console::SetCursorPosition(x,y); | |
| if(x==0&&y==1){printf("%c",186);break;} | |
| if(x==0&&y==0){printf("%c",201);dx=1;dy=0;} | |
| if(x==79&&y==0){printf("%c",187);dx=0;dy=1;} | |
| if(x==79&&y==38){printf("%c",188);dx=-1;dy=0;} | |
| if(x==0&&y==38){printf("%c",200);dx=0;dy=-1;}; | |
| if(x!=0 && x!=79 &&y==0) printf("%c",205); | |
| if(x!=0 && x!=79 &&y==38) printf("%c",205); | |
| if(x==0 && y!=0 && y!=38) { | |
| if(x==0&&y==5)printf("%c",204); | |
| else printf("%c",186); | |
| }; | |
| if(x==79 && y!=0 && y!=38){ | |
| if(x==79&&y==5)printf("%c",185); | |
| else printf("%c",186); | |
| }; | |
| x= x + dx; | |
| y= y + dy; | |
| } | |
| x=1; | |
| y=5; | |
| Console::SetCursorPosition(x,y); | |
| while(x>=1&&x<=79){ | |
| printf("%c",205); | |
| Console::SetCursorPosition(x++,y); | |
| } | |
| } | |
| void verticales(int Y, int dir){ | |
| int largo=10; | |
| if(dir==-1){ | |
| Console::SetCursorPosition(2,Y+largo); | |
| printf(" "); | |
| Console::SetCursorPosition(77,Y+largo); | |
| printf(" "); | |
| } | |
| if(dir==1){ | |
| Console::SetCursorPosition(2,Y-1); | |
| printf(" "); | |
| Console::SetCursorPosition(77,Y-1); | |
| printf(" "); | |
| } | |
| for(int i=0;i<largo;i++){ | |
| Console::SetCursorPosition(2,Y+i); | |
| printf("%c",206); | |
| Console::SetCursorPosition(77,Y+i); | |
| printf("%c",206); | |
| } | |
| } | |
| //funcion barras horizontales | |
| void horizontales(int X, int dir){ | |
| int largo=10; | |
| if(dir==-1){ | |
| Console::SetCursorPosition(X+largo,6); | |
| printf(" "); | |
| Console::SetCursorPosition(X+largo,37); | |
| printf(" "); | |
| } | |
| if(dir==1){ | |
| Console::SetCursorPosition(X-1,6); | |
| printf(" "); | |
| Console::SetCursorPosition(X-1,37); | |
| printf(" "); | |
| } | |
| for(int i=0;i<largo;i++){ | |
| Console::SetCursorPosition(X+i,6); | |
| printf("="); | |
| Console::SetCursorPosition(X+i,37); | |
| printf("="); | |
| } | |
| } | |
| //fin funcion horizontales | |
| void scoreVida(){ | |
| } | |
| int main(array<System::String ^> ^args) | |
| { | |
| int posX=35, posY=15, x, y, score=0, vidas=10; | |
| float a=7.0, b=7.0, dx=0.1, dy=0.1; | |
| char key, userIni; | |
| intro(); | |
| while(1){ | |
| if(_kbhit())if(_getch()=='s'){ | |
| Console::Clear(); | |
| break; | |
| } | |
| } | |
| userIni=user(); | |
| escenario(); | |
| verticales(posY,0); | |
| horizontales(posX,0); | |
| while(vidas>0){ | |
| if(_kbhit()){ | |
| key=_getch(); | |
| switch(key){ | |
| case 72:if(posY==7)verticales(posY,-1); | |
| else verticales(--posY,-1); | |
| break; | |
| case 80:if(posY==27)verticales(posY,1); | |
| else verticales(++posY,1); | |
| break; | |
| case 77:if(posX==67)horizontales(posX,1); | |
| else horizontales(++posX,1); | |
| break; | |
| case 75:if(posX==3)horizontales(posX,-1); | |
| else horizontales(--posX,-1); | |
| break; | |
| }//fin de captura de teclas | |
| } | |
| //pelota | |
| x=posX; | |
| y=posY; | |
| Console::SetCursorPosition(a,b); | |
| printf(" "); | |
| //restriccion horizontal | |
| if(((x<=int(a)&&int(a)<x+3)||(x+7<int(a)&&int(a)<=x+10))&&(int(b)==7||int(b)==36)){ | |
| dy*=-1; | |
| score+=100; | |
| Console::Beep(); | |
| } | |
| if((x+3<=int(a)&&int(a)<=x+7)&&(int(b)==7||int(b)==36)){ | |
| dy*=-1; | |
| score+=100; | |
| Console::Beep(); | |
| } | |
| //restriccion vertical | |
| if(((y<=int(b)&&int(b)<y+3)||(y+7<int(b)&&int(b)<=y+10))&&(int(a)==3||int(a)==76)){ | |
| dx*=-1; | |
| score+=100; | |
| Console::Beep(); | |
| } | |
| if((y+3<=int(b)&&int(b)<=y+7)&&(int(a)==3||int(a)==76)){ | |
| dx*=-1; | |
| score+=100; | |
| Console::Beep(); | |
| } | |
| //restriccion de salida de marco | |
| if((3<=int(a)&&int(a)<=78&&int(b)==6)||(3<=int(a)&&int(a)<=77&&int(b)==37)){ | |
| Console::SetCursorPosition(40,3); | |
| vidas--; | |
| if (vidas==0) | |
| printf("PERDISTE %c", userIni); | |
| }; | |
| if((6<=int(b)&&int(b)<=37&&int(a)==2)||(6<=int(b)&&int(b)<=37&&int(a)==78)){ | |
| Console::SetCursorPosition(40,3); | |
| vidas--; | |
| if (vidas==0) | |
| printf("perdiste %c", userIni); | |
| }; | |
| a+=dx; | |
| b+=dy; | |
| Console::SetCursorPosition(a,b); | |
| printf("%c",15); | |
| Console::SetCursorPosition(3,2); | |
| printf("%d",score); | |
| Console::SetCursorPosition(25,2); | |
| printf("%d",vidas); | |
| Sleep(10); | |
| //fin depelota | |
| } | |
| _getch(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment