Загрузка...

Помогите с игрой на Unity

Тема в разделе C# создана пользователем Karasu_san 13 сен 2022. (поднята 14 сен 2022) 216 просмотров

  1. Karasu_san
    Karasu_san Автор темы 13 сен 2022 Заблокирован(а) 5016 1 сен 2018
    Короче есть игра на юнити, что то типо алхимии
    [IMG]
    Проблема в том, что я тупой и не знаю как избавиться от повторяющихся плиток. (Они появляются если 2 раза объеденить одни и теже элементы)


    C#
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class GameController : Singleton<GameController>
    {
    private bool gameStarted = false;

    // Start is called before the first frame update
    void Start()
    {
    InitNewGame();
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void InitNewGame()
    {
    if (gameStarted)
    return;

    MainGameScreenController.Inst.ClearElementsExternal();

    // New game elements
    MainGameScreenController.Inst.AddNewElementExternal(ProtoItemId.One);
    MainGameScreenController.Inst.AddNewElementExternal(ProtoItemId.Gate);
    MainGameScreenController.Inst.AddNewElementExternal(ProtoItemId.Human);
    MainGameScreenController.Inst.AddNewElementExternal(ProtoItemId.Ten);
    }


    private List<ProtoItemId> _selectedElements = new List<ProtoItemId>();

    public List<ProtoItemId> SelectedElements
    {
    get { return new List<ProtoItemId>(_selectedElements); }
    }

    public void SelectElement(ProtoItemId el)
    {

    if (!_selectedElements.Contains(el))
    {
    _selectedElements.Add(el);
    }
    }

    public void DeselectElement(ProtoItemId el)
    {
    if (_selectedElements.Contains(el))
    {
    _selectedElements.Remove(el);
    }
    }

    public void DeselectAll()
    {
    _selectedElements = new List<ProtoItemId>();
    }
    }


    C#
        public void SelectElement(ProtoItemId el)
    {

    if (!_selectedElements.Contains(el))
    {
    _selectedElements.Add(el);
    }
    }

    //Отвечает за объединение плиток
    C#
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class RecipesHolder : Singleton<RecipesHolder>
    {
    private List<ElementRecipe> _allRecipes = new List<ElementRecipe>();

    void Awake()
    {
    InitRecipes();
    }

    public bool isValidCondition(List<ProtoItemId> items, out RecipeResult matchResult)
    {
    RecipeResult found = null;
    int i = 0;
    _allRecipes.ForEach(recipe =>
    {
    Debug.LogFormat("step={0}, found={1}", i, found);
    i++;
    if (!found && recipe.Condition.match(items))
    {
    found = recipe.Result;
    }
    });

    Debug.LogFormat("Found after search={0}", found);

    matchResult = found;
    return matchResult;
    }

    private void InitRecipes()
    {
    // One + Gate -> Sun
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.One, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Sun })
    ));

    // Sun + One -> Dawn
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Sun, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Dawn })
    ));

    // Dawn + One -> Extend
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Dawn, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Extend })
    ));

    // Human + One -> Big
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Human, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Big })
    ));

    // Big + One -> Sky
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Big, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Sky })
    ));

    // Extend + Gate -> Glorious
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Extend, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Glorious })
    ));

    // Extend + Sun -> Sunlight
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Extend, ProtoItemId.Sun }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Sunlight })
    ));

    // Big + Gate -> Shout
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Big, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Shout })
    ));

    // One + Ten -> Soil
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.One, ProtoItemId.Ten }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Soil })
    ));

    // Soil + One -> King
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Soil, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.King })
    ));

    // Ten + Sun -> Early
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Ten, ProtoItemId.Sun }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Early })
    ));

    // Ancient + Gate -> Solid
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Ancient, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Solid })
    ));

    // Country + Gate -> Croak
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Country, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Croak })
    ));

    // King + Gate -> Shout
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.King, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Country })
    ));

    // Soil + Gate -> Vomit
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Soil, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Vomit })
    ));

    // Ten + Gate -> Shout
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Ten, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Ancient })
    ));

    // Human + King -> Complete
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Human, ProtoItemId.King }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Complete })
    ));

    // Human + Ten -> Tree
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Human, ProtoItemId.Ten }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Tree })
    ));

    // Tree + One -> Root
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.One }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Root })
    ));

    // Tree + Sun -> Bright
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.Sun }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Bright })
    ));

    // Tree + Gate -> Apricot
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.Gate }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Apricot })
    ));

    // Tree + Dawn -> Grieved
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.Dawn }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Grieved })
    ));

    // Ancient + Human -> Be able to
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Ancient, ProtoItemId.Human }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Ability })
    ));

    // Tree + King -> Twist
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.King }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Twist })
    ));

    // Tree + Ancient -> Dried up
    _allRecipes.Add(new ElementRecipe(
    new RecipeCondition(
    new List<ProtoItemId> { ProtoItemId.Tree, ProtoItemId.Ancient }),
    new RecipeResult(
    new List<ProtoItemId> { ProtoItemId.Dried })
    ));
    }
    }
     
    13 сен 2022 Изменено
Загрузка...
Top