C語言實現(xiàn)意大利炮小游戲
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#include <string.h>

void HideCursor();
void gotoxy(int x, int y);
#define R 26?
#define N 5//通關(guān)分數(shù)
int ax[3] = { 0 }, y[3] = { 3,7,11 }, i, fd[3];
void cshcxhs()
{
? ? system(" 二營長的意大利炮");
? ? system("mode con cols=100 lines=30");
? ? HideCursor();
? ? gotoxy(46, 12);? printf("二營長的意大利炮");
? ? gotoxy(36, 14);? printf("w a d鍵控制方向,空格鍵開炮");
? ? gotoxy(26, 16); printf("打中小鬼子 |---0> 記一等功一次,打中自己人 >>>>0>記大過處分一次");
? ? gotoxy(40, 18);
? ? Sleep(2800);
? ? system("cls");
? ? int k;
? ? gotoxy(40, R);
? ? for (k = 0; k < 17; k++)? printf("_");
? ? gotoxy(46, R);
? ? printf("[_O_]");
? ? gotoxy(48, 25);
? ? printf("|");
? ? int j;
? ? srand((unsigned)time(NULL));
? ? for (j = 0; j < 3; j++)
? ? {
? ? ? ? ax[j] = rand() % R;
? ? ? ? fd[j] = rand() % 2;
? ? }
? ? gotoxy(0, R);
? ? printf("一等功次數(shù):");
}
void hcfjhs()
{
? ? gotoxy(ax[i], y[i]);
? ? if (fd[i] == 1)
? ? ? ? printf("|---0>");
? ? else
? ? ? ? printf(">>>>0>");
? ? gotoxy(ax[i] - 1, y[i]);
? ? printf(" ");
? ? ax[i]++;
}
void dhpdxshs()
{
? ? for (i = 0; i < 3; i++)
? ? {
? ? ? ? hcfjhs();
? ? ? ? if (ax[i] + 6 > 93)
? ? ? ? {
? ? ? ? ? ? gotoxy(94, y[i]);
? ? ? ? ? ? printf(" ");
? ? ? ? ? ? if (ax[i] + 6 >= 101)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ax[i] = rand() % R;
? ? ? ? ? ? ? ? fd[i] = rand() % 2;
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
int da = 2, yip = 0, rtde = 1;
int shells_x, shells_y;
void ckkzhs()
{
? ? char ch;
? ? ch = _getch();
? ? if (ch == 'd' || ch == 'D')
? ? {
? ? ? ? gotoxy(49, 25);
? ? ? ? printf("/");
? ? ? ? gotoxy(47, 25);
? ? ? ? printf(" ");
? ? ? ? da = 3;
? ? }
? ? if (ch == 'A' || ch == 'a')
? ? {
? ? ? ? gotoxy(47, 25);
? ? ? ? printf("\\");
? ? ? ? gotoxy(48, 25);
? ? ? ? printf(" ");
? ? ? ? da = 1;
? ? }
? ? if (ch == 'W' || ch == 'w')
? ? {
? ? ? ? gotoxy(48, 25);
? ? ? ? printf("|");
? ? ? ? gotoxy(47, 25);
? ? ? ? printf(" ");
? ? ? ? gotoxy(49, 25);
? ? ? ? printf(" ");
? ? ? ? da = 2;
? ? }
? ? if (ch == ' ' && rtde == 0)
? ? {
? ? ? ? if (da == 2)
? ? ? ? ? ? yip = 2;
? ? ? ? if (da == 1)
? ? ? ? {
? ? ? ? ? ? yip = 1;
? ? ? ? ? ? shells_x = 45;
? ? ? ? }
? ? ? ? if (da == 3)
? ? ? ? {
? ? ? ? ? ? yip = 3;
? ? ? ? ? ? shells_x = 51;
? ? ? ? }
? ? ? ? shells_y = 23;
? ? }
}
void dpfshs()
{
? ? rtde = 1;
? ? if (yip == 2)
? ? {
? ? ? ? shells_x = 48;
? ? ? ? gotoxy(shells_x, shells_y -= 2);
? ? ? ? printf("o");
? ? ? ? gotoxy(shells_x, shells_y + 2);
? ? ? ? printf(" ");
? ? }
? ? if (yip == 1)
? ? {
? ? ? ? gotoxy(shells_x -= 2, shells_y -= 2);
? ? ? ? printf("o");
? ? ? ? gotoxy(shells_x + 2, shells_y + 2);
? ? ? ? printf(" ");
? ? }
? ? if (yip == 3)
? ? {
? ? ? ? gotoxy(shells_x += 2, shells_y -= 2);
? ? ? ? printf("o");
? ? ? ? gotoxy(shells_x - 2, shells_y + 2);
? ? ? ? printf(" ");
? ? }
? ? if (shells_y <= 1)
? ? {
? ? ? ? yip = 0;
? ? ? ? gotoxy(48, 1);
? ? ? ? printf(" ");
? ? ? ? gotoxy(23, 1);
? ? ? ? printf(" ");
? ? ? ? gotoxy(73, 1);
? ? ? ? printf(" ");
? ? ? ? rtde = 0;
? ? }
}
int score;
void pdfsjzhs()
{
? ? for (i = 0; i < 3; i++)
? ? {
? ? ? ? if (shells_x >= ax[i] && shells_x <= ax[i] + 6 && shells_y == y[i])
? ? ? ? {
? ? ? ? ? ? if (fd[i] == 1)
? ? ? ? ? ? ? ? score++;
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? score--;
? ? ? ? ? ? ? ? if (score <= 0)
? ? ? ? ? ? ? ? ? ? score = 0;
? ? ? ? ? ? }
? ? ? ? ? ? rtde = 0;
? ? ? ? ? ? gotoxy(ax[i] - 1, y[i]);
? ? ? ? ? ? printf(" ");
? ? ? ? ? ? ax[i] = rand() % R;
? ? ? ? ? ? fd[i] = rand() % 2;
? ? ? ? ? ? gotoxy(shells_x, shells_y);
? ? ? ? ? ? printf(" ");
? ? ? ? ? ? shells_x = 0, shells_y = 0;
? ? ? ? }
? ? }
? ? gotoxy(9, R);
? ? printf("%d", score);
? ? if (score >= N)
? ? {
? ? ? ? system("cls");
? ? ? ? gotoxy(39, 15);
? ? ? ? printf("你TND還真是個人才!");
? ? ? ? gotoxy(0, 29);
? ? ? ? exit(0);
? ? }
}
void process()
{
? ? while (1)
? ? {
? ? ? ? dhpdxshs();
? ? ? ? if (_kbhit())
? ? ? ? {
? ? ? ? ? ? ckkzhs();
? ? ? ? }
? ? ? ? dpfshs();
? ? ? ? pdfsjzhs();
? ? ? ? Sleep(18);
? ? }
}
int main()
{
? ? cshcxhs();
? ? process();
? ? return 0;
}
void HideCursor()
{
? ? CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
? ? SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void gotoxy(int x, int y)
{
? ? COORD pos = { x,y };
? ? SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

實際上為捕魚達人類魔改,新手上路,還請輕噴。