火箭工作室c++小游戏——海战棋

火箭工作室第一个c++开发游戏——海战棋

今天是我第一次写博客,发个小游戏给大家当做见面礼。

#include <cstdio>
#include <ctime>           //rand()%(x) 0~x-1 int 
#include <windows.h>       //停顿:Sleep(); 
#include <cstdlib>         //清屏:system("cls");
#include <conio.h>         //getch(); char
#include <iostream>
#include <cstring>         //未知  :□; 打中  :◎;  未打中:○ 船:★;
using namespace std;
int rest[3][5],r1,r2;      //rest[1]:玩家的海域; rest[2]:电脑的海域  r1:玩家还剩船数; r2:电脑还剩船数 
int b1[12][12],b2[12][12];                            //0:空海; 1:船只; 2:打中; 3:边界 4:未打中 5:沉船 
int c1[12][12],c2[12][12];                            //c1:玩家海域的颜色  c2:电脑海域颜色 
int fx[8][2]={
   {
   0,1},{
   1,0},{
   0,-1},{
   -1,0},{
   1,1},{
   -1,-1},{
   1,-1},{
   -1,1}};
int now[2][2];              //now[左/右][x/y]  光标 
string a1[12][12],a2[12][12];
int fd [500][2],head=0,tail=0;
const long long wdmm=956454236985412563;
long long cjzt=0,wdm;


void color(int a)//颜色函数
{
   
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gotoxy(int x,int y)//位置函数(整个界面)(行为x 列为y)
{
   
COORD pos;
pos.X=2*(y);
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void gotoxy1(int x,int y)//位置函数(左边棋盘)(行为x 列为y)
{
   
COORD pos;
pos.X=2*(y+5);
pos.Y=x+1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void gotoxy2(int x,int y)//位置函数(右边棋盘)(行为x 列为y)
{
   
COORD pos;
pos.X=2*(y+18);
pos.Y=x+1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

void check2(int x,int y){
   
    int k=0,kx,ky,f=1;
    for (int i=0; i<=3; i++){
   
        if (b2[x+fx[i][0]][y+fx[i][1]]==2) k=i;
        if (b2[x+fx[i][0]][y+fx[i][1]]==1) f=0;
    }
    for (kx=x,ky=y; b2[kx][ky]==2; kx+=fx[k][0],ky+=fx[k][1]);
    if (b2[kx][ky]==1) f=0;
    if (f){
   
        int w=0;
        color(12);
        for (kx=x,ky=y; b2[kx][ky]==2; kx+=fx[k][0],ky+=fx[k][1]){
   
            gotoxy2(kx,ky);
            a2[kx][ky]="※";
            c2[kx][ky]=12; 
            cout <<"※";
            w++;
        }
        for (kx=x+fx[(k+2)%4][0],ky=y+fx[(k+2)%4][1]; b2[kx][ky]==2; kx+=fx[(k+2)%4][0],ky+=fx[(k+2)%4][1]){
   
            gotoxy2(kx,ky);
            a2[kx][ky]="※";
            c2[kx][ky]=12; 
            cout <<"※";
            w++;
        }

        if (w>0){
   
            rest[2][w]--;
            r2--; 
            if (rest[2][w]>0) color(14); else color(11);
            gotoxy2(5-w,16); printf("*%d",rest[2][w]);
        }
    }
}

int move1(){
   
    if (r1*r2==0) return(1);

    color(5); gotoxy1(14,4); printf("电脑开炮");
    color(13); gotoxy2(14,4); printf("玩家开炮");

    int kx=now[1][0],ky=now[1][1],lastx,lasty,f=1;
    char ch;
    gotoxy2(kx,ky); color(11); if (a2[kx][ky]!="  ")cout <<a2[kx][ky]; else cout <<"▂"; gotoxy2(kx,ky)
  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值