小蜜蜂游戏c语言,C语言实现井字棋小游戏

#include

#include

int store[]={'_','_','_','_','_','_','_','_','_'}, shunt=1, count, i;

void print_map()

{

char boundary='|';

getchar();

system("cls");

for(i=0;i<9;i++)

{

printf("%c%c",boundary,store[i]);

if(i==2||i==5)

{

putchar(boundary);

putchar('\n');

}

}

putchar(boundary);

putchar('\n');

}

int judge_win(int f=0)

{

if(store[0]+store[1]+store[2]==3*'O'||store[0]+store[1]+store[2]==3*'X'||

store[3]+store[4]+store[5]==3*'O'||store[3]+store[4]+store[5]==3*'X'||

store[6]+store[7]+store[8]==3*'O'||store[6]+store[7]+store[8]==3*'X'||

store[0]+store[3]+store[6]==3*'O'||store[0]+store[3]+store[6]==3*'X'||

store[1]+store[4]+store[7]==3*'O'||store[1]+store[4]+store[7]==3*'X'||

store[2]+store[5]+store[8]==3*'O'||store[2]+store[5]+store[8]==3*'X'||

store[0]+store[4]+store[8]==3*'O'||store[0]+store[4]+store[8]==3*'X'||

store[2]+store[4]+store[6]==3*'O'||store[2]+store[4]+store[6]==3*'X')

f=1;

return f;

}

void judge_final()

{

if(count%2==0) printf("二号选手获胜\n");

else printf("一号选手获胜\n");

}

int number_mend(int number)

{

switch(number)

{

case 1:number=7;break;

case 2:number=8;break;

case 3:number=9;break;

case 7:number=1;break;

case 8:number=2;break;

case 9:number=3;break;

default:;

}

return number;

}

void scan_number()

{

int a, b, number;

scanf("%d",&number);

number=number_mend(number);

while(number<1||number>9||store[number-1]!='_')

{

printf("非法输入,请重新输入\n");

getchar();

scanf("%d",&number);

number=number_mend(number);

}

if(shunt%2!=0)

{

a=number;

store[a-1]='O';

print_map();

shunt++;

}

else

{

b=number;

store[b-1]='X';

print_map();

shunt++;

}

}

void renew()

{

for(;i>=0;i--)

store[i]='_';

}

int main()

{

char turn;

printf("这是一个井字棋游戏,小键盘1到9对应九个格。按回车开始游戏\n");

for(turn='y';turn=='y';turn=getchar(),renew())

{

print_map();

for(count=0;count<10;count++)

{

if(judge_win())break;

if(count==9)

{

printf("平局\n");

goto lp;

}

scan_number();

}

judge_final();

lp:printf("是否继续?y/n\n");

}

printf("游戏结束\n");

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的Python小蜜蜂游戏: ```python import pygame import random # 初始化pygame pygame.init() # 设置游戏窗口的宽和高 width = 600 height = 600 # 创建游戏窗口 screen = pygame.display.set_mode((width, height)) # 设置游戏窗口标题 pygame.display.set_caption("小蜜蜂游戏") # 加载小蜜蜂图片 bee_img = pygame.image.load("bee.png") # 设置小蜜蜂的初始位置和速度 bee_x = 250 bee_y = 500 bee_speed = 5 # 创建蜜蜂列表和速度列表 bees = [] bee_speeds = [] # 初始化蜜蜂列表和速度列表 for i in range(10): bees.append(pygame.Rect(random.randint(0, width-50), random.randint(-500, 0), 50, 50)) bee_speeds.append(random.randint(1, 5)) # 加载背景音乐 pygame.mixer.music.load("bg_music.mp3") pygame.mixer.music.set_volume(0.2) pygame.mixer.music.play(-1) # 创建字体对象 font = pygame.font.Font(None, 36) # 初始化得分和游戏结束标志 score = 0 game_over = False # 游戏循环 while True: # 处理游戏事件 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: bee_x -= bee_speed elif event.key == pygame.K_RIGHT: bee_x += bee_speed # 移动蜜蜂 for i in range(10): bees[i].move_ip(0, bee_speeds[i]) if bees[i].bottom > height: bees[i].top = random.randint(-500, 0) bees[i].left = random.randint(0, width-50) bee_speeds[i] = random.randint(1, 5) score += 1 # 清除上一帧画面 screen.fill((255, 255, 255)) # 绘制小蜜蜂和蜜蜂 screen.blit(bee_img, (bee_x, bee_y)) for bee in bees: pygame.draw.rect(screen, (255, 0, 0), bee) # 绘制得分 score_text = font.render("得分:%d" % score, True, (0, 0, 0)) screen.blit(score_text, (10, 10)) # 判断游戏是否结束 for bee in bees: if bee.colliderect(pygame.Rect(bee_x, bee_y, 50, 50)): game_over = True break if game_over: game_over_text = font.render("游戏结束!", True, (255, 0, 0)) screen.blit(game_over_text, (width//2 - 100, height//2 - 20)) # 更新屏幕显示 pygame.display.update() ``` 在运行这个程序之前,你需要准备以下素材文件: - bee.png:小蜜蜂的图片文件 - bg_music.mp3:游戏的背景音乐文件 将这两个文件放在程序同级目录下,然后运行程序即可开始游戏。在游戏中,你需要控制小蜜蜂躲避下落的蜜蜂,并尽可能地吃到更多的蜜蜂,得分越高,游戏难度也会相应提高。如果小蜜蜂被蜜蜂撞到,游戏就会结束。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值