可以考虑一下C++实现泰拉瑞亚?

部署运行你感兴趣的模型镜像

V1.0

#include<iostream>
#include<cstdio>
#include"game.h"
#include<cstdlib>
#include<ctime>
#include<map>
using namespace std;
const int WIN_SIZE = 24;
SYSTEMTIME sys;

/*                                                      -------------WELCOME--------------                                                          */

void project() {
    SetConsoleTitle("Floatiy World");
    system("mode con cols=49 lines=31");
    srand(time(NULL));
}
void welcome_print() {
    cout<<"                                                "<<endl;
    cout<<"  □      □              □                □  "<<endl;
    cout<<"                                  □            "<<endl;
    cout<<"          M A D E   B Y   F L O A T I Y   □    "<<endl;
    cout<<"    □                          □              "<<endl;//5
    cout<<"                                                "<<endl;
    cout<<"    □□□□□          □□□          □□□  "<<endl;
    cout<<"    □                    □              □    "<<endl;
    cout<<"    □                    □              □    "<<endl;
    cout<<"    □                      □    □    □      "<<endl;//10
    cout<<"    □□□□      □□      □    □    □      "<<endl;
    cout<<"    □            □□      □    □    □      "<<endl;
    cout<<"    □                      □  □  □  □      "<<endl;
    cout<<"    □                      □□      □□      "<<endl;
    cout<<"    □                      □          □      "<<endl;//15
    cout<<"                                                "<<endl;
    cout<<"                                                "<<endl;
    cout<<"            □                □                "<<endl;
    cout<<"                                    □          "<<endl;
    cout<<"      □          LODING......                  "<<endl;//20
    cout<<"□                                          □  "<<endl;
    cout<<"                                      □        "<<endl;
    cout<<"□□□□□□□□□□□□□□□□□□□□□□□□"<<endl;
    cout<<"□□□□□□□□□□□□□□□□□□□□□□□□"<<endl;//24
    cout<<"================================================"<<endl;//25
    cout<<"=====   If you have any questions about   ======"<<endl;
    cout<<"=====   this game, please send a message  ======"<<endl;
    cout<<"=====   to me at blog.youkuaiyun.com/floatiy    ======"<<endl;
    cout<<"=====        HOPE  YOU  HAVE  FUN!        ======"<<endl;
    cout<<"================================================"<<endl;//30
    Sleep(1500);
    return;
}

/*                                                      -------------INIT--------------                                                         */

string world[100][100];
struct Player {
    int hp;
    int hungry;
    int bag[100];
    int x,y;
    int jump;
    string hand;
} player;
map<string,int> item;
map<int,string> id;

void map_create();
void player_create();
void items_create();
void tree_create();
void init() {
    map_create();
    items_create();
    player_create();
}
void map_create() {
    int last = WIN_SIZE - 4;
    for(int i = 1; i <= WIN_SIZE; i++) {
        int tmp = last + rand()%3 - 1;
        last = tmp;
        int j;
        for(j = WIN_SIZE; j >= tmp; j--) world[j][i] = "stone";
        j++;
        world[j-1][i] = world[j-2][i] = "dirt";
        world[j-3][i] = "gress";
        world[WIN_SIZE][i] = "bedstone";
    }
    tree_create();
}
int jd(int x) {
    if(x) return x;
    return -x+1;
}
void tree_create() {
    for(int iu = 1; iu <= 3; iu++) {
        int opt = rand() % WIN_SIZE;
        int high = 5 + rand()%3 - 1;
        int i;
        for(i = 1; i <= WIN_SIZE; i++) {
            if(world[i][opt] == "gress") break;
        }
        int j;
        for(j = 1; j <= high && (i - j - 1); j++) {
            world[i-j][opt] = "treewood";
        }
        for(int a = -2; a <= 2; a++) {
            for(int b = -2; b <= 2; b++) {
                if(rand()%jd(a+b) <= 2) {
                    if((a==-2||a==2)&&(b==-2||b==2)) continue;
                    if(j + a <= 0 || j + a >= WIN_SIZE+1 || opt + b <= 0 || opt + b >= WIN_SIZE+1) continue;
                    world[i-j + a][opt + b] = "leaf";
                }
            }
        }
    }
}
void items_create() {
    item["nothing"] = 0;
    item["pickaxe"] = 1;
    item["axe"] = 2;
    item["sword"] = 3;
    item["bow"] = 4;
    item["apple"] = 5;
    item["meat"] = 6;
    item["arrow"] = 7;
    item["clip"] = 8;
    item["stone"] = 9;
    item["dirt"] = 10;
    item["seed"] = 11;
    item["wood"] = 12;
    item["tree_seed"] = 13;
    item["boom"] = 14;

    id[0] = "nothing";
    id[1] = "pickaxe";
    id[2] = "axe";
    id[3] = "sword";
    id[4] = "bow";
    id[5] = "apple";
    id[6] = "meat";
    id[7] = "arrow";
    id[8] = "clip";
    id[9] = "stone";
    id[10] = "dirt";
    id[11] = "seed";
    id[12] = "wood";
    id[13] = "tree_seed";
    id[14] = "boom";
}
void player_create() {
    player.hp = 100;
    player.hungry = 100;
    for(int i = 1; i <= WIN_SIZE; i++) {
        if(world[i][12] == "gress") {
            player.x = i-1;
            player.y = 12;
            break;
        }
    }
    player.hand = "nothing";
    player.bag[0] = 1;
}
/*                                                      -------------PRINT--------------                                                            */
void print_stone(int x,int y);
void print_dirt(int x,int y);
void print_gress(int x,int y);
void print_treewood(int x,int y);
void print_leaf(int x,int y);
void print_bedstone(int x,int y);
void print_seting();
void world_print() {
    system("cls");
    for(int i = 1; i <= WIN_SIZE; i++) {
        for(int j = 1; j <= WIN_SIZE; j++) {
            if(world[i][j] == "stone") print_stone(i,j);
            else if(world[i][j] == "dirt") print_dirt(i,j);
            else if(world[i][j] == "gress") print_gress(i,j);
            else if(world[i][j] == "treewood") print_treewood(i,j);
            else if(world[i][j] == "leaf") print_leaf(i,j);
            else if(world[i][j] == "bedstone") print_bedstone(i,j);
        }
    }
    print_seting();
}
void print_seting() {
    Locate(25,1);
    printf("================================================\n");
    if(player.hand == "nothing") printf("===  Item in your hand:  nothing             ===\n");
    if(player.hand == "pickaxe") printf("===  Item in your hand:  pickaxe             ===\n");
    if(player.hand == "axe") printf("===  Item in your hand:  axe                     ===\n");
    if(player.hand == "sword") printf("===  Item in your hand:  sword                 ===\n");
    if(player.hand == "bow") printf("===  Item in your hand:  bow                     ===\n");
    if(player.hand == "apple") printf("===  Item in your hand:  apple                 ===\n");
    if(player.hand == "meat") printf("===  Item in your hand:  meat                   ===\n");
    if(player.hand == "arrow") printf("===  Item in your hand:  arrow                 ===\n");
    if(player.hand == "clip") printf("===  Item in your hand:  clip                   ===\n");
    if(player.hand == "stone") printf("===  Item in your hand:  stone                 ===\n");
    if(player.hand == "dirt") printf("===  Item in your hand:  dirt                   ===\n");
    if(player.hand == "seed") printf("===  Item in your hand:  seed                   ===\n");
    if(player.hand == "wood") printf("===  Item in your hand:  wood                   ===\n");
    if(player.hand == "tree_seed") printf("===  Item in your hand:  tree_seed         ===\n");
    if(player.hand == "boom") printf("===  Item in your hand:  boom                   ===\n");
    Locate(27,1);
    printf("===  Bag:                                    ===\n");
    printf("===                                          ===\n");
    printf("===                                          ===\n");
    if(player.bag[item["pickaxe"]]) Locate(28,7/2),printf("pickaxe");
    if(player.bag[item["axe"]]) Locate(28,17/2),printf("axe");
    if(player.bag[item["sword"]]) Locate(28,23/2),printf("sword");
//  if(player.bag[item[4]]) Locate(28,7),printf("apple");
    if(player.bag[item["apple"]]) Locate(28,31/2),printf("apple");
//  if(player.bag[item[6]]) Locate(28,7),printf("pickaxe");
//  if(player.bag[item[7]]) Locate(28,7),printf("pickaxe");
//  if(player.bag[item[8]]) Locate(28,7),printf("pickaxe");
    if(player.bag[item["stone"]]) Locate(28,7/2),printf("stone");
    if(player.bag[item["dirt"]]) Locate(28,15/2),printf("dirt");
    if(player.bag[item["wood"]]) Locate(28,22/2),printf("wood");
    /*
        item["nothing"] = 0;
        item["pickaxe"] = 1;
        item["axe"] = 2;
        item["sword"] = 3;
        item["bow"] = 4;
        item["apple"] = 5;
        item["meat"] = 6;
        item["arrow"] = 7;
        item["clip"] = 8;
        item["stone"] = 9;
        item["dirt"] = 10;
        item["seed"] = 11;
        item["wood"] = 12;
        item["tree_seed"] = 13;
        item["boom"] = 14;
    */
//  printf("===   pickaxe,  axe,  sword,  apple,  meat   ===\n");
//  printf("===   stone,  dirt,  wood,  seed,  treeseed  ===\n");
    printf("================================================\n");
}
void print_stone(int x,int y) {
    Setcolor(GRAY);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_dirt(int x,int y) {
    Setcolor(DARKYELLOW);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_gress(int x,int y) {
    Setcolor(DARKGREEN);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_treewood(int x,int y) {
    Setcolor(DARKGREEN);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_leaf(int x,int y) {
    Setcolor(GREEN);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_bedstone(int x,int y) {
    Setcolor(DARKGRAY);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_wood(int x,int y) {
    Setcolor(DARKRED);
    Locate(x,y);
    printf("■");
    Setcolor(GRAY);
}
void print_player(int x,int y) {
//  cout<<player.x<<" "<<player.y<<endl;
    Setcolor(TEAL);
    Locate(x,y);
    printf("♀");
    Setcolor(GRAY);
}
void clean_player(int x,int y) {
    if(world[x][y] == "treewood") {
        print_treewood(x,y);
        return;
    } else if(world[x][y] == "leaf") {
        print_leaf(x,y);
        return;
    }
    Locate(x,y);
    printf(" ");
}
void clean_block(int x,int y) {
    Locate(x,y);
    printf(" ");
}
/*                                                      -------------Playing--------------                                                          */
bool judge(int x,int y) {
    if(world[x][y] == "stone") return false;
    else if(world[x][y] == "dirt") return false;
    else if(world[x][y] == "gress") return false;
    else if(world[x][y] == "wood") return false;
    else if(world[x][y] == "bedstone") return false;
    if(x <= 0 || x >= WIN_SIZE+1 || y <= 0 || y >= WIN_SIZE+1) return false;
    return true;
}
void go_left() {
    if(judge(player.x,player.y-1)) {
        clean_player(player.x,player.y);
        player.y--;
        print_player(player.x,player.y);
    }
}
void go_right() {
    if(judge(player.x,player.y+1)) {
        clean_player(player.x,player.y);
        player.y++;
        print_player(player.x,player.y);
    }
}
void jump() {
    if(!player.jump&&!judge(player.x+1,player.y)) player.jump = 3;
}
judge_hit(int x,int y) {
    if(world[x][y] == "stone") return true;
    else if(world[x][y] == "dirt") return true;
    else if(world[x][y] == "gress") return true;
    else if(world[x][y] == "treewood") {
//      cout<<"fafafa";
        return true;
    }
    else if(world[x][y] == "leaf") return true;
    else if(world[x][y] == "wood") return true;
    else if(world[x][y] == "bedstone") return false;
    if(x <= 0 || x >= WIN_SIZE+1 || y <= 0 || y >= WIN_SIZE+1) return false;
    return false;
}
void hit_left() {
    if(judge_hit(player.x,player.y-1)) {
        if(world[player.x][player.y-1] == "stone") Sleep(700);
        if(world[player.x][player.y-1] == "treewood") Sleep(500);
        else Sleep(300);
        clean_block(player.x,player.y-1);
        if(world[player.x][player.y-1]=="treewood") world[player.x][player.y-1]="wood";
        player.bag[item[ world[player.x][player.y-1] ]]++;
        world[player.x][player.y-1] = " ";
    }
}
void hit_right() {
    if(judge_hit(player.x,player.y+1)) {
        if(world[player.x][player.y+1] == "stone") Sleep(700);
        if(world[player.x][player.y+1] == "treewood") Sleep(500);
        else Sleep(300);
        clean_block(player.x,player.y+1);
        if(world[player.x][player.y+1]=="treewood") world[player.x][player.y+1]="wood";
        player.bag[item[ world[player.x][player.y+1] ]]++;
        world[player.x][player.y+1] = " ";
    }
}
void hit_down() {
    if(judge_hit(player.x+1,player.y)) {
        if(world[player.x+1][player.y] == "stone") Sleep(700);
        if(world[player.x+1][player.y] == "treewood") Sleep(500);
        else Sleep(300);
        clean_block(player.x+1,player.y);
        if(world[player.x+1][player.y]=="treewood") world[player.x+1][player.y] = "wood";
        player.bag[item[ world[player.x+1][player.y] ]]++;
        world[player.x+1][player.y] = " ";
    }
}
bool judge_put(int x,int y) {
    if(world[x][y] == "stone") return false;
    else if(world[x][y] == "dirt") return false;
    else if(world[x][y] == "gress") return false;
    else if(world[x][y] == "wood") return false;
//  else if(world[x][y] == "leaf") return false;
    else if(world[x][y] == "treewood") return false;
    else if(world[x][y] == "bedstone") return false;
    if(!player.bag[item[player.hand]]) return false;
    if(player.hand != "stone"&&player.hand != "dirt"&&player.hand != "wood") return false;
    if(x <= 0 || x >= WIN_SIZE+1 || y <= 0 || y >= WIN_SIZE+1) return false;
    if(judge(x+1,y) && judge(x,y-1) && judge(x,y+1)) return false;
    return true;
}
void put_left() {
    if(judge_put(player.x,player.y-1)) {
        player.bag[item[player.hand]]--;
        if(player.hand == "stone") print_stone(player.x,player.y-1),world[player.x][player.y-1] = "stone";
        else if(player.hand == "dirt") print_dirt(player.x,player.y-1),world[player.x][player.y-1] = "dirt";
        else if(player.hand == "wood") print_wood(player.x,player.y-1),world[player.x][player.y-1] = "wood";
    }
}
void put_right() {
    if(judge_put(player.x,player.y+1)) {
        player.bag[item[player.hand]]--;
        if(player.hand == "stone") print_stone(player.x,player.y+1),world[player.x][player.y+1] = "stone";
        else if(player.hand == "dirt") print_dirt(player.x,player.y+1),world[player.x][player.y+1] = "dirt";
        else if(player.hand == "wood") print_wood(player.x,player.y+1),world[player.x][player.y+1] = "wood";
    }
}
void put_down() {
    if(judge_put(player.x+1,player.y)) {
        player.bag[item[player.hand]]--;
        if(player.hand == "stone") print_stone(player.x+1,player.y),world[player.x+1][player.y] = "stone";
        else if(player.hand == "dirt") print_dirt(player.x+1,player.y),world[player.x+1][player.y] = "dirt";
        else if(player.hand == "wood") print_wood(player.x+1,player.y),world[player.x+1][player.y] = "wood";
    }
}
void takeout_item_1() {
    for(int i = 1; i <= 50; i++) {
        if(player.bag[i] && id[i] != player.hand) {
            player.hand = id[i];
            break;
        }
        if(i == 50) i = -1;
    }
}
void takeout_item_2() {
    for(int i = 50; i > -1; i--) {
        if(player.bag[i] && id[i] != player.hand) {
            player.hand = id[i];
            break;
        }
        if(i == 0) i = 50;
    }
}
void update_bag() {
//  if(player.bag[item["wood"]]) printf("88888");
    if(!player.bag[item[player.hand]]) player.hand = "nothing";
    Locate(25,1);
    printf("================================================\n");
    if(player.hand == "nothing") printf("===  Item in your hand:  nothing             ===\n");
    if(player.hand == "pickaxe") printf("===  Item in your hand:  pickaxe             ===\n");
    if(player.hand == "axe") printf("===  Item in your hand:  axe                     ===\n");
    if(player.hand == "sword") printf("===  Item in your hand:  sword                 ===\n");
    if(player.hand == "bow") printf("===  Item in your hand:  bow                     ===\n");
    if(player.hand == "apple") printf("===  Item in your hand:  apple                 ===\n");
    if(player.hand == "meat") printf("===  Item in your hand:  meat                   ===\n");
    if(player.hand == "arrow") printf("===  Item in your hand:  arrow                 ===\n");
    if(player.hand == "clip") printf("===  Item in your hand:  clip                   ===\n");
    if(player.hand == "stone") printf("===  Item in your hand:  stone                 ===\n");
    if(player.hand == "dirt") printf("===  Item in your hand:  dirt                   ===\n");
    if(player.hand == "seed") printf("===  Item in your hand:  seed                   ===\n");
    if(player.hand == "wood") printf("===  Item in your hand:  wood                   ===\n");
    if(player.hand == "tree_seed") printf("===  Item in your hand:  tree_seed         ===\n");
    if(player.hand == "boom") printf("===  Item in your hand:  boom                   ===\n");
    Locate(27,1);
    printf("===  Bag:                                    ===\n");
    printf("===                                          ===\n");
    printf("===                                          ===\n");
    if(player.bag[item["pickaxe"]]) Locate(28,7/2),printf("pickaxe");
    if(player.bag[item["axe"]]) Locate(28,17/2),printf("axe");
    if(player.bag[item["sword"]]) Locate(28,23/2),printf("sword");
//  if(player.bag[item[4]]) Locate(28,7),printf("apple");
    if(player.bag[item["apple"]]) Locate(28,31/2),printf("apple");
//  if(player.bag[item[6]]) Locate(28,7),printf("pickaxe");
//  if(player.bag[item[7]]) Locate(28,7),printf("pickaxe");
//  if(player.bag[item[8]]) Locate(28,7),printf("pickaxe");
    if(player.bag[item["stone"]]) Locate(28,5),printf("stone");
    if(player.bag[item["dirt"]]) Locate(28,9),printf("dirt");
    if(player.bag[item["wood"]]) Locate(28,12),printf("wood");
}
int t;
int last_time = sys.wMilliseconds + sys.wSecond * 1000 + sys.wMinute * 1000*60 + sys.wHour * 1000*3600;
void world_modify() {
    GetLocalTime( &sys );
    t = sys.wMilliseconds + sys.wSecond * 1000 + sys.wMinute * 1000*60 + sys.wHour * 1000*3600;
    if(t - last_time >= 75) {
        last_time = t;
        update_bag();
        if(player.jump) {
            player.jump--;
            if(judge(player.x-1,player.y)) {
                clean_player(player.x,player.y);
                player.x--;
                print_player(player.x,player.y);
            }
        } else if(!player.jump) {
            if(judge(player.x+1,player.y)) {
                clean_player(player.x,player.y);
                player.x++;
                print_player(player.x,player.y);
            }
        }
    }
}

void playing() {
    char ch;
    while(true) {
        if(kbhit()) {
            ch=getch();
            if(ch == 'a') go_left();
            else if(ch == 'd') go_right();
            else if(ch == ' ') jump();
            else if(ch == '1') hit_left();
            else if(ch == '3') hit_right();
            else if(ch == '2') hit_down();
            else if(ch == '4') put_left();
            else if(ch == '6') put_right();
            else if(ch == '5') put_down();
            else if(ch == '7') takeout_item_1();
            else if(ch == '9') takeout_item_2();
//          else if(ch == '0') use_item();
        }
        world_modify();
    }
}

int main() {
    project();
    welcome_print();
    init();
    world_print();
    playing();
    Sleep(10000);
}

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值