admin管理员组

文章数量:1637225

【C语言】双人格斗小游戏

芜湖

程序介绍:【C语言】实现双人控制的战斗小游戏

/*--------------------------------------
project: 双人小游戏
anthor:   LLz 
操作    移动    逆、顺时针旋转   发射子弹 
玩家1   4568    7 9 			      0 
玩家2   adws 	  q e 			      空格        
--------------------------------*/ 
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define High 20  // 游戏画面尺寸
#define Width 100        
// 全局变量
int position_x,position_y,p_x,p_y,turn_a,turn_b,num_a,num_b,num_max,life_a = 10,life_b = 10; // 飞机位置
int canvas[High][Width] = {
   0}; // 二维数组存储游戏画布中对应的元素
                        // 0为空格,1为飞机*,2为子弹|,3为敌机@
int next[8][2] = {
   {
   0,1},{
   1,1},{
   1,0},{
   1,-1},{
   0,-1},{
   -1,-1},{
   -1,0},{
   -1,1}}; //从右  右下  下  左下 
int bullet_a[21][4];
int bullet_b[21][4];   //a b玩家子弹20发;            
void gotoxy(int x,int y)  //光标移动到(x,y)位置
{
   
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(handle,pos);
} 
void startup() // 数据初始化
{
   
	num_a = 0;
	num_b = 0;
	turn_a = 0;
	turn_b = 0;
	p_x = High/2;
	p_y = Width* 4 / 5;
	canvas[p_x][p_y] = 5;
	position_x = High/2;
	position_y = Width/5;
	canvas[position_x][position_y] = 1;	
}
void show()  // 显示画面
{
   
	gotoxy(0,0);  // 光标移动到原点位置,以下重画清屏
	int i,j;
	for (i=0;i<High;i++)
	{
   
		for (j=0;j<Width;j++)
		{
   
			if( i == 0 || i == High -1 || j == 0 || j == Width -1){
   
				canvas[i][j] = 4;
				printf("0");
				continue;
			}
			if (canvas[i][j]==0)
				printf(" ");   //   输出空格
			else if (canvas[i][j]==1)
				printf("N");   //   输出飞机a
			else if (canvas[i][j]==2)
				printf("@");   //   输出飞机B
			else if (canvas[i][j]==3)
				printf("o");   //  输出子弹o 
			else if (canvas[i][j]==4)
				printf("o");   //	输出飞机a指向 
			else if (canvas[i][j]==

本文标签: 小游戏双人源码语言