Spiele Vorstellung: ::BallBlocks::
-
Sehr geehrtes Forum, ich habe mich jetzt schon lange mit C und C++ beschäftigt, und ein erstes C-Game Programmiert, was haltet ihr davon?
www.gamehighscores.kilu.de/BallBlocks/BallBlocks.exe
M.f.G. Developer_X
Merry Christmas!
-
Wenn du kein Troll bist dann zeig den Source incl. der Projektmappe her.
Ich klick da sicherlich nicht auf irgendeine .exe .
-
Developer_X schrieb:
me@home:~$ ./BallBlocks.exe bash: ./BallBlocks.exe: Permission denied me@home:~$ chmod a+x BallBlocks.exe me@home:~$ ./BallBlocks.exe run-detectors: unable to find an interpreter for ./BallBlocks.exe me@home:~$
Was mach ich falsch?
-
mngbd schrieb:
...
-
Hast du Windows? mngbd, ich habe das für Windows geschrieben,
ach ja, schau dir folgende Gleichung an:
Developer_X != Troll,
deshalb und das ist der Code, geht mit mir aber bitte nicht zu hart ins Gericht, ich bin erst Anfänger, dont forget!/** * Code by Kevin Riehl (alias Developer_X 2010) */ /////////////// #include <windows.h> #include <stdlib.h> #include <stdio.h> #define boolean short #define true 1 #define false 0 ///Global Variables////////// boolean ever_played = false; boolean game_running = true; boolean game_paused = false; boolean lamp_on = true; boolean tmr = true; boolean gmr = true; boolean amr = true; long seconds_played = 0; int zeile = 0; int bar_x = 36; int bar_width = 10; int pmsg1 = 0; int pmsg2 = 0; int ball_x = 40; int ball_y = 13; int old_x = 40; int old_y = 13; int mx = -1; int my = -1; int life = 3; long bytesSize = 0; struct rect { int X; int Y; int Width; int Height; } gameRect; ///////////////////////////// ///Functions////// void game_dialog(); void tut(); void playTutMusic(int *id); void about_game(); void playGamMusic(int *id); void countSize(); void about_auth(); void playAutMusic(int *id); void game(); void moveBall(); void checkLife(); void actualize(); void gameOver(); void init(); void makeBackground(int speed); void makeGameArea(int speed); void makeTitle(int speed); void setColor(WORD color); void time_counter(int *id); void setVars(); void drawInformation(); void setPosition(int x, int y); void keyInputChecker(int *id); void moveBar(int i); void pauseGame(int speed); void lampChange(int *id); void drawCenteredString(char c[],int length); ////////////////// ///Ask the User to Play//// void game_dialog() { boolean dialog = true; while(dialog) { fflush(stdin); system("Cls"); zeile = 5; setColor(15); drawCenteredString(":: Willkommen zu BallBlocks ::",30); drawCenteredString("",0); if(ever_played==true) drawCenteredString("<1> Nochmal Spielen",20); else drawCenteredString("<1> Spielen",11); drawCenteredString("<2> Anleitung zum Spielen",26); drawCenteredString("<3> Ueber das Spiel",19); drawCenteredString("<4> Ueber den Autor",19); drawCenteredString("<5> Beenden",11); drawCenteredString("",0); printf("\n"); int answer = 0; while(answer!=1&&answer!=2&&answer!=3&&answer!=4&&answer!=5) { answer = 0; fflush(stdin); printf("Geben Sie ihre Wahl an : "); scanf("%d",&answer); } switch(answer) { case 1: game();break; case 2: tut();break; case 3: about_game();break; case 4: about_auth();break; case 5: dialog = false;break; } fflush(stdin); } } ///////////////////// //Explains how to Play void tut() { tmr = true; system("Cls"); int thread = 0; _beginthread(playTutMusic,0,&thread); zeile = 5; setColor(10); drawCenteredString("Anleitung zum Spiel",19); drawCenteredString("",0); setColor(10); drawCenteredString("Steuerung :",11); setColor(11); drawCenteredString("Die Steuerung des Schlaegers erfolgt mit den Pfeiltasten.",57); drawCenteredString("",0); setColor(10); drawCenteredString("Ziel :",6); setColor(11); drawCenteredString("Der Ball muss auf dem Schlager aufkommen, und darf den Boden",60); drawCenteredString("nicht berühren sonst verliert man ein Leben. Man hat 3 Leben.",61); drawCenteredString("",0); setColor(14); drawCenteredString("Beliebige Taste zum Schliessen druecken",39); fflush(stdin); getch(); setColor(15); tmr = false; } void playTutMusic(int *id) { int speed = 100; int height = 1; int i = 0; while(tmr) { for(i=0;i<3;i++) { Beep(200*height,speed);if(tmr==false)break; Beep(100*height,speed);if(tmr==false)break; } Beep(300*height,speed);if(tmr==false)break; for(i=0;i<3;i++) { Beep(200*height,speed);if(tmr==false)break; Beep(100*height,speed);if(tmr==false)break; } Beep(300,speed);if(tmr==false)break; Sleep(speed); height++; if(height==5) height = 1; } } void about_game() { gmr = true; system("Cls"); int thread = 0; _beginthread(playGamMusic,0,&thread); setColor(7); drawCenteredString("Ueber das Spiel",15); drawCenteredString("",0); setColor(10); drawCenteredString("Dieses Spiel wurde in der Programmiersprache",44); drawCenteredString("\'C \' geschrieben.",17); countSize(); setColor(14); drawCenteredString("Beliebige Taste zum Schliessen druecken",39); fflush(stdin); getch(); setColor(15); gmr = false; } void playGamMusic(int *id) { int i = 0; while(gmr==true) { for(i=0;i<5000;i+=5) { if(i<2500) Beep(2500-i,20); else Beep(i,20); if(gmr==false)break; } } } void countSize() { bytesSize = 0; bytesSize += sizeof(ever_played); bytesSize += sizeof(game_running); bytesSize += sizeof(game_paused); bytesSize += sizeof(lamp_on); bytesSize += sizeof(tmr); bytesSize += sizeof(gmr); bytesSize += sizeof(amr); bytesSize += sizeof(seconds_played); bytesSize += sizeof(zeile); bytesSize += sizeof(bar_x); bytesSize += sizeof(bar_width); bytesSize += sizeof(pmsg1); bytesSize += sizeof(pmsg2); bytesSize += sizeof(gameRect); bytesSize += sizeof(ball_x); bytesSize += sizeof(ball_y); bytesSize += sizeof(old_x); bytesSize += sizeof(old_y); bytesSize += sizeof(mx); bytesSize += sizeof(my); bytesSize += sizeof(life); setPosition(20,20); printf("Verbrauch des Spieles in Bytes : %d Bytes",bytesSize); } void about_auth() { amr = true; system("Cls"); int thread = 0; _beginthread(playAutMusic,0,&thread); zeile = 10; setColor(5); drawCenteredString("Ueber den Autor",15); drawCenteredString("",0); setColor(10); drawCenteredString("Dieses Spiel wurde von Developer_X",35); drawCenteredString("alias Kevin Riehl geschrieben.",31); drawCenteredString("Copyright 2010 by Kevin Riehl",29); drawCenteredString("",0); setColor(14); drawCenteredString("Beliebige Taste zum Schliessen druecken",39); fflush(stdin); getch(); setColor(15); amr = false; } void playAutMusic(int *id) { int speed = 50; int height = 1; int i = 0; while(amr) { for(i=0;i<10000;i++) { Beep(i,speed);if(amr==false)break; Beep(100000-i,speed);if(amr==false)break; } } } ///This is the game Function////// ///which keeps the game running/// void game() { fflush(stdin); init(); while(game_running==true) { if(game_paused==false) { moveBall(); checkLife(); } actualize(); Sleep(1000/25); } } ////////////////// //Moves The Ball// void moveBall() { old_x = ball_x; old_y = ball_y; ball_x += mx; ball_y += my; if(ball_x<gameRect.X+1||ball_x>gameRect.X+gameRect.Width-2) { mx *= -1; Beep(500,200); } if(ball_y<gameRect.Y+1) { my *= -1; Beep(200,200); } if(ball_y>gameRect.Y+gameRect.Height-3) { if(ball_x<bar_x+bar_width&&ball_x>=bar_x) { my *= -1; Beep(1000,200); } else { my *= -1; life--; Beep(100,50); Beep(1000,50); Beep(100,50); Beep(1000,100); } } } void checkLife() { if(life==0) { gameOver(); } } void gameOver() { game_running = false; system("Cls"); zeile = 10; setColor(10); drawCenteredString("GameOver",8); setPosition(30,21); printf("You survived %d seconds. Congratulations!",seconds_played); Sleep(5000); game_dialog(); } ////////////////// //Draws Everything in the Game which has //to be re-drawn n-times void actualize() { // Draw Blinking Game Rect int a = 0; for(a=0;a<80;a++) { if((a+1)%2==0) if(lamp_on==true) setColor(12); else setColor(4); else if(lamp_on==true) setColor(4); else setColor(12); setPosition(a,0); if(a<33||a>47) printf("%c",4); } // Draw Game During setPosition(10,1); setColor(15); printf("Spieldauer : %4d Sekunden",seconds_played); // Draw Bar int x = 0; setColor(0); setPosition(gameRect.X,gameRect.Height+gameRect.Y-1); for(x=gameRect.X;x<gameRect.X+gameRect.Width;x++) { printf(" "); } setPosition(bar_x,gameRect.Height+gameRect.Y-1); setColor(15); for(x=0;x<bar_width;x++) { printf("-"); } // Draw ball setColor(0); setPosition(old_x,old_y); printf(" "); setColor(12); setPosition(ball_x,ball_y); printf("%c",29); // Draw Lifes setColor(12); setPosition(10,24); printf("Leben : "); setPosition(18,24); for(x=0;x<3;x++) if(x<life) printf("%c",1); else printf("%c",2); // Draw Pause Information int i = 0; if(pmsg1!=14||pmsg2!=26) { setColor(0); setPosition(33,14); for(i=0;i<14;i++) { printf("%c",0); } setPosition(27,15); for(i=0;i<26;i++) { printf("%c",0); } } setColor(10); char msg1[] = {"Spiel pausiert"}; char msg2[] = {"Um fortzufahren P druecken"}; setPosition(33,14); for(i=0;i<pmsg1;i++) { printf("%c",msg1[i]); } setPosition(27,15); for(i=0;i<pmsg2;i++) { printf("%c",msg2[i]); } } //////////////// ///Inits the Game and prepares variables //Main initialiser void init() { setVars(); makeBackground(3); makeGameArea(3); makeTitle(30); drawInformation(); int thread = 0; _beginthread(keyInputChecker,0,&thread); thread++; _beginthread(time_counter,0,&thread); thread++; _beginthread(lampChange,0,&thread); } //Prepares the Global Variables void setVars() { ever_played = true; gameRect.X = 3; gameRect.Y = 3; gameRect.Width = 74; gameRect.Height = 20; game_running = true; life = 3; CONSOLE_CURSOR_INFO ci = {10,FALSE}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE) , &ci); } //Draws the Background void makeBackground(int speed) { system("Cls"); char symbol = 176; int a = 0; int b = 0; for(a = 0;a<26;a++) { for(b = 0;b<80;b++) { setPosition(b,a); setColor(3); if(a!=gameRect.Height+gameRect.Y-1) printf("%c",symbol); Sleep(speed); Beep(a*(b+1),speed); } } symbol = 177; for(a = 0;a<26;a++) { for(b = 0;b<80;b+=2) { setPosition(b,a); setColor(11); if(a!=gameRect.Height+gameRect.Y-1) printf("%c",symbol); Sleep(speed); Beep(200*a,speed); } } COORD coords; coords.X = 0; coords.Y = 0; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE) , coords); } //Draws the GameArea void makeGameArea(int speed) { char symbol = 176; int a = 0; int b = 0; setColor(0); for(b = gameRect.X;b<gameRect.X+gameRect.Width;b++) { for(a = gameRect.Y;a<gameRect.Y+gameRect.Height;a++) { setPosition(b,a); printf("%c",symbol); Sleep(speed); Beep(((gameRect.Y+gameRect.Height)*(gameRect.X+gameRect.Width))-(a*(b+1)),speed); } } // Draw Bar setPosition(bar_x,gameRect.Height+gameRect.Y-1); int x = 0; setColor(15); for(x=0;x<bar_width;x++) { printf("-"); Sleep(speed*4); if((x+1)%2==0) Beep(300*x,speed*4); else Beep(300*(bar_width-x),speed*4); } } // Draws The Title void makeTitle(int speed) { setColor(15); char c[] = {"::BallBlocks::"}; setPosition(33,0); int i = 0; for(i=0;i<14;i++) { printf("%c",c[i]); Sleep(speed); if((i+1)%2==0) Beep(300*(14-i),speed); else Beep(300*(i),speed); } } //Draws the GameInformation void drawInformation() { setPosition(50,1); setColor(0); char info1[] = {"Zum Pausieren P druecken"}; char info2[] = {"Zum Beenden Q druecken"}; int i = 0; setColor(15); for(i = 0;i<25;i++) { printf("%c",info1[i]); Beep(i*10,100); Sleep(100); } setPosition(50,2); i = 0; for(i = 0;i<25;i++) { printf("%c",info2[i]); Beep(220-(i*10),100); Sleep(100); } } ///Threads running while the game is running //Time Counter//// void time_counter(int *id) { while(game_running==true) { if(game_paused==false) { seconds_played++; Sleep(1000); } } } ////////////////// //Userinput Checker checks User Input void keyInputChecker(int *id) { while(game_running==true) { int typed_key = getch(); if(typed_key==75&&game_paused==false) // ArrowsKey_Left { moveBar(-1); } else if(typed_key==77&&game_paused==false) // ArrowKey_Right { moveBar(+1); } else if(typed_key==113) // Quit Game { } else if(typed_key==112) // Pause Game { pauseGame(20); } } } //////////////////////////////////////// //LampChange to make the blink effect void lampChange(int *id) { while(game_running) { if(lamp_on==true) lamp_on = false; else lamp_on = true; Sleep(500); } } ////////////////// ///Functions that are used in the Game //Function to Set the Color//// void setColor(WORD color) { SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), color ); } //////////////////////////////// //Function to Set the Position in Console void setPosition(int x, int y) { COORD coords; coords.X = x; coords.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE) , coords); } ////////////////// //Function to moveThe Bar void moveBar(int i) { // Move Bar if(i==-1&&bar_x-1>=gameRect.X) { bar_x--; } else if(i==+1&&bar_x+1<=gameRect.X+gameRect.Width-bar_width) { bar_x++; } } ////////////////// //Function to Pause and to Continue Game void pauseGame(int speed) { if(game_paused==false) { game_paused = true; int i = 0; char msg1[] = {"Spiel pausiert"}; char msg2[] = {"Um fortzufahren P druecken"}; for(i=0;i<14;i++) { pmsg1++; if((i+1)%2==0) Beep(300*(14-i),speed); else Beep(300*(i),speed); Sleep(speed); } for(i=0;i<26;i++) { pmsg2++; if((i+1)%2==0) Beep(300*(26-i),speed); else Beep(300*(i),speed); Sleep(speed); } } else if(game_paused==true) { int i = 0; char symb = 0; for(i=0;i<14;i++) { pmsg1--; if((i+1)%2==0) Beep(300*(14-i),speed); else Beep(300*(i),speed); Sleep(speed); } for(i=0;i<26;i++) { pmsg2--; if((i+1)%2==0) Beep(300*(26-i),speed); else Beep(300*(i),speed); Sleep(speed); } game_paused = false; } } ////////////////// void drawCenteredString(char c[], int length) { setPosition(40-length/2,zeile); int i = 0; for(i=0;i<length;i++) { printf("%c",c[i]); Sleep(75); } zeile++; } ///Main/////////// int main() { game_dialog(); return 0; } ///////////////////
-
Developer_X schrieb:
Hast du Windows? mngbd, ich habe das für Windows geschrieben,
ach ja, schau dir folgende Gleichung an:
Developer_X != Troll,
deshalb und das ist der Code, geht mit mir aber bitte nicht zu hart ins Gericht, ich bin erst Anfänger, dont forget!Dies ist ein Forum für C und nicht für Windows.
-
Der Code ist zweifellos C wenn auch nicht standardkonform, fflush(stdin),getch,gotoxy,beginthread und dergleichen deuten auf MSVC hin.
Die ncurses-Bibliothek gibt es auch für Windows, die bietet für all deine selbstgebastelten Konsolendinge was Professionelles an.
-
Aber für nen Anfänger nicht schlecht oder?
-
Ja ja, für einen Anfänger ganz gut aber ein Codereview wirst du wohl wenn überhaupt im Forum Projekte o.ä. bekommen.
-
Wutz schrieb:
Ja ja, für einen Anfänger ganz gut..
Woha, da hatte ich mich so auf drei Seiten lange flames gefreut und dann das..
:xmas1: