可以考虑一下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.csdn.net/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);
}
### 回答1: 制作一款类似于泰拉瑞亚游戏需要许多不同的技能和知识,包括游戏设计、编程、图形设计和音频设计。 1. 首先,需要确定游戏的目标和设计,包括游戏世界、人物、敌人、物品和任务等内容。 2. 其次,使用游戏引擎(如 Unity 或 Unreal Engine)开发游戏的基本结构和功能。 3. 然后,使用图形设计工具(如 Adobe Photoshop 或 Procreate)制作游戏中的角色、场景和物品等素材。 4. 接下来,使用音频编辑软件(如 Ableton 或 Pro Tools)制作背景音乐和音效。 5. 最后,使用测试和调试工具进行游戏的测试和调整,并在合适的平台上发布游戏。 注意,这只是制作游戏的大致步骤,具体实现细节可能因人而异。 ### 回答2: 制作像泰拉瑞亚游戏需要经过以下具体步骤: 1. 游戏概念和设计:首先,您需要明确游戏的主题、故事和玩法机制。确保您有一个清晰的游戏设计文档,其中包含关卡设计、物品系统、角色和敌人等。 2. 编程和开发:使用适合的游戏引擎(如Unity或Unreal Engine)开始游戏的编程和开发。创建角色控制、碰撞和物理系统,以及其他必要的程序功能。 3. 图形和艺术设计:设计游戏的图形和艺术风格。创建背景、角色、敌人和物品的模型和纹理,并确保它们与游戏的整体风格一致。 4. 地图和关卡设计:设计游戏的地图和关卡,包括地形生成、地下洞穴和各种地点。确保关卡有足够的挑战性和变化,给玩家提供不同的目标和任务。 5. 物品和工艺系统:创建和平衡各种物品和工艺系统,例如武器、装备和药水。确保这些系统能够提供玩家与敌人的战斗和探索所需要的足够的深度和乐趣。 6. 游戏音效和音乐:添加与游戏风格和情节相匹配的音效和音乐。制作或购买适合游戏氛围的原创音乐,并确保音效和音乐的质量和一致性。 7. 游戏测试和反馈:进行全面的游戏测试,检查游戏的平衡性、游戏性和可能的错误。收集玩家的反馈,根据需要进行调整和改进。 8. 发布和推广:准备游戏的发布版本,并在适当的平台上发布(如PC、掌机或手机)。使用各种营销渠道和社交媒体推广游戏,增加游戏的知名度和玩家群体。 需要注意的是,制作像泰拉瑞亚游戏是一个复杂和耗时的过程,需要艺术、编程和设计等多个方面的技能和知识。在这个过程中,不断学习和改进是至关重要的。 ### 回答3: 要制作像泰拉瑞亚(Terraria)这样的游戏,首先需要明确游戏的需求和目标。然后,按照以下步骤进行制作: 1. 规划游戏设计:明确游戏的故事背景、地图和角色设置等。 2. 编游戏文档:详细描述游戏中的功能、玩法和界面等要素,方便后续开发。 3. 创建游戏引擎:根据需求选择合适的游戏引擎,如Unity、Unreal等,并在引擎中创建游戏项目。 4. 开发游戏资源:设计并创建游戏中的角色、地图、场景、道具、敌人和音效等资源。 5. 实现游戏功能:使用编程语言(如C#、C++等)编游戏中的各种功能和玩法,如玩家操作、动作逻辑、战斗系统和物品管理等。 6. 设计游戏界面:利用游戏引擎提供的工具和插件设计游戏的用户界面,包括菜单、设置、角色状态和敌人信息等。 7. 进行游戏测试:逐步完善游戏功能,进行测试和调试,解决游戏中的bug和问题。 8. 优化游戏性能:对游戏资源和功能进行优化,提高游戏运行速度和画面质量,提升用户体验。 9. 进行游戏发布:根据平台要求,将游戏打包并发布到相应的游戏平台,如PC、手机、主机等。 要制作像泰拉瑞亚这样成功的游戏,还需持续关注用户反馈并进行改进,提供稳定的更新和可玩性。此外,团队的协作和专业技术能力也至关重要。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值