Плитки не печатаются на экране

Я бы рекомендовал использовать Html.RenderAction и PartialViewResults для этого; он позволит вам отображать одни и те же данные, но у каждого частичного вида все еще будет одна модель представления и устраняет необходимость в BigViewModel

. Таким образом, ваше представление содержит примерно следующее:

@Html.RenderAction("Login")
@Html.RenderAction("Register")

Где Login & amp; Register - оба действия в вашем контроллере, определенные следующим образом:

public PartialViewResult Login( )
{
    return PartialView( "Login", new LoginViewModel() );
}

public PartialViewResult Register( )
{
    return PartialView( "Register", new RegisterViewModel() );
}

Login & amp; Register будет пользовательским элементом управления, находящимся либо в текущей папке View, либо в общей папке, и хотел бы что-то вроде этого:

/Views/Shared/Login.cshtml: (или / Views / MyView /Login.cshtml)

@model LoginViewModel
@using (Html.BeginForm("Login", "Auth", FormMethod.Post))
{
    @Html.TextBoxFor(model => model.Email)
    @Html.PasswordFor(model => model.Password)
}

/Views/Shared/Register.cshtml: (или /Views/MyView/Register.cshtml)

@model ViewModel.RegisterViewModel
@using (Html.BeginForm("Login", "Auth", FormMethod.Post))
{
    @Html.TextBoxFor(model => model.Name)
    @Html.TextBoxFor(model => model.Email)
    @Html.PasswordFor(model => model.Password)
}

И там у вас есть действие одного контроллера, просмотр и просмотр файла для каждого действия с каждым полностью отличным и не зависящим друг от друга для чего-либо.

1
задан Charlie Wallace 31 March 2019 в 18:36
поделиться

1 ответ

Передайте координаты x и y и цвет плитки конструктору из Tiles. Конструктор должен иметь 3 входные переменные (x, y, color):

class Tile {
    constructor(x, y, color) {
        this.x = x;
        this.y = y;
        this.color = color;
}  

Функция id должна возвращать значение, и объявление должно быть: [1122 ]

 id = function(x, y) {
     return y * tilesDown + x;
 }

Вычислили все переменные для ширины и высоты плиток в setup, где вы можете использовать функции p5.js , например, round , далее обратите внимание, что определение tileWidth отсутствует в вашем коде:

function setup() {

    tilesAlong = 16;
    tileBase = W/tilesAlong;
    tileHeight = ((tileBase**2)-((tileBase/2)**2))**0.5;
    tilesDown = (round((H/tileHeight)/2))*2;
    yOffset = (H-(tilesDown*tileHeight))/2;
    tilesTotal = (tilesAlong-1)*(tilesDown-1);

    createCanvas(W, H);
    background(bg);

    id = function(x, y) {
        return y * tilesDown + x;
    }

    let tempX = 0, tempY = 0, tempColor = ["40, 40, 40"];
    while(id(tempX, tempY) < tilesTotal){
        tiles.push(new Tile(tempX, tempY, tempColor));
        tempX += 1;
        if(tilesAlong < tempX){
            tempX = 0;
            tempY += 1;
        }
    }
}

Имя списка, который содержит плитки, - tiles, а не Tile. Tile - это имя класса:

function draw() {
    for(let i=0; i < tiles.length; ++i) {
        tiles[i].display();
    }
}

См. Пример, где я применил изменения к вашему исходному коду:

W = 800;
H = 600;
bg = 210;

let tiles = [];

function setup() {

    tilesAlong = 16;
    tileBase = W/tilesAlong;
    tileWidth = tileBase
    tileHeight = ((tileWidth**2)-((tileWidth/2)**2))**0.5;
    tilesDown = (round((H/tileHeight)/2))*2;
    yOffset = (H-(tilesDown*tileHeight))/2;
    tilesTotal = (tilesAlong-1)*(tilesDown-1);  

    createCanvas(W, H);
    background(bg);

    id = function(x, y) {
        return y * tilesDown + x;
    }

    let tempX = 0, tempY = 0, tempColor = ["40, 40, 40"];
    while(id(tempX, tempY) < tilesTotal){
        tiles.push(new Tile(tempX, tempY, tempColor));
        tempX += 1;
        if(tilesAlong < tempX){
            tempX = 0;
            tempY += 1;
        }
    }
}

class Tile {
    constructor(x, y, color) {
        this.x = x;
        this.y = y;
        this.color = color;
    }

    display() {
        if(this.y/2 == round(this.y/2)){
            if(this.x/2 == round(this.x/2)){
                triangle(tileWidth * this.x/2, tileHeight*(this.y+1), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*this.y), (tileWidth*(this.x/2+1)), tileHeight*(this.y+1));
            } else{
                triangle(tileWidth * this.x/2, tileHeight*(this.y), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*(this.y+1)), (tileWidth*(this.x/2+1)), tileHeight*(this.y));
            }
        } else {
            if(this.x/2 == round(this.x/2)){
                triangle(tileWidth * this.x/2, tileHeight*(this.y), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*(this.y+1)), (tileWidth*((this.x/2)+1)), tileHeight*(this.y));
            } else{
                triangle(tileWidth * this.x/2, tileHeight*(this.y+1), (tileWidth*this.x/2)+(tileWidth/2), (tileHeight*this.y), (tileWidth*((this.x/2)+1)), tileHeight*(this.y+1));
            }  
        }
    }
}

function draw() {
    for(let i=0; i <tiles.length; ++i) {
        tiles[i].display();
    }
}
[115 ]

0
ответ дан Rabbid76 31 March 2019 в 18:36
поделиться
Другие вопросы по тегам:

Похожие вопросы: