如何制作迷宫瓷砖3x3

时间:2018-01-22 07:11:39

标签: c++

就像问题所说,我有一个10X11阵列,我需要每个瓷砖为3x3而不是1x1,我不知道该怎么做。我也无法为我的终点提取正确的x值。任何帮助将非常感激。这是我目前的代码:

10, 11.
(0, 0).
(3, 10).
(0, 6), (0, 7), (0, 9), 
(1, 1), (1, 2), (1, 4), (1, 7),
(2, 1), (2, 7), (2, 8), (2, 10),
(3, 1), (3, 2), (3, 3), (3, 4), (3, 7),
(4, 0), (4, 6), (4, 9), (4, 10),
(5, 2), (5, 3), (5, 4), (5, 5), (5, 7),
(6, 1), (6, 8), (6, 9),
(7, 1), (7, 2), (7, 3), (7, 6), 
(8, 1), (8, 5), (8, 6), (8, 8), (8, 10),
(9, 3), (9, 7).

这是我的.txt输入用于引用,每个不同的点都用句点标记。即尺寸。开始。完。壁:

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>


int main()
{
    //establishing constant variables;
    const int row = 10;
    const int col = 11;
    double p1x,p1y;

    //defining strings to pull from text file
    std::string arraysize_sx;
    std::string arraysize_sy;
    std::string start_sx;
    std::string start_sy;
    std::string finish_sx;
    std::string finish_sy;
//    std::string walls_sx;
//    std::string walls_sy;
    std::string walls_sf;

    std::ifstream openfile ("input.txt");
    std::ofstream outputfile ("output.txt",std::ios::app);

//    int wx,wy;
    int startx,starty;
    int finishx,finishy;
    //gets points from text file, using , and . as delimiters
    std::getline(openfile, arraysize_sx , ',');
    std::getline(openfile, arraysize_sy, '.');
    std::getline(openfile, start_sx, ',');
    std::getline(openfile, start_sy, '.');
    std::getline(openfile, finish_sx , ',');
    std::getline(openfile, finish_sy , '.');
//        std::getline(openfile,walls_sx, ',');
//        std::getline(openfile,walls_sy, ',');
    std::getline(openfile,walls_sf, '.');

        //convert string to int
    std::stringstream rowconv(arraysize_sx);
    std::stringstream colconv(arraysize_sy);
    std::stringstream startsx(start_sx);
    std::stringstream startsy(start_sy);
    std::stringstream finishsx(finish_sx);
    std::stringstream finishsy(finish_sy);
//        std::stringstream wallx(walls_sx);
//        std::stringstream wally(walls_sy);

    startsx >> startx;
    startsy >> starty;
    finishsx >> finishx;
    finishsy >> finishy;
//        wallx >> wx;
//        wally >> wy;



    //defining the shape of the maze
    char maze [col][row];
    char s [3][3] = {
        {'-','-','-'},
        {'-','S','-'},
        {'-','-','-'}
    };

    //defining the start point and endpoint using the points pulled from the text file
    for (int x = 0; x < col; x++){
        for (int y = 0; y < row; y++){
            if (x == startx && y == starty){
                maze[x][y] = 'S';
            }
            else if (y == finishx+3 && x == finishy){
                maze[x][y] = 'F';
            }
            else{
                maze [x][y] = '-';
            }
        }
    }

    std::cout << walls_sf << std::endl;

更新

我更新了我的代码,而不是像上面那样创建数组。我用循环来创建开始和结束。我仍在努力添加墙壁并为每个点创建3X3正方形。我试图找出是否有可能将3X3阵列放在另一个阵列的一个点内。

更新的代码:

{{1}}

0 个答案:

没有答案