public bool RepairFruit(GameObject FruitPiece1, GameObject FruitPiece2) { // Get fruit type and generate corresponding type PieceGenerator pieceGenerator = gameObject.GetComponent <PieceGenerator>(); if (pieceGenerator == null) { Debug.LogError("PieceGenerator should be under the same object as judge!"); return(false); } FruitBase.FruitType fruitType = FruitPiece1.GetComponent <FruitBase>().fruitType; GameObject fullFruit = GameObject.Instantiate(pieceGenerator.fullFruitList[(int)fruitType]); fullFruit.transform.position = (FruitPiece1.transform.position + FruitPiece2.transform.position) / 2; fullFruit.GetComponent <SimpleGravity>().velocity = (FruitPiece1.GetComponent <SimpleGravity>().velocity + FruitPiece2.GetComponent <SimpleGravity>().velocity) / 2; // Destroy fruit pieces pieceGenerator.ActiveFruitList.Remove(FruitPiece1); pieceGenerator.ActiveFruitList.Remove(FruitPiece2); Destroy(FruitPiece1); Destroy(FruitPiece2); score += 5; scoreLabel.text = "Score: " + score; return(true); }
public void initialise(string saveData) { string[] data = saveData.Split(new string[] { "|" }, System.StringSplitOptions.None); int width = int.Parse(data [0]); int height = int.Parse(data [1]); int genId = int.Parse(data [2]); tileData = new GamePiece?[width, height]; currentTile = GamePiece.fromHash(int.Parse(data [3])); storedTile = GamePiece.fromHash(int.Parse(data [4])); queueEvent(new CurrentTileChangedEvent(currentTile)); queueEvent(new StoredTileChangedEvent(storedTile)); int i = 5; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { string td = data [i]; i++; if (td != "X") { GamePiece newTile = GamePiece.fromHash(int.Parse(td)); tileData [x, y] = newTile; queueEvent(new TileChangedEvent(newTile, x, y)); } } } recalculateUncoveredArrows(); generator = PieceGenerator.fromId(genId); }
static void Main(string[] args) { var pieceGenerator = new PieceGenerator(); var pieces = pieceGenerator.GeneratePieces(NR_PIECES, DIMENSION); //mediator Board board = new Board(DIMENSION, pieces); foreach (var piece in board.ChessPieces) { Console.WriteLine(piece.ToString()); } //observers var printObserver = new PrintObserver(board); printObserver.Subscribe(); var killObserver = new KillCounterObserver(board); killObserver.Subscribe(); board.Play(NR_MOVES); var black = board.GetNumberPiecesAlive(ChessPieceColor.BLACK); var white = board.GetNumberPiecesAlive(ChessPieceColor.WHITE); Console.WriteLine($" ALIVE WHITE:{white} - ALIVE BLACK {black} GG!"); Console.ReadKey(); }
void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } }
// Use this for initialization void Start() { engine = new Game(); width = 44; height = 44; if (loadString == null) { engine.initialise(width, height, PieceGenerator.fromId(generatorId)); Stats.addAttempt(generatorId); } else { engine.initialise(loadString); generatorId = engine.getGeneratorId(); } tiles = new Tile[width, height]; previousCP = new bool[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tiles [x, y] = createTile(x, y); } } GameObject q; for (int x = 0; x < width; x++) { q = Instantiate(edgeTextures [0], transform); q.transform.localPosition = new Vector3(x, height, 0); q = Instantiate(edgeTextures [3], transform); q.transform.localPosition = new Vector3(x, -1, 0); } for (int y = 0; y < height; y++) { q = Instantiate(edgeTextures [1], transform); q.transform.localPosition = new Vector3(-1, y, 0); q = Instantiate(edgeTextures [2], transform); q.transform.localPosition = new Vector3(width, y, 0); } q = Instantiate(edgeTextures [4], transform); q.transform.localPosition = new Vector3(-1, height, 0); q = Instantiate(edgeTextures [5], transform); q.transform.localPosition = new Vector3(width, height, 0); q = Instantiate(edgeTextures [6], transform); q.transform.localPosition = new Vector3(-1, -1, 0); q = Instantiate(edgeTextures [7], transform); q.transform.localPosition = new Vector3(width, -1, 0); hasPlaced = new bool[width, height]; ProcessAllEvents(false); playSound(newGameSound); }
// Use this for initialization public void initialise(int xwidth, int ywidth, PieceGenerator _generator) { generator = _generator; tileData = new GamePiece?[xwidth, ywidth]; currentTile = new GamePiece(); currentTile.up = true; currentTile.left = true; currentTile.right = true; currentTile.down = true; storedTile = generatePiece(); queueEvent(new CurrentTileChangedEvent(currentTile)); queueEvent(new StoredTileChangedEvent(storedTile)); }
private static IEnumerable<Piece> GetRandomPieces() { var generator = new PieceGenerator(); var pieces = new List<Piece>(); Execute.This(() => { var newPiece = generator.GetNewPiece(); pieces.Add(newPiece); }, 50.Times()); return pieces; }
// Start is called before the first frame update void Start() { _pieceGenerator = FindObjectOfType <PieceGenerator>(); _rigidBody = gameObject.GetComponent <Rigidbody2D>(); }
// Start is called before the first frame update void Start() { _pieceGenerator = FindObjectOfType <PieceGenerator>(); }