game

· · 个人记录

#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int read()
{
    int kk(0);
    bool fh=true;
    char ch=getchar();
    for(;ch<'0'||ch>'9';)
    {
        if(ch=='-')fh=false;
        ch=getchar();
    }
    for(;ch>='0'&&ch<='9';)
    {
        kk=(kk<<3)+(kk<<1)+(ch^48);
        ch=getchar();
    }
    return fh?kk:-kk;
}
long long readll()
{
    long long kk(0);
    bool fh=true;
    char ch=getchar();
    for(;ch<'0'||ch>'9';)
    {
        if(ch=='-')fh=false;
        ch=getchar();
    }
    for(;ch>='0'&&ch<='9';)
    {
        kk=(kk<<3)+(kk<<1)+(ch^48);
        ch=getchar();
    }
    return fh?kk:-kk;
}
#define INF 214748364
#define MOD 1000000007
#define MAXN
struct node
{
    int atk,hea;//
    char name[5];//
    int belong;//
    bool putable;
    bool empty;
    bool buff;//
    bool has_mine;
    int way;//1--yuancheng 2--jinshen 3--zihui 4--cichuan
    int range;//
    int rnd;
}field[5][10];
struct player
{
    int hea;
    int perk;
    int mana;
//  bool used;
    bool buff;
    int left;
    int tired;
    int power_per_round; 
}a[3];
char perk[5][5]={"","修复","破坏","渊博","圣盾"};
int rnd=1;
void print()       
{
    system("cls");
    printf("能量:%3d  01      02      03      04      05      06      07      08      09      10  能量:%3d\n",a[1].mana,a[2].mana);
    printf("/----\\  ");
    for(int i=1;i<=10;i++)
    {
        if(field[1][i].empty==false)printf("/----\\  ");
        else printf("        ");
    }
    puts("/----\\  ");
    printf("|%s|  ",perk[a[1].perk]);
    for(int i=1;i<=10;i++)
    {
        if(field[1][i].empty==false)printf("|%s|  ",field[1][i].name);
        else printf("        ");
    }
    printf("|%s|  \n",perk[a[2].perk]);
    printf("\\----/  ");
    for(int i=1;i<=10;i++)
    {
        if(field[1][i].empty==false)
        {
            printf("%d",field[1][i].atk);
            if(field[1][i].atk>=10)printf("--");
            else printf("---");
            if(field[1][i].hea<10)printf("-");
            printf("%d  ",field[1][i].atk);
        }
        else printf("        ");
    }
    printf("\\----/  \n");
    for(int i=1;i<=10;i++)
    {
        if(field[2][i].empty==false)printf("/----\\  ");
        else printf("        ");
    }
    printf("\n        ");
    for(int i=1;i<=10;i++)
    {
        if(field[2][i].empty==false)printf("|%s|  ",field[2][i].name);
        else printf("        ");
    }
    printf("\n/----\\  ");
    for(int i=1;i<=10;i++)
    {
        if(field[2][i].empty==false)
        {
            printf("%d",field[2][i].atk);
            if(field[2][i].atk>=10)printf("--");
            else printf("---");
            if(field[2][i].hea<10)printf("-");
            printf("%d  ",field[2][i].atk);
        }
        else printf("        ");
    }
    puts("/----\\");
    printf("|    |  ");
    for(int i=1;i<=10;i++)
    {
        if(field[3][i].empty==false)printf("/----\\  ");
        else printf("        ");
    }
    puts("|    |  ");
    printf("|    |  ");
    for(int i=1;i<=10;i++)
    {
        if(field[3][i].empty==false)printf("|%s|  ",field[3][i].name);
        else printf("        ");
    }
    puts("|    |  ");
    printf("\\---%2d  ",a[1].hea);
    for(int i=1;i<=10;i++)
    {
        if(field[3][i].empty==false)
        {
            printf("%d",field[3][i].atk);
            if(field[3][i].atk>=10)printf("--");
            else printf("---");
            if(field[3][i].hea<10)printf("-");
            printf("%d  ",field[3][i].atk);
        }
        else printf("        ");
    }
    printf("\\---%2d  ",a[2].hea);
    for(int i=1;i<=10;i++)
    {
        if(field[4][i].empty==false)printf("/----\\  ");
        else printf("        ");
    }
    printf("\n");
    for(int i=1;i<=10;i++)
    {
        if(field[4][i].empty==false)printf("|%s|  ",field[4][i].name);
        else printf("        ");
    }
    printf("\n%2d/50   ",a[1].left);
    for(int i=1;i<=10;i++)
    {
        if(field[4][i].empty==false)
        {
            printf("%d",field[4][i].atk);
            if(field[4][i].atk>=10)printf("--");
            else printf("---");
            if(field[4][i].hea<10)printf("-");
            printf("%d  ",field[4][i].atk);
        }
        else printf("        ");
    }
    printf("%2d/50   ",a[2].left);
    printf("\n这是第%3d轮\n",rnd);
}
void Init()
{
    for(int i=1;i<=4;i++)
    {
        for(int j=1;j<=10;j++)
        {
            if(j==5||j==6)
            {
                field[i][j].putable=false;
            }
            else
            {
                field[i][j].putable=true;
            }
            field[i][j].atk=0;
            field[i][j].empty=1;
            field[i][j].hea=0;
            field[i][j].rnd=1;
            field[i][j].belong=0;
            field[i][j].buff=false;
            field[i][j].has_mine=false;
        }
    }
    for(int i=1;i<=2;i++)
    {
        a[i].hea=50;
        a[i].mana=50;
        a[i].buff=false;
        a[i].left=50;
        a[i].tired=0;
    }
}
void start()
{
    for(int i=1;i<=2;i++)
    {
        printf("请玩家%d选择技能\n",i);
        puts("技能1 修复:使任意器械获得+0/+2 花费:25能量");
        puts("技能2 破坏:使任意器械获得-1/-2 花费:50能量");
        puts("技能3 渊博:使下一次花费减少25能量 花费:0能量");
        puts("技能4 圣盾:使任意器械免疫一次伤害 花费:25能量");
        int temp=read();
        while(1)
        {
            if(temp<=4&&temp>=0)
            {
                a[i].perk=temp;
                break;
            }
            else
            {
                puts("No this perk! Please input again");
                temp=read();
            }
        }
    }
    print();
}
bool end()
{
    for(int i=1;i<=2;i++)
    {
        if(a[i].hea<=0)return true;
    }
    return false;
}
void fz(int i)
{
    if(a[i].left==0)
    {
        printf("已用尽\n");
        return; 
    }
    printf("请输入坐标(x,y)");
    int x,y;
    while(1)
    {
        x=read(),y=read();
        if(x<=0||y<=0||x>4||y>10||!field[x][y].putable)
        {
            printf("非法坐标!请重新输入!\n");
            printf("请输入坐标(x,y)");
            continue;
        }
        else break;
    }
    int temp;
    const int atk[]={-1,0,1,3,3,7,10,3};
    const int hea[]={-1,3,2,3,8,0,5,5};
    char name[8][100]={"1","电源","弹弓","短弓","战车","地雷","炸弹","弓弩"};
    const int way[]={-1,1,1,1,2,3,3,4};
    const int cost[]={-1,50,0,100,150,75,125,150};
    while(1)
    {
        puts("请输入棋子编号:"); 
        puts("1 电源(50/0-3):前3回合每回合提供15能量,以后每回合提供25能量");
        puts("2 弹弓(0/1-2):对距离3以内的敌人造成1点伤害");
        puts("3 短弓(100/3-3):对任意敌人造成3点伤害");
        puts("4 战车(150/3-8):近战");
        puts("5 地雷(75/7-0):隐蔽");
        puts("6 炸弹(125/10-5):对3*3范围内的所有棋子造成10点伤害");
        puts("7 弓弩(150/3-5):对一列的所有棋子造成3点伤害");
        temp=read();
        if(temp<=0||temp>=8)
        {
            puts("错误的编号!");
            print();
            continue;
        }
        else if(a[i].mana<cost[temp])
        {
            puts("资金不足!");
            print();
            continue;
        }
        field[x][y].atk=atk[temp];
        field[x][y].hea=hea[temp]; 
        field[x][y].belong=i;
        field[x][y].has_mine=temp==5?1:0;
        field[x][y].putable=false;
        field[x][y].empty=false;
        strcpy(field[x][y].name,name[temp]);
        field[x][y].way=way[temp];
        a[i].mana-=cost[temp];
        print();
        break;
    }
}
void move()
{

}
void attack()
{

}
void pk(int i)
{

}
void play(int cur)
{
    if(a[cur].left==0)
    {
        a[cur].tired++;
        a[cur].hea-=a[cur].tired;
    }
    printf("你想做什么?1--放置棋子 2--移动棋子 3--进行攻击 4--发动技能 other--结束回合\n");
    int temp=read();
    if(temp==1)
    {
        fz(cur);
    }
    else if(temp==2)
    {
        move();
    }
    else if(temp==3)
    {
        attack();
    }
    else if(temp==4)
    {
        pk(a[cur].perk);
    }
    else return;
}
int main()
{
    Init();
    start();
    while(!end())
    {
        play(rnd%2);
        rnd++;
    }
    print();
    printf("\nPLAYER %d WINS!",rnd%2+1);
    return 0;
}