generals.oi v0.2.3 项目日志

版本日志

和 wu_yue 一起写的。

忽略了前期版本,之前的修改如下:

v0.2.1 更改终端设置
v0.2.2 更新迷雾,添加E,O撤销操作
v0.2.3 添加箭头

使用说明

目前操作数量较少:

可以在 mac 编译并使用终端打开,目前是单机二人版。
可以在终端设置中更改背景颜色和禁用方块闪烁;
红方使用WASD移动,Z键传送回home,1键释放鼠标指针,2键带50%兵,3键带100%兵,E键撤销操作;
红方使用IJKL移动,M键传送回home,8键释放鼠标指针,9键带50%兵,0键带100%兵,O键撤销操作。

代码

// #include<bits/stdc++.h>
#include<random>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <chrono>
#include <thread>
#include<fstream>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <cerrno>
#include <unistd.h>
#include<ctime>
#include<random>
#include <termios.h>
#include <fcntl.h>
#include <chrono>
#include <thread>
#include<fstream>
#include <stdio.h>
#include <map>
#include <queue>
#include <deque>

//#include "filecontrol.h"
//#include "keyboard.h"
void setTerminalSize(int rows, int cols) {
    // 格式: \033[8;<rows>;<cols>t
    std::cout << "\033[8;" << rows << ";" << cols << "t";
}

bool kbhit() {
    struct termios oldt, newt;
    int ch;
    int oldf;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
    fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
    ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    fcntl(STDIN_FILENO, F_SETFL, oldf);
    if (ch != EOF) {
        ungetc(ch, stdin);
        return true;
    }
    return false;
}
char getch() {
   char ch;
   struct termios oldt, newt;
   tcgetattr(STDIN_FILENO, &oldt);
   newt = oldt;
   newt.c_lflag &= ~(ICANON | ECHO);
   tcsetattr(STDIN_FILENO, TCSANOW, &newt);
   ch = getchar();
   tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
   return ch;
}
using namespace std;
class _file{
#define sc scanf
#define pr printf
#define v1 first
#define v2 second
private:
    const char*filename1="user.txt";
    const char*filename2="rating.txt";
    int user_size,online_user;
    map<string,string> account;
    vector<pair<string,string> > acc;
    vector<double> rating;
    map<string,int> online_id; 
    map<string,int> real_id;
    map<int,string> online_acc;
    void update_file(){
        FILE *fp=fopen(filename1,"w");
        fprintf(fp,"%d ",user_size);
        for(auto y:acc){
            fprintf(fp,"%s %s ",y.v1.c_str(),y.v2.c_str());
        }
        fclose(fp);
        FILE *fp2=fopen(filename2,"w");
        for(auto y:rating){
            fprintf(fp,"%.9lf ",y);
        }
        fclose(fp2);
    }
    double calc(double ply,bool op){
        double add=min(10.0,30.0/sqrt(ply)+5/ply+4/ply/ply+3/ply/ply/ply);
        double minus=0.05*ply+sqrt(ply)+pow(0.5,ply)*0.2-0.2;
        if(op){
            return ply+add;
        }
        else{
            return max(ply-minus,0.0);
        }
    }
    double change_user_rating(const int user_id,bool op){
        double change=calc(rating[user_id],op);
        rating[user_id]=change;
        update_file();
        return change;
    }
public:
    bool init_file(){
        string s1,s2;
        FILE *fp=fopen(filename1,"r");
        if(!fp)
            return 0;
        char c;
        int sum=0;
        while(1){
            c=fgetc(fp);
            if(feof(fp))
                break;
            if(c==' '){
                if(!sum){
                    user_size=stoi(s2);
                    s2="";
                }
                else if((sum&1)==0){
                    account[s1]=s2;
                    acc.push_back(make_pair(s1,s2));
                    real_id[s1]=sum/2-1;
                    s1="";
                    s2="";
                }
                sum++;
                continue;
            }
            if(sum&1)s1+=c;
            else s2+=c;
        }
        fclose(fp);
        FILE *fp2=fopen(filename2,"r");
        if(!fp2)
            return 0;
        string ss;
        while(1){
            c=fgetc(fp2);
            if(feof(fp2))
                break;
            if(c==' '){
                rating.push_back(stod(ss));
                ss="";
                continue;
            }
            ss+=c;
        }
        fclose(fp2);
        return 1;
    }
    bool judge_game(const string user1,const string user2,const string winner){
        if(account[user1]==""||account[user2]==""||(winner!=user1&&winner!=user2))
            return 0;
        if(winner==user1){
            change_user_rating(real_id[user1],1);
            change_user_rating(real_id[user2],0);
        }
        else{
            change_user_rating(real_id[user1],0);
            change_user_rating(real_id[user2],1);
        }
        return 1;
    }
    bool create_new_account(string name,string password){
        if(account[name]!="")
            return 0;
        user_size++;
        account[name]=password;
        acc.push_back(make_pair(name,password));
        real_id[name]=user_size-1;
        rating.push_back(0);
        update_file();
        return 1;
    }
    bool log_in(string s1,string s2){
        if(account[s1]==""||account[s1]!=s2)
            return 0;
        online_id[s1]=++online_user;
        online_acc[online_user]=s1;
        return 1;
    }
    double get_rating(string name){
        return rating[real_id[name]];
    }
#undef sc
#undef pr
#undef v1
#undef v2
}f_control;

void Delay(int time){
    auto start = chrono::steady_clock::now();
    while(chrono::steady_clock::now()-start <chrono::milliseconds(time));
}
random_device rd;
mt19937 rng(rd());
int randint(int l,int r){
    uniform_int_distribution<int> dis(l,r);
    return dis(rng);
}
#undef x1
#undef y1
int getdis(int x1,int y1,int x2,int y2){
    return abs(x1-x2)+abs(y1-y2);
}
namespace game{
#define MINDIS 20
#define MAXSZ 200
const int mapx=20,mapy=20;
int n,m;
int rating;
const int plynum=2;
bool game_over=0;
string pos;
map<int,char> mptochar;
struct mapnode{
    int val,type=1,color1=90,color2=40;
    int finded=0;
    int sd;
    int arw[4];
    mapnode(int _val,int _type,int _color1,int _color2,int _finded,int _sd,int _arw0,int _arw1,int _arw2,int _arw3){
        val=_val;
        type=_type;
        color1=_color1;
        color2=_color2;
        finded=_finded;
        sd=_sd;
        arw[0]=_arw0;
        arw[1]=_arw1;
        arw[2]=_arw2;
        arw[3]=_arw3;
    }
    mapnode(){
        arw[0]=arw[1]=arw[2]=arw[3]=0;
    }
} mp[MAXSZ][MAXSZ];
const mapnode 
myland(0,1,37,41,1,0,0,0,0,0),
//myhome(1,4,91,40,1,0),
myhome(1,4,93,40,1,0,0,0,0,0),
mount(0,2,37,40,0,-1,0,0,0,0),
enland(0,1,37,41,1,1,0,0,0,0),
enhome(1,4,91,40,1,1,0,0,0,0),
nll(0,0,90,40,0,-1,0,0,0,0);
const string admin_nm1="Player 1",admin_ps1="wu_yue",admin_nm2="Player 2",admin_ps2="wangtairan114";
struct player{
    int x,y,id;
    int msx,msy;
    int homex,homey;
    int color1,color2;
    int landcnt,unitcnt;
    int con;//con=0 release con=1 0.5 con=2 1
    int mscon;
    string plyername;
    deque<pair<pair<int,int>,pair<int,int> > > task_queue;
    player(){
    }
    
}p[2];
void auto_login(string usname,string uspassword,int plyerid){
    if(!f_control.log_in(usname,uspassword)){
        if(!f_control.create_new_account(usname,uspassword)){
            cout << "Login Error";
            exit(0);
        }
        f_control.log_in(usname,uspassword);
    }
    p[plyerid].plyername=usname;
}
void init(){
    f_control.init_file();
    setTerminalSize(1000,1000);
    auto_login(admin_nm1,admin_ps1,0);
    auto_login(admin_nm2,admin_ps2,1);
    mptochar[0]='.';//空地
    mptochar[1]=' ';
    mptochar[2]='#';//mount
    mptochar[3]='*';//tower
    mptochar[4]='@';//home

}
void clear_deque(deque<pair<pair<int,int>,pair<int,int> > > &dq){
    while(dq.size()){
        if(dq.front().second.second){
            if(dq.front().second.first<=3){
                mp[dq.front().first.first][dq.front().first.second].arw[dq.front().second.first]--;
            }
        }
        dq.pop_front();
    }
}
#undef x1
#undef y1
bool reach(int x1,int y1,int x2,int y2){
    bool bl[MAXSZ][MAXSZ];
    memset(bl,0,sizeof(bl));
    int dir[4][2]={1,0,-1,0,0,1,0,-1};
    queue<pair<int,int> > q;
    q.push(make_pair(x1,y1));
    bl[x1][y1]=1;
    while(q.size()){
        int ply=q.front().first;
        int y=q.front().second;
        q.pop();
        for(int i=0; i < 4; i++){
            int xx=ply+dir[i][0];
            int yy=y+dir[i][1];
            if(xx>0&&xx<=mapx&&yy>0&&yy<=mapy&&!bl[xx][yy]&&mp[xx][yy].type!=2){
                bl[xx][yy]=1;
                q.push(make_pair(xx,yy));
            }
        }
    }
    for(int i=1; i <= mapx; i++){
        for(int j=1; j <= mapy; j++){
            if(mp[i][j].type==2)
                continue;
            if(!bl[i][j])
                return 0;
        }
    }
    return 1;
}
void initmap(){
    p[0].con=p[1].con=p[0].mscon=p[1].mscon=2;
    p[0].landcnt=1;
    p[1].landcnt=1;
    p[0].unitcnt=0;
    p[1].unitcnt=0;
    clear_deque(p[0].task_queue);
    clear_deque(p[1].task_queue);
    mp[p[0].homex][p[0].homey]=nll;
    mp[p[1].homex][p[1].homey]=nll;
    p[0].msx=p[0].x=p[0].homex=randint(1,mapx);
    p[0].msy=p[0].y=p[0].homey=randint(1,mapy);
    p[0].id=0;
    p[0].color1=37;
    p[0].color2=41;
    mp[p[0].homex][p[0].homey]=myhome;
    p[1].x=p[0].x;
    p[1].y=p[0].y;
    p[1].id=1;
    while(getdis(p[0].x,p[0].y,p[1].x,p[1].y)<MINDIS){
        p[1].x=randint(1,mapx);
        p[1].y=randint(1,mapy);
    }
    p[1].msx=p[1].homex=p[1].x;
    p[1].msy=p[1].homey=p[1].y;
    mp[p[1].homex][p[1].homey]=mapnode(1,4,92,40,2,1,0,0,0,0);
    p[1].color1=37;
    p[1].color2=44;
    int rndint;
    while(1){
        for(int i=1;i<=mapx;i++){
            for(int j=1;j<=mapy;j++){
                auto &mp1=mp[i][j];
                if(mp1.type==4)
                    continue;
                rndint=randint(1,30);
                if(rndint<=5) mp[i][j]=mount;
                else if(rndint<=7){
                    mp1=nll;
                    mp1.type=3;
                    mp1.val=randint(35,50);
                    mp1.color1=37;
                } 
                else
                    mp[i][j]=nll;
            }
        }
        if(reach(p[0].homex,p[0].homey,p[1].homex,p[1].homey))
            break;
    }
    mp[p[0].homex][p[0].homey].finded=1;
    mp[p[0].homex][p[0].homey+1].finded=1;
    mp[p[0].homex+1][p[0].homey].finded=1;
    mp[p[0].homex-1][p[0].homey].finded=1;
    mp[p[0].homex][p[0].homey-1].finded=1;

    mp[p[1].homex][p[1].homey].finded=2;
    mp[p[1].homex][p[1].homey+1].finded=2;
    mp[p[1].homex+1][p[1].homey].finded=2;
    mp[p[1].homex-1][p[1].homey].finded=2;
    mp[p[1].homex][p[1].homey-1].finded=2;
    mp[p[0].homex+1][p[0].homey+1].finded=1;
    mp[p[0].homex+1][p[0].homey-1].finded=1;
    mp[p[0].homex-1][p[0].homey+1].finded=1;
    mp[p[0].homex-1][p[0].homey-1].finded=1;

    mp[p[1].homex+1][p[1].homey+1].finded=2;
    mp[p[1].homex+1][p[1].homey-1].finded=2;
    mp[p[1].homex-1][p[1].homey+1].finded=2;
    mp[p[1].homex-1][p[1].homey-1].finded=2;
}
bool cmp_ply(){
    if(p[0].unitcnt!=p[1].unitcnt){
        return p[0].unitcnt<p[1].unitcnt;
    }
    return p[0].landcnt<p[1].landcnt;
}
void debugprint(){
    string colorstr;
    int maxlen=max(p[0].plyername.size(),p[1].plyername.size());
    maxlen=max(maxlen,6);
    int idx=cmp_ply();
    for(int i=1;i<=mapx;i++){
        pos="\033["+to_string((i-1)*3+1)+";"+to_string(1)+"H";
        cout<<pos;
        cout <<"\033[K";
        for(int j = 1; j <= mapy; j++) {
            auto &mp1 = mp[i][j];
            // cout << mp1.arw[2];
            if(mp1.arw[2]){
                cout<< "←";
            }
            else
                cout << " ";
            if(mp1.finded==0) {
                //colorstr="\033[0;90;40m";
                colorstr="\033[0;" + to_string(mp[i][j].color1) + ";" + to_string(mp[i][j].color2) + "m";
                if(i==p[0].msx&&j==p[0].msy||i==p[1].msx&&j==p[1].msy) colorstr+="\033[4m",colorstr+="\033[58;5;255m";
                cout<<"  "<<colorstr<<"."<<"\033[0m ";
            }
            else{
                colorstr = "\033[0;" + to_string(mp[i][j].color1) + ";" + to_string(mp[i][j].color2) + "m";
                if(i==p[0].msx&&j==p[0].msy||i==p[1].msx&&j==p[1].msy) colorstr+="\033[4m",colorstr+="\033[58;5;255m";
                if(mp1.type==2){
                    cout<<" "<<colorstr<<"##"<<"\033[0m ";
                }
                else {
                    if(0<=mp1.val&&mp1.val<=9) cout<<" "<<colorstr<<mp1.val<<mptochar[mp1.type]<<"\033[0m"<<" ";
                    else if(10<=mp1.val&&mp1.val<=99) cout<<""<<colorstr<<mp1.val<<mptochar[mp1.type]<<"\033[0m"<<" ";
                    else if(100<=mp1.val&&mp1.val<=999) cout<<""<<colorstr<<mp1.val<<mptochar[mp1.type]<<"\033[0m"<<"";
                    else if(1000<=mp1.val&&mp1.val<=9999) cout<<""<<colorstr<<(mp1.val/1000)<<"……"<<mptochar[mp1.type]<<"\033[0m"<<"";
                }
            }
            // cout << mp1.arw[3];
            if(mp1.arw[3]){
                cout <<"→";
            }
            else
                cout << " ";
        }
        string str;
        if(i==1){
            str= "Player";
        }
        else if(i==2){
            str=p[idx].plyername;
        }
        else if(i==3){
            str=p[idx^1].plyername;
        }
        cout<< str;
        cout << " ";
        if(i==1){
            cout<<"     ";
        }
        else if(i==2){
            printf("%-5.1lf",f_control.get_rating(p[idx].plyername));
        }
        else if(i==3){
            printf("%-5.1lf",f_control.get_rating(p[idx^1].plyername));
        }
        for(int j=1; j <= maxlen-str.size()+1; j++)
            cout << " ";
        if(i==1){
            cout << "Unit  Land";
        }
        else if(i==2){
            printf("%-6d%-4d",p[idx].unitcnt,p[idx].landcnt);
        }
        else if(i==3){
            printf("%-6d%-4d",p[idx^1].unitcnt,p[idx^1].landcnt);
        }
        cout<<"\n";
        for(int j=1;j<=mapy;j++){
            cout<<"  ";
            // cout << mp[i][j].arw[1];
            if(mp[i][j].arw[1]){
                cout << "↓";
            }
            else
                cout << " ";
            cout << "   ";
        }
        cout<<"\n";
        for(int j=1;j<=mapy;j++){
            cout<<"  ";
            // cout <<mp[i+1][j].arw[0];
            if(mp[i+1][j].arw[0]){
                cout << "↑";
            }
            else
                cout << " ";
            cout << "   ";
        }
        cout<<"\n";

    }

}
int move_point(int plyerid,pair<pair<int,int>,pair<int,int> > inp);
void reload(int t){
    if(t%50==0){
        for(int i=1;i<=mapx;i++){
            for(int j=1;j<=mapy;j++){
                if(mp[i][j].type>=1 && mp[i][j].type<=4&&mp[i][j].sd>=0){
                    mp[i][j].val++;
                    p[mp[i][j].sd].unitcnt++;
                }
            }
        }
    }
    else if(t%2==0){
        for(int i=1;i<=mapx;i++){
            for(int j=1;j<=mapy;j++){
                auto &mp1=mp[i][j];
                if(mp1.type==3||mp1.type==4){
                    if(mp1.sd>=0) {
                        mp1.val++;
                        p[mp1.sd].unitcnt++;
                    }
                }
            }
        }
    }
    for(int i=0; i < plynum; i++){
        while(p[i].task_queue.size()){
             int res=move_point(i,p[i].task_queue.front());
             p[i].task_queue.pop_front();
             if(res==-1){
                p[i].x=p[i].msx;
                p[i].y=p[i].msy;
                p[i].con=p[i].mscon;
                clear_deque(p[i].task_queue);
                break;
            }
            if(res==1)
                break;
        }
    }
    return;
}
int dir[8][2]={-1,0,1,0,0,-1,0,1,1,-1,-1,1,1,1,-1,-1};
void move(int id,int x1,int y1,int x2,int y2){
    if(mp[x1][y1].val<=1){
        return;
    }
    int val=mp[x1][y1].val-1;
    if(p[mp[x1][y1].sd].con==1) val=(val+1)>>1;
    if(mp[x1][y1].sd==mp[x2][y2].sd){
        mp[x1][y1].val-=val;
        mp[x2][y2].val+=val;
        return;
    }
    mp[x1][y1].val-=val;
    if(val>mp[x2][y2].val){
        //这里还要对对方操作
        p[id].landcnt++;
        p[id].unitcnt-=mp[x2][y2].val;
        if(mp[x2][y2].sd>=0){
            p[mp[x2][y2].sd].landcnt--;
            p[mp[x2][y2].sd].unitcnt-=mp[x2][y2].val;
        }
        val-=mp[x2][y2].val;
        mp[x2][y2]=mapnode(val,mp[x2][y2].type,p[id].color1,p[id].color2,1<<id,id,mp[x2][y2].arw[0],mp[x2][y2].arw[1],mp[x2][y2].arw[2],mp[x2][y2].arw[3]);
        if(mp[x2][y2].type==0) mp[x2][y2].type=1;
        for(int i=0; i <= 7; i++){
            int nx=x2+dir[i][0];
            int ny=y2+dir[i][1];
            if(nx>=1&&nx<=mapx&&ny>=1&&ny<=mapy)
                mp[nx][ny].finded=1<<id;
        }
        if(mp[x2][y2].type==4){
            debugprint();
            f_control.judge_game(p[0].plyername,p[1].plyername,p[id].plyername);
            cout<<"you win";
            game_over=1;
            return;
        }
    }
    else{
        p[id].unitcnt-=val;
        if(mp[x2][y2].sd>=0)
            p[mp[x2][y2].sd].unitcnt-=val;
        mp[x2][y2].val-=val;
    }
}
int move_point(int plyerid,pair<pair<int,int>,pair<int,int> > inp) {
    player &ply=p[plyerid];
    const mapnode &mp1=mp[ply.x][ply.y];
    if(inp.second.first<=3){
        p[plyerid].x=inp.first.first+dir[inp.second.first][0];
        p[plyerid].y=inp.first.second+dir[inp.second.first][1];
        if(!inp.second.second){
            return 0;
        }
        mp[inp.first.first][inp.first.second].arw[inp.second.first]--;
        if(mp[p[plyerid].x][p[plyerid].y].type!=2){
            if(mp[inp.first.first][inp.first.second].sd==plyerid)
                move(plyerid,inp.first.first,inp.first.second,p[plyerid].x,p[plyerid].y);
            return 1;
        }
        return -1;
    }
    else if(inp.second.first==4){
        p[plyerid].x=p[plyerid].homex;
        p[plyerid].y=p[plyerid].homey;
    }
    else if(inp.second.first<=7){
        p[plyerid].con=inp.second.second;
    }
    return 0;
}
void judge_input(char inp){
    int plyerid=0;
    if(inp=='w'){
            if(p[plyerid].msx>1){
                if(p[plyerid].mscon)
                   mp[p[plyerid].msx][p[plyerid].msy].arw[0]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(0,p[plyerid].mscon)));
                p[plyerid].msx--;
            }
        return ;
    }
    else if(inp=='s'){
            if(p[plyerid].msx<mapx){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[1]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(1,p[plyerid].mscon)));
                p[plyerid].msx++;
            }
        return ;
    }
    else if(inp=='a'){
            if(p[plyerid].msy>1){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[2]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(2,p[plyerid].mscon)));
                p[plyerid].msy--;
            }
        return ;
    }
    else if(inp=='d'){
            if(p[plyerid].msy<mapy){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[3]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(3,p[plyerid].mscon)));
                p[plyerid].msy++;
            }
        return ;
    }
    else if(inp=='z'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(4,p[plyerid].mscon)));
        p[plyerid].msx=p[plyerid].homex;
        p[plyerid].msy=p[plyerid].homey;
        return ;
    }
    plyerid=1;
    if(inp=='i'){
            if(p[plyerid].msx>1){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[0]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(0,p[plyerid].mscon)));
                p[plyerid].msx--;
            }
        return ;
    }
    else if(inp=='k'){
            if(p[plyerid].msx<mapx){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[1]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(1,p[plyerid].mscon)));
                p[plyerid].msx++;
            }
        return ;
    }
    else if(inp=='j'){
            if(p[plyerid].msy>1){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[2]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(2,p[plyerid].mscon)));
                p[plyerid].msy--;
            }
        return ;
    }
    else if(inp=='l'){
            if(p[plyerid].msy<mapy){
                if(p[plyerid].mscon)
                    mp[p[plyerid].msx][p[plyerid].msy].arw[3]++;
                p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(3,p[plyerid].mscon)));
                p[plyerid].msy++;
            }
        return ;
    }
    else if(inp=='m'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].msx,p[plyerid].msy),make_pair(4,p[plyerid].mscon)));
        p[plyerid].msx=p[plyerid].homex;
        p[plyerid].msy=p[plyerid].homey;
        // p[plyerid].task_queue.push_back(inp);
        return ;
    }
    plyerid=0;
    if(inp=='1'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(5,0)));
        p[plyerid].mscon=0;
    }
    else if(inp=='2'){
        // p[plyerid].task_queue.push_back(inp);
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(6,1)));
        p[plyerid].mscon=1;
    }
    else if(inp=='3'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(7,2)));
        p[plyerid].mscon=2;
    }
    else if(inp=='e'){
        if(!p[plyerid].task_queue.size())
            return;
        pair<pair<int,int>,pair<int,int> > res=p[plyerid].task_queue.back();
        p[plyerid].task_queue.pop_back();
        if(res.second.first<=3){
            p[plyerid].msx=res.first.first,p[plyerid].msy=res.first.second;
            if(res.second.second)
                mp[res.first.first][res.first.second].arw[res.second.first]--;
        }
        else if(res.second.first==4){
            p[plyerid].msx=res.first.first,p[plyerid].msy=res.first.second;
        }
        else if(res.second.first<=7){
            p[plyerid].mscon=res.first.first;
        }
    }
    plyerid=1;
    if(inp=='8'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(5,0)));
        p[plyerid].mscon=0;
    }
    else if(inp=='9'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(6,1)));
        p[plyerid].mscon=1;
    }
    else if(inp=='0'){
        p[plyerid].task_queue.push_back(make_pair(make_pair(p[plyerid].mscon,0),make_pair(7,2)));
        p[plyerid].mscon=2;
    }
    else if(inp=='o'){
        if(!p[plyerid].task_queue.size())
            return;
        pair<pair<int,int>,pair<int,int> > res=p[plyerid].task_queue.back();
        p[plyerid].task_queue.pop_back();
        if(res.second.first<=3){
            p[plyerid].msx=res.first.first,p[plyerid].msy=res.first.second;
            if(res.second.second)
                mp[res.first.first][res.first.second].arw[res.second.first]--;
        }
        else if(res.second.first==4){
            p[plyerid].msx=res.first.first,p[plyerid].msy=res.first.second;
        }
        else if(res.second.first<=7){
            p[plyerid].mscon=res.first.first;
        }
    }
}
void one_game(){
    initmap();
    game_over=0;
    int tm=0;
    auto start = chrono::steady_clock::now();
    debugprint();
    while(1){
        while(!kbhit()){
            if(chrono::steady_clock::now()-start >=chrono::milliseconds(500)){
                tm++;
                reload(tm);
                if(game_over)
                    return;
                start=chrono::steady_clock::now();
                debugprint();
            }
        }
        char inp;
        inp=getch();
        judge_input(inp);
        debugprint();
    }
}
void lobby(){
        cout<<"\033[2J\033[H";
        cout<<"         Lobby"<<"\n\n";
        cout<<"         "<< admin_nm1<<": "<<f_control.get_rating(admin_nm1)<<"\n";
        cout<<"         "<< admin_nm2<<": "<<f_control.get_rating(admin_nm2)<<"\n";
        cout<<"         Press Anywhere to Start Game\n";
        cout<<"         [0]Exit"<<"\n";
        char ch;
        while(!kbhit())
            Delay(2);
        ch=getch();
    if(ch=='0')exit(0);
    cout<<"\033[2J\033[H";
    one_game();
}
void start(){
	Delay(1000);
	cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n";
	// cout<<"         抵制不良游戏,拒绝盗版游戏。\n";
	// cout<<"         注意自我保护,谨防受骗上当。\n";
	// cout<<"         适度游戏益脑,沉迷游戏伤身。\n";
	// cout<<"         合理安排时间,享受健康生活。\n";
    cout<<"         抵制不良题目,拒绝毒瘤题目。\n";
	cout<<"         注意自我保护,谨防受骗上当。\n";
	cout<<"         适度O I益脑 ,沉迷O I伤身。\n";
	cout<<"         合理安排时间,享受挂分生活。\n";
	Delay(3000);
	
	//system("cls");
    cout<<"\033[2J\033[H";
	Delay(1000);
	cout<<"----------------Generals.oi-----------------"<<endl<<endl; 
	cout<<"         Press any key to start!"<<endl;
	//cout<<"                       (0键读取存档)"<<endl; 
	char ch;
	ch=getch();

	Delay(1000);

	cout<<"Welcome to play  ";
    cout<<"generals.oi"<<endl;Delay(1000);
	//cout<<"made by wu_yue  &&  wangtairan114"<<endl; Delay(1000);
	//system("pause");
    cout<<"\033[2J\033[H";
}
}

int main(){
    // game::start();
    game::init();
    while(1){
        game::lobby();
    }
    return 0;
}
posted @ 2025-12-25 16:15  wangtairan114  阅读(3)  评论(0)    收藏  举报