mein schiffeversenken mit animationen!
-
hi.
wollte euch mal mein schiffe versenken zeigen.
hier der code. könnts ja selbst compilen.
cya#include<stdio.h> #include<stdlib.h> int shipsize, wrong, pl1win = 15, pl2win = 15; int fieldship[2][10][10] = {0}, fieldshot[2][10][10] = {0}; int main() { int player; void title(); /* Places title on screen*/ void ships(int); /* Lets you place your ships*/ void play_board(int); /* Places Playboard on screen*/ void error(); /* Places error messages on screen*/ int hit_miss(int); /* Checks if you hit or miss*/ char transfer(char); /* Transfers your coordinates*/ for(player = 1 ; player <= 2 ; player++) { title(); shipsize = 5; printf("\n\nPlayer %d\n\n", player); system("pause"); system("cls"); do { title(); play_board(player); ships(player); } while(shipsize >= 1); } player = 1; do { title(); printf("\n\nPlayer %d\n\n", player); system("pause"); system("cls"); title(); play_board(player); player = hit_miss(player); if(pl1win == 0 || pl2win == 0) { printf("\n\nPlayer %d has won\n\n", player); system("pause"); break; } if(player == 1) { player = 2; } else { player = 1; } system("cls"); } while(pl1win != 0 || pl2win != 0); } void title() { printf("\n"); printf("\t %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n", 218, 196, 196, 191, 218, 196, 196, 191, 218, 196, 196, 191, 218, 196, 196, 191, 218, 191, 218, 196, 196, 191, 218, 196, 196, 191, 218, 191, 218, 191, 218, 191, 218, 196, 196, 191, 218, 196, 196, 191); printf("\t %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n", 179, 218, 191, 179, 179, 218, 191, 179, 192, 191, 218, 217, 192, 191, 218, 217, 179, 179, 179, 218, 196, 217, 179, 218, 196, 217, 179, 179, 179, 179, 179, 179, 179, 218, 191, 179, 179, 218, 196, 217); printf("\t %c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n", 179, 192, 217, 179, 179, 192, 217, 179, 179, 179, 179, 179, 179, 179, 179, 192, 196, 191, 179, 192, 196, 191, 179, 192, 217, 179, 179, 179, 179, 192, 217, 179, 179, 192, 196, 191); printf("\t %c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c \n", 179, 218, 191, 179, 179, 218, 191, 179, 179, 179, 179, 179, 179, 179, 179, 218, 196, 217, 192, 196, 191, 179, 179, 218, 191, 179, 179, 179, 179, 218, 196, 217, 192, 196, 191, 179); printf("\t %c%c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c \n", 179, 192, 217, 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, 192, 196, 191, 179, 192, 196, 191, 218, 196, 217, 179, 179, 179, 179, 179, 179, 179, 179, 179, 218, 196, 217, 179); printf("\t %c%c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c \n", 192, 196, 196, 217, 192, 217, 192, 217, 192, 217, 192, 217, 192, 196, 196, 217, 192, 196, 196, 217, 192, 196, 196, 217, 192, 217, 192, 217, 192, 217, 192, 217, 192, 196, 196, 217); printf("\n\n\n"); } void ships(int player) { int i, j, ship_x, direction; char ship_y; j = 0; printf("\n"); printf("Size %d ship ", shipsize); ship_y = getch(); printf("%c", ship_y); ship_y = transfer(ship_y); scanf("%d", &ship_x); printf("Up, Down, Left or Right? "); direction = getch(); printf("%c", direction); switch(direction) { default: { wrong = 2; error(); break; } case 'u': case 'U': { for(i = ship_y ; i > ship_y - shipsize ; i--) { if(fieldship[player - 1][i][ship_x - 1] == 'X') { j = 1; break; } } if(ship_y - shipsize >= -1 && j == 0) { for(i = ship_y ; i > ship_y - shipsize ; i--) { fieldship[player - 1][i][ship_x - 1] = 'X'; } shipsize -= 1; break; } else { wrong = 1; error(); break; } } case 'd': case 'D': { for(i = ship_y ; i < ship_y + shipsize ; i++) { if(fieldship[player - 1][i][ship_x - 1] == 'X') { j = 1; break; } } if(ship_y + shipsize <= 10 && j == 0) { for(i = ship_y ; i < ship_y + shipsize ; i++) { fieldship[player - 1][i][ship_x - 1] = 'X'; } shipsize -= 1; break; } else { wrong = 1; error(); break; } } case 'l': case 'L': { for(i = ship_x ; i > ship_x - shipsize ; i--) { if(fieldship[player - 1][ship_y][i - 1] == 'X') { j = 1; break; } } if(ship_x - shipsize >= 0 && j == 0) { for(i = ship_x ; i > ship_x - shipsize ; i--) { fieldship[player - 1][ship_y][i - 1] = 'X'; } shipsize -= 1; break; } else { wrong = 1; error(); break; } } case 'r': case 'R': { for(i = ship_x ; i < ship_x + shipsize ; i++) { if(fieldship[player - 1][ship_y][i - 1] == 'X') { j = 1; break; } } if(ship_x + shipsize <= 11 && j == 0) { for(i = ship_x ; i < ship_x + shipsize ; i++) { fieldship[player - 1][ship_y][i - 1] = 'X'; } shipsize -= 1; break; } else { wrong = 1; error(); break; } } } system("cls"); } void play_board(int player) { int i, j, k; printf("\t\t"); for(i = 0 ; i < 10 ; i++) { printf(" %2d", i + 1); } printf("\n\t\t %c", 218); for(i = 0 ; i < 10 ; i++) { if(i != 9) { printf("%c%c%c%c", 196, 196, 196, 194); } else { printf("%c%c%c%c", 196, 196, 196, 191); } } printf("\n"); for(i = 0 ; i < 10 ; i++) { printf("\t\t%c%c", i + 65, 179); for(j = 0 ; j < 10 ; j++) { if(fieldship[player - 1][i][j] != 0 || shipsize == 0) { if(shipsize == 0) { printf(" %c %c", fieldshot[player - 1][i][j], 179); } else { printf(" %c %c", fieldship[player - 1][i][j], 179); } } else { printf(" %c", 179); } } if(i != 9) { printf("\n\t\t %c", 195); } else { printf("\n\t\t %c", 192); } for(j = 0 ; j < 10 ; j++) { if(j != 9 && i != 9) { printf("%c%c%c%c", 196, 196, 196, 197); } if(j == 9 & i != 9) { printf("%c%c%c%c", 196, 196, 196, 180); } if(j == 9 && i == 9) { for(k = 0 ; k < 10 ; k++) { if(k != 9) { printf("%c%c%c%c", 196, 196, 196, 193); } else { printf("%c%c%c%c", 196, 196, 196, 217); } } } } printf("\n"); } } void error() { if(wrong == 1) { printf("\n\nNot enough space in that direction, stupid.\n\n"); system("pause"); } if(wrong == 2) { printf("\n\nThat is not a direction, stupid.\n\n"); system("pause"); } if(wrong == 3) { printf("\n\nIncorrect coordinate.\n\n"); system("pause"); } } int hit_miss(int player) { char ship_y; int ship_x; ship_y = getch(); printf("%c", ship_y); ship_y = transfer(ship_y); scanf("%d", &ship_x); if(player == 1) { if(fieldship[player][ship_y][ship_x - 1] == 'X') { fieldshot[player - 1][ship_y][ship_x - 1] = 'X'; pl1win -= 1; system("cls"); title(); play_board(player); printf("\n\nHit\n\n"); system("pause"); } else { fieldshot[player - 1][ship_y][ship_x - 1] = 'O'; system("cls"); title(); play_board(player); printf("\n\nMiss\n\n"); system("pause"); } } else { if(fieldship[player - 2][ship_y][ship_x - 1] == 'X') { fieldshot[player - 1][ship_y][ship_x - 1] = 'X'; pl2win -= 1; system("cls"); title(); play_board(player); printf("\n\nHit\n\n"); system("pause"); } else { fieldshot[player - 1][ship_y][ship_x - 1] = 'O'; system("cls"); title(); play_board(player); printf("\n\nMiss\n\n"); system("pause"); } } return(player); } char transfer(char ship_y) { if(ship_y >= 'A' && ship_y <= 'J') { ship_y -= 65; } if(ship_y >= 'a' && ship_y <= 'j') { ship_y -= 97; } return(ship_y); }
-
SORRY, das war die falsche version!!!
hier die die ich meine::#include<stdio.h> #include<stdlib.h> #include<conio.c> int shipsize, pl1win, pl2win, titletime; int fieldship[2][10][10] = {0}, fieldshot[2][10][10] = {0}; int sink[2][4]; void title(); /* Places title on screen */ void ships(int); /* Lets you place your ships */ void play_board(int); /* Places Playboard on screen */ void error(int); /* Places error messages on screen */ int hit_miss(int); /* Checks if you hit or miss */ char transform(char); /* transforms your coordinates */ void movie(int); /* Plays the movie */ void shipcount(int); /* Counts the shipsize */ void sinkship(); /* checks when you sink a ship */ int main() { int player, i, j, k, sinkship, wrong; char menu, game, quit; do { title(); textcolor(LIGHTRED); printf("Rules : 1\n"); printf("Controls : 2\n"); printf("Play : 3\n"); printf("Quit : 4\n\n"); printf("Your entry: "); menu = getch(); printf("%c\n\n", menu); switch(menu) { default : { wrong = 5; error(wrong); system("pause"); break; } case '1': { printf("Ships must have at least 1 space between each other.\n"); printf("Players are not allowed to look when other players are placing ships.\n"); printf("Players are not allowed to irritate other players.\n"); printf("If you do not play by these rules, the other player wins.\n"); printf("Shipsizes : 2 = Cruiser\n"); printf(" : 3 = Battleship\n"); printf(" : 4 = Destroyer\n"); printf(" : 5 = Aircraftcarrier\n\n"); system("pause"); break; } case '2': { printf("First you type (A)a - (J)j.\n"); printf("Then you type 1 - 10.\n"); printf("Then your press enter.\n"); printf("Then you type in a direction.\n"); printf("Directions: (U)u = Up\n"); printf(" (D)d = Down\n"); printf(" (L)l = Left\n"); printf(" (R)r = Right\n\n"); system("pause"); break; } case '3': { do { pl1win = 14; pl2win = 14; system("cls"); for(player = 1 ; player <= 2 ; player++) { shipsize = 5; title(); textcolor(LIGHTRED); printf("\n\nPlayer %d\n\n", player); system("pause"); system("cls"); do { title(); play_board(player); ships(player); } while(shipsize >= 2); } player = 1; do { title(); textcolor(LIGHTRED); printf("\n\nPlayer %d\n\n", player); system("pause"); system("cls"); title(); play_board(player); player = hit_miss(player); if(pl1win == 0 || pl2win == 0) { printf("\n\nPlayer %d has won\n\n", player); printf("Play again? "); do { game = getch(); printf("%c", game); if(game != 'Y' && game != 'y' && game != 'N' && game != 'n') { wrong = 5; error(wrong); printf("\n(Y)y / (N)n"); } if(game == 'Y' || game == 'y') { for(i = 0 ; i < 10 ; i++) { for(j = 0 ; j < 10 ; j++) { for(k = 0 ; k < 10 ; k++) { fieldship[i][j][k] = 0; fieldshot[i][j][k] = 0; } } } } } while(game != 'Y' && game != 'y' && game != 'N' && game != 'n'); break; } if(player == 1) { player = 2; } else { player = 1; } system("cls"); } while(pl1win != 0 && pl2win != 0); } while(game != 'N' && game != 'n'); break; } case '4': { printf("\nAre You sure? "); do { quit = getch(); printf("%c\n", quit); if(quit != 'Y' && quit != 'y' && quit != 'N' && quit != 'n'); { wrong = 5; error(wrong); printf("(Y)y / (N)n "); } } while(quit != 'Y' && quit != 'y' && quit != 'N' && quit != 'n'); } } system("cls"); } while(quit != 'Y' && quit != 'y'); } void title() { int i, j, x, y, done, color; char hl[6][45]; done = 0; srand(time(NULL)); hl[0][0] = 218; hl[1][0] = 179; hl[2][0] = 179; hl[3][0] = 179; hl[4][0] = 179; hl[5][0] = 192; hl[0][1] = 196; hl[1][1] = 218; hl[2][1] = 192; hl[3][1] = 218; hl[4][1] = 192; hl[5][1] = 196; hl[0][2] = 196; hl[1][2] = 191; hl[2][2] = 217; hl[3][2] = 191; hl[4][2] = 217; hl[5][2] = 196; hl[0][3] = 191; hl[1][3] = 179; hl[2][3] = 179; hl[3][3] = 179; hl[4][3] = 179; hl[5][3] = 217; hl[0][4] = 218; hl[1][4] = 179; hl[2][4] = 179; hl[3][4] = 179; hl[4][4] = 179; hl[5][4] = 192; hl[0][5] = 196; hl[1][5] = 218; hl[2][5] = 192; hl[3][5] = 218; hl[4][5] = 179; hl[5][5] = 217; hl[0][6] = 196; hl[1][6] = 191; hl[2][6] = 217; hl[3][6] = 191; hl[4][6] = 179; hl[5][6] = 192; hl[0][7] = 191; hl[1][7] = 179; hl[2][7] = 179; hl[3][7] = 179; hl[4][7] = 179; hl[5][7] = 217; hl[0][8] = 218; hl[1][8] = 192; hl[2][8] = ' '; hl[3][8] = ' '; hl[4][8] = ' '; hl[5][8] = ' '; hl[0][9] = 196; hl[1][9] = 191; hl[2][9] = 179; hl[3][9] = 179; hl[4][9] = 179; hl[5][9] = 192; hl[0][10] = 196; hl[1][10] = 218; hl[2][10] = 179; hl[3][10] = 179; hl[4][10] = 179; hl[5][10] = 217; hl[0][11] = 191; hl[1][11] = 217; hl[2][11] = ' '; hl[3][11] = ' '; hl[4][11] = ' '; hl[5][11] = ' '; hl[0][12] = 218; hl[1][12] = 192; hl[2][12] = ' '; hl[3][12] = ' '; hl[4][12] = ' '; hl[5][12] = ' '; hl[0][13] = 196; hl[1][13] = 191; hl[2][13] = 179; hl[3][13] = 179; hl[4][13] = 179; hl[5][13] = 192; hl[0][14] = 196; hl[1][14] = 218; hl[2][14] = 179; hl[3][14] = 179; hl[4][14] = 179; hl[5][14] = 217; hl[0][15] = 191; hl[1][15] = 217; hl[2][15] = ' '; hl[3][15] = ' '; hl[4][15] = ' '; hl[5][15] = ' '; hl[0][16] = 218; hl[1][16] = 179; hl[2][16] = 179; hl[3][16] = 179; hl[4][16] = 179; hl[5][16] = 192; hl[0][17] = 191; hl[1][17] = 179; hl[2][17] = 179; hl[3][17] = 179; hl[4][17] = 192; hl[5][17] = 196; hl[0][18] = ' '; hl[1][18] = ' '; hl[2][18] = ' '; hl[3][18] = ' '; hl[4][18] = 196; hl[5][18] = 196; hl[0][19] = ' '; hl[1][19] = ' '; hl[2][19] = ' '; hl[3][19] = ' '; hl[4][19] = 191; hl[5][19] = 217; hl[0][20] = 218; hl[1][20] = 179; hl[2][20] = 179; hl[3][20] = 179; hl[4][20] = 179; hl[5][20] = 192; hl[0][21] = 196; hl[1][21] = 218; hl[2][21] = 192; hl[3][21] = 218; hl[4][21] = 192; hl[5][21] = 196; hl[0][22] = 196; hl[1][22] = 196; hl[2][22] = 196; hl[3][22] = 196; hl[4][22] = 196; hl[5][22] = 196; hl[0][23] = 191; hl[1][23] = 217; hl[2][23] = 191; hl[3][23] = 217; hl[4][23] = 191; hl[5][23] = 217; hl[0][24] = ' '; hl[1][24] = ' '; hl[2][24] = ' '; hl[3][24] = ' '; hl[4][24] = ' '; hl[5][24] = ' '; hl[0][25] = ' '; hl[1][25] = ' '; hl[2][25] = ' '; hl[3][25] = ' '; hl[4][25] = ' '; hl[5][25] = ' '; hl[0][26] = ' '; hl[1][26] = ' '; hl[2][26] = ' '; hl[3][26] = ' '; hl[4][26] = ' '; hl[5][26] = ' '; hl[0][27] = 218; hl[1][27] = 179; hl[2][27] = 179; hl[3][27] = 192; hl[4][27] = 218; hl[5][27] = 192; hl[0][28] = 196; hl[1][28] = 218; hl[2][28] = 192; hl[3][28] = 196; hl[4][28] = 196; hl[5][28] = 196; hl[0][29] = 196; hl[1][29] = 196; hl[2][29] = 196; hl[3][29] = 191; hl[4][29] = 217; hl[5][29] = 196; hl[0][30] = 191; hl[1][30] = 217; hl[2][30] = 191; hl[3][30] = 179; hl[4][30] = 179; hl[5][30] = 217; hl[0][31] = 218; hl[1][31] = 179; hl[2][31] = 179; hl[3][31] = 179; hl[4][31] = 179; hl[5][31] = 192; hl[0][32] = 191; hl[1][32] = 179; hl[2][32] = 192; hl[3][32] = 218; hl[4][32] = 179; hl[5][32] = 217; hl[0][33] = 218; hl[1][33] = 179; hl[2][33] = 217; hl[3][33] = 191; hl[4][33] = 179; hl[5][33] = 192; hl[0][34] = 191; hl[1][34] = 179; hl[2][34] = 179; hl[3][34] = 179; hl[4][34] = 179; hl[5][34] = 217; hl[0][35] = 218; hl[1][35] = 179; hl[2][35] = 179; hl[3][35] = 179; hl[4][35] = 179; hl[5][35] = 192; hl[0][36] = 191; hl[1][36] = 179; hl[2][36] = 179; hl[3][36] = 179; hl[4][36] = 179; hl[5][36] = 217; hl[0][37] = 218; hl[1][37] = 179; hl[2][37] = 179; hl[3][37] = 179; hl[4][37] = 179; hl[5][37] = 192; hl[0][38] = 196; hl[1][38] = 218; hl[2][38] = 192; hl[3][38] = 218; hl[4][38] = 179; hl[5][38] = 217; hl[0][39] = 196; hl[1][39] = 191; hl[2][39] = 217; hl[3][39] = 196; hl[4][39] = ' '; hl[5][39] = ' '; hl[0][40] = 191; hl[1][40] = 179; hl[2][40] = 179; hl[3][40] = 217; hl[4][40] = ' '; hl[5][40] = ' '; hl[0][41] = 218; hl[1][41] = 179; hl[2][41] = 179; hl[3][41] = 192; hl[4][41] = 218; hl[5][41] = 192; hl[0][42] = 196; hl[1][42] = 218; hl[2][42] = 192; hl[3][42] = 196; hl[4][42] = 196; hl[5][42] = 196; hl[0][43] = 196; hl[1][43] = 196; hl[2][43] = 196; hl[3][43] = 191; hl[4][43] = 217; hl[5][43] = 196; hl[0][44] = 191; hl[1][44] = 217; hl[2][44] = 191; hl[3][44] = 179; hl[4][44] = 179; hl[5][44] = 217; do { y = rand() % 6; x = rand() % 45; color = rand() % 2; if(color == 1) { textcolor(GREEN); } else { textcolor(LIGHTGREEN); } if(hl[y][x] != 0) { gotoxy(x + 16 , y + 2); printf("%c", hl[y][x]); if(titletime != 1) { sleep(10); } done += 1; hl[y][x] = 0; } } while(done != 270); titletime = 1; textcolor(LIGHTBLUE); gotoxy(1 , 10); } void ships(int player) { int i, j, ship_x, direction, wrong; char ship_y; j = 0; textcolor(LIGHTRED); printf("\n"); printf("Size %d ship ", shipsize); do { ship_y = getch(); printf("%c", ship_y); if(ship_y < 'A' || ship_y > 'J' && ship_y < 'a' || ship_y > 'j') { wrong = 3; error(wrong); printf("(A)a - (J)j "); } } while(ship_y < 'A' || ship_y > 'J' && ship_y < 'a' || ship_y > 'j'); ship_y = transform(ship_y); do { scanf("%d", &ship_x); if(ship_x < 1 || ship_x > 10) { wrong = 3; error(wrong); printf("1 - 10 "); } } while(ship_x < 1 || ship_x > 10); printf("Up, Down, Left or Right? "); direction = getch(); printf("%c\n", direction); switch(direction) { default : { wrong = 2; error(wrong); break; } case 'u': case 'U': { for(i = ship_y ; i > ship_y - shipsize ; i--) { if(fieldship[player - 1][i][ship_x - 1] >= 2 && fieldship[player - 1][i][ship_x - 1] <= 5) { j = 1; break; } } if(ship_y - shipsize >= -1 && j == 0) { shipcount(player); for(i = ship_y ; i > ship_y - shipsize ; i--) { fieldship[player - 1][i][ship_x - 1] = shipsize; } shipsize -= 1; break; } else { wrong = 1; error(wrong); break; } } case 'd': case 'D': { for(i = ship_y ; i < ship_y + shipsize ; i++) { if(fieldship[player - 1][i][ship_x - 1] >= 2 && fieldship[player - 1][i][ship_x - 1] <= 5) { j = 1; break; } } if(ship_y + shipsize <= 10 && j == 0) { shipcount(player); for(i = ship_y ; i < ship_y + shipsize ; i++) { fieldship[player - 1][i][ship_x - 1] = shipsize; } shipsize -= 1; break; } else { wrong = 1; error(wrong); break; } } case 'l': case 'L': { for(i = ship_x ; i > ship_x - shipsize ; i--) { if(fieldship[player - 1][ship_y][i - 1] >= 2 && fieldship[player - 1][ship_y][i - 1] <= 5) { j = 1; break; } } if(ship_x - shipsize >= 0 && j == 0) { shipcount(player); for(i = ship_x ; i > ship_x - shipsize ; i--) { fieldship[player - 1][ship_y][i - 1] = shipsize; } shipsize -= 1; break; } else { wrong = 1; error(wrong); break; } } case 'r': case 'R': { for(i = ship_x ; i < ship_x + shipsize ; i++) { if(fieldship[player - 1][ship_y][i - 1] >= 2 && fieldship[player - 1][ship_y][i - 1] <= 5) { j = 1; break; } } if(ship_x + shipsize <= 11 && j == 0) { shipcount(player); for(i = ship_x ; i < ship_x + shipsize ; i++) { fieldship[player - 1][ship_y][i - 1] = shipsize; } shipsize -= 1; break; } else { wrong = 1; error(wrong); break; } } } system("cls"); } void play_board(int player) { int i, j, k; textcolor(LIGHTGREEN); printf("\t\t"); for(i = 0 ; i < 10 ; i++) { printf(" %2d", i + 1); } printf("\n\t\t %c", 218); for(i = 0 ; i < 10 ; i++) { if(i != 9) { printf("%c%c%c%c", 196, 196, 196, 194); } else { printf("%c%c%c%c", 196, 196, 196, 191); } } printf("\n"); for(i = 0 ; i < 10 ; i++) { printf("\t\t%c%c", i + 65, 179); for(j = 0 ; j < 10 ; j++) { if(fieldship[player - 1][i][j] != 0 || shipsize == 1) { if(shipsize == 1) { printf(" %c %c", fieldshot[player - 1][i][j], 179); } else { printf(" X %c", 179); } } else { printf(" %c", 179); } } if(i != 9) { printf("\n\t\t %c", 195); } else { printf("\n\t\t %c", 192); } for(j = 0 ; j < 10 ; j++) { if(j != 9 && i != 9) { printf("%c%c%c%c", 196, 196, 196, 197); } if(j == 9 & i != 9) { printf("%c%c%c%c", 196, 196, 196, 180); } if(j == 9 && i == 9) { for(k = 0 ; k < 10 ; k++) { if(k != 9) { printf("%c%c%c%c", 196, 196, 196, 193); } else { printf("%c%c%c%c", 196, 196, 196, 217); } } } } printf("\n"); } } void error(int wrong) { switch(wrong) { case 1: { printf("\nNot enough space in that direction.\n"); system("pause"); break; } case 2: { printf("\nThat is not a direction.\n"); system("pause"); break; } case 3: { printf("\nIncorrect coordinate. Try again.\n"); break; } case 4: { printf("\nYou already have shot there.\n"); break; } case 5: { printf("\nIncorrect entry.\n\n"); break; } } } int hit_miss(int player) { int wrong; int ship_x; char ship_y; textcolor(LIGHTRED); do { printf("\nWhere do you want to shoot at? "); do { ship_y = getch(); printf("%c", ship_y); if(ship_y < 'A' || ship_y > 'J' && ship_y < 'a' || ship_y > 'j') { wrong = 3; error(wrong); printf("\n(A)a - (J)j "); } } while(ship_y < 'A' || ship_y > 'J' && ship_y < 'a' || ship_y > 'j'); ship_y = transform(ship_y); do { scanf("%d", &ship_x); if(ship_x < 1 || ship_x > 10) { wrong = 3; error(wrong); printf("\n1 - 10 "); } } while(ship_x < 1 || ship_x > 10); if(player == 1) { if(fieldshot[player - 1][ship_y][ship_x - 1] == 'X' || fieldshot[player - 1][ship_y][ship_x - 1] == 'O') { wrong = 4; error(wrong); } else { if(fieldship[player][ship_y][ship_x - 1] >= 2 && fieldship[player][ship_y][ship_x - 1] <= 5) { fieldshot[player - 1][ship_y][ship_x - 1] = 'X'; pl1win -= 1; sinkship(player, ship_x, ship_y); wrong = 0; system("pause"); } else { fieldshot[player - 1][ship_y][ship_x - 1] = 'O'; system("cls"); title(); movie(0); printf("\nMiss\n\n"); wrong = 0; system("pause"); } } } else { if(fieldshot[player - 1][ship_y][ship_x - 1] == 'X' || fieldshot[player - 1][ship_y][ship_x - 1] == 'O') { wrong = 4; error(wrong); } else { if(fieldship[player - 2][ship_y][ship_x - 1] >= 2 && fieldship[player - 2][ship_y][ship_x - 1] <= 5) { fieldshot[player - 1][ship_y][ship_x - 1] = 'X'; pl2win -= 1; sinkship(player, ship_x, ship_y); wrong = 0; system("pause"); } else { fieldshot[player - 1][ship_y][ship_x - 1] = 'O'; system("cls"); title(); movie(0); printf("\nMiss\n\n"); wrong = 0; system("pause"); } } } } while(wrong == 4); return(player); } char transform(char ship_y) { if(ship_y >= 'A' && ship_y <= 'J') { ship_y -= 65; } if(ship_y >= 'a' && ship_y <= 'j') { ship_y -= 97; } return(ship_y); } void movie(int x) { int i, j, k, z; textcolor(LIGHTCYAN); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t\t\t %c%c\n", 218, 123); printf("\t\t\t\t\t\t %c%c%c %c\n", 218, 193, 191, 47); printf("\t\t\t\t\t\t %c%c %c %c%c%c %c%c\n", 92, 179, 179, 218, 193, 191, 218, 123); printf("\t\t\t\t\t\t %c%c %c %c %c%c%c%c\n", 195, 217, 179, 179, 179, 218, 193, 191); printf("\t\t\t\t\t\t %c %c%c%c %c %c %c%c %c%c%c\n", 92, 92, 218, 217, 179, 179, 192, 217, 192, 191, 47); printf("\t\t\t\t\t\t %c%c%c%c%c%c %c%c%c %c%c%c\n", 123, 196, 193, 196, 193, 217, 192, 196, 217, 192, 193, 125); printf("\t\t\t\t\t\t %c %c\n", 92, 47); printf("\t\t\t\t\t\t %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", 92, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 47); textcolor(LIGHTGREEN); if(x > 0) { z = 28; } else { z = 35; } for(i = 10 ; i <= z ; i++) { switch(x) { case 0: { j = i + 10; break; } case 1: case 2: { j = i + 30; } } gotoxy(j , i); printf("%c", 92); sleep(30); gotoxy(j , i); printf(" "); } if(x > 0) { textcolor(LIGHTRED); gotoxy(j - 1 , i - 1); printf("%c%c%c", 218, 193, 191); k = 0; for(i = 28 ; i >= 20 ; i--) { k += 1; if(x == 2) { gotoxy(i + 30 - 4, j - 31 + 5); printf("%c",193); gotoxy(i + 30 - 4, j - 31 + 4); printf("%c",92); gotoxy(i + 30 - 8, j - 31 + 5); printf("%c",123); gotoxy(i + 30 - 7, j - 31 + k + 5); printf("%c",92); gotoxy(i + 30 - 4, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k - 4, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k - 3, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k - 2, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k - 1, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k , j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k + k , j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k + k + 5, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k + k + 6, j - 31 + k + 6); printf("%c",196); gotoxy(i + 30 + k + k + 7, j - 31 + k + 6); printf("%c", 47); gotoxy(i + 30 + k + k + 8, j - 31 + k + 5); printf("%c", 47); gotoxy(i + 30 + k + k + 7, j - 31 + 5); printf("%c", 192); gotoxy(i + 30 + k + k + 3, j - 31 + 4); printf("%c", 192); gotoxy(i + 30 + k + k + 2, j - 31 - k + 2); printf("%c", 47); gotoxy(i + 30 + k - 1, j - 31 - k + 1); printf("%c", 218); gotoxy(j + k + 2 , i + k + k + 1); printf("%c", 179); gotoxy(j + k + 2 , i + k + k + 2); printf("%c", 217); gotoxy(j + k + 1 , i + k + k + 2); printf("%c", 196); gotoxy(j + k , i + k + k + 2); printf("%c", 192); gotoxy(j + k , i + k + k + 1); printf("%c", 192); gotoxy(j + k , i + k + 1); printf("%c", 179); gotoxy(j + k , i + k); printf("%c", 179); gotoxy(i + 29 , j - 29 + k); printf("%c", 217); gotoxy(i + 28 , j - 29); printf("%c", 92); gotoxy(i + 29 , j - 30 + k); printf("%c", 179); gotoxy(j + k, i + 1); printf("%c", 179); } gotoxy(j + 1, i); printf("%c", 191); gotoxy(i + 29, j - 30); printf("%c", 218); gotoxy(i + 30, i); printf("%c", 193); sleep(60); if(x == 2) { gotoxy(i + 30 - 4, j - 31 + 5); printf(" "); gotoxy(i + 30 - 4, j - 31 + 4); printf(" "); gotoxy(i + 30 - 8, j - 31 + 5); printf(" "); gotoxy(i + 30 - 7, j - 31 + k + 5); printf(" "); gotoxy(i + 30 - 4, j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k - 4, j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k - 3, j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k - 2, j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k - 1, j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k , j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k + k , j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k + k + 5 , j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k + k + 6 , j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k + k + 7 , j - 31 + k + 6); printf(" "); gotoxy(i + 30 + k + k + 8 , j - 31 + k + 5); printf(" "); gotoxy(i + 30 + k + k + 7 , j - 31 + 5); printf(" "); gotoxy(i + 30 + k + k + 3 , j - 31 + 4); printf(" "); gotoxy(i + 30 + k + k + 2 , j - 31 - k + 2); printf(" "); gotoxy(i + 30 + k - 1 , j - 31 - k + 1); printf(" "); gotoxy(j + k + 2 , i + k + k + 1); printf(" "); gotoxy(j + k + 2 , i + k + k + 2); printf(" "); gotoxy(j + k + 1 , i + k + k + 2); printf(" "); gotoxy(j + k , i + k + k + 2); printf(" "); gotoxy(j + k , i + k + k + 1); printf(" "); gotoxy(j + k , i + k + 1); printf(" "); gotoxy(j + k , i + k); printf(" "); gotoxy(i + 29 , j - 29 + k); printf(" "); gotoxy(i + 28 , j - 29); printf(" "); gotoxy(i + 29 , j - 30 + k); printf(" "); gotoxy(j + k , i + 1); printf(" "); } gotoxy(j + 1 , i); printf(" "); gotoxy(i + 29 , j - 30); printf(" "); gotoxy(i + 30 , i); printf(" "); } printf("\n\n\n\n\n\n\n\n\n\n"); } } void shipcount(int player) { switch(shipsize) { case 5: { sink[player - 1][shipsize - 2] = shipsize; } case 4: { sink[player - 1][shipsize - 2] = shipsize; } case 3: { sink[player - 1][shipsize - 2] = shipsize; } case 2: { sink[player - 1][shipsize - 2] = shipsize; } } } void sinkship(player, ship_x, ship_y) int player, ship_x; char ship_y; { if(player == 1) { switch(fieldship[player][ship_y][ship_x - 1]) { case 5: { sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Aircraftcarrier.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 4: { sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Destroyer.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 3: { sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Battleship.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 2: { sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Cruiser.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } } } else { switch(fieldship[player - 2][ship_y][ship_x - 1]) { case 5: { sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Aircraftcarrier.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 4: { sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Destroyer.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 3: { sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Battleship.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } case 2: { sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] -= 1; if(sink[player - 1][fieldship[player - 2][ship_y][ship_x - 1] - 2] == 0) { system("cls"); title(); movie(2); printf("\n\nYou have destroyed the Cruiser.\n\n"); } else { system("cls"); title(); movie(1); printf("\n\nHit\n\n"); } break; } } } }
-
1. Und?
2. Was hat das mit ANSI C zu tun?
-
So!
Zuerst einmal:Bitte schaffe dir einen Web-Space an:
www.8ung.at
und stelle den Quellcode als cpp bzw. c datei als Download zur Verfügung!
Da kannst du sogar die *.exe uploaden. (zippen||rarn), dann weiß noch keiner den Quellcode.Zweitens:
Du kannst deine eigenen Beiträge editieren und musst nicht noch einmal den gesamten Code hinknallen.Ich werde das Programm aber mal testen.
-
PS.: Wie wärs wenn du
conio.c auch hierher stellst???
FATAL ERROR: Datei ist nicht vorhanden!
-
Quellcode ist viel zu kompliziert und zu lang!!!
Warnungen bitte beseitigen!!!
"Verkürzung von const int in char"
Das ist nicht gut, weil const int einen größeren Bereich umfasst und so bei der Konvertierung in char Fehler auftreten können!Noch etwas:
W E L C H E P R O G R A M M I E R S P R A C H E S C H R E I B S T DU D A ?
-
hallo mu!
Tolles Programm.
Ist dieser programmcode opensource?
Könnte das Programm mit Hilfe von ncurses auch für Unix-Plattformen verfügbar machen. Möchte dir gerne meine Mithilfe anbieten.Gruß
Michael
-
mu schrieb:
hier der code. könnts ja selbst compilen.
Nö, können wir nicht:
VC++ 6.0 schrieb:
Fehler beim Ausführen von cl.exe.
test.exe - 19 Fehler, 451 Warnung(en)
Hast Du das überhaupt selber mal kompiliert? Anscheinend nicht...
#include<conio.c> // fatal error C1083: Include-Datei kann nicht geöffnet werden: 'conio.c': No such file or directory ... void sinkship(player, ship_x, ship_y) // error C2078: Zu viele Initialisierungen // und weil da das Semikolon fehlt: // fatal error C1004: Unerwartetes Dateiende gefunden int player, ship_x; char ship_y; //error C2371: 'ship_y' : Neudefinition; unterschiedliche Basistypen { //error C2447: '<L_PROPERTY>' : Funktionskopf fehlt - Parameterliste im alten Stil? if(player == 1) { ... } }
...um nur 2 der 19 Fehler zu zeigen.
-
der fairness halber: können gäste ihre eigenen beiträge editieren?
zum programm:
wieso stellst du hier etwas rein, was du noch nicht mal selber compiliert hast? ist der code überhaupt von dir? ich mach mir sicher nicht die mühe und besser die ganzen fehler für dich aus (um dann vielleicht festzustellen dass es noch immer nicht funzt)...
-
SORRY schrieb:
SORRY, das war die falsche version!!!
das zweite wohl auch
-
hi.
ich habs mal geuppt. bitte: http://mitglied.lycos.de/vanessadean/Game.exe
-
Lycos Tripod schrieb:
Kein externes linken erlaubt...
-
Du musst verstehen!
Niemand macht sich die Mühe und korrigiert so ein langes aufwendiges Programm, wenn man sich nicht sicher sein kann, ob es dann funktionieren wird!
PS.: Quellcode bitte vorher testen!
-
rechtsklick ziel speichern unter
-
Status: getestet
Wertung:- Coole Animationen!
Mein Kompliment
- 1 Fehler gefungen:
gib als 1. Koordinate f. ein:
aa
dann geht gar nichts mehr!
PS.: DAS kann man auch eingeben (Eingabeabsicherung)
aaaaaaaa
wie liest du die Zeichenvariable (A,B,C,D,...) ein?
- Coole Animationen!
-
Also bevor ich mir das überhaupt näher anschaue, sollten alle system() durch sinnvolle Funktionen ersetzt werden und das Programm bei den Eingaben vor Bufferoverflows geschützt werden.
-
werd ich weiterleiten