public void startGame() { if (contents == null) { contents = new Tile[w, h]; } if (enableGarbage && garbage == null) { garbage = new GarbageTile[w, h]; } for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (at(x, y)) { Destroy(at(x, y).gameObject); setAt(x, y, null); } if (enableGarbage && garbageAt(x, y)) { Destroy(garbageAt(x, y).gameObject); setGarbageAt(x, y, null); } } } for (int i = 0; i < startTiles; i++) { addTile(); } combo = 0; tilesReceived = 0; hasWon = false; hasLost = false; winLossCode = WinLossCode.NONE; comboTimer = 0; lagTimer = 0; tileTimer = 0; }
public void makeMove(Vector2i direction) { if (lagTimer > 0) { moveBuffer = direction; return; } moveBuffer = Vector2i.one * -1; if (!allowNullMove && direction == Vector2i.zero) { /* * if (checkGarbageLoss()) * { * hasLost = true; * winLossCode = WinLossCode.GARBAGEFULL; * } */ breakCombo(); if (checkLoss()) { hasLost = true; winLossCode = WinLossCode.OUTOFMOVES; } return; } //Debug.Log("Making move: " + direction); List <Tile> traversal = new List <Tile>(); bool tileMoved = false; if (direction.x == 1) { for (int x = w - 1; x >= 0; x--) { for (int y = 0; y < h; y++) { traversal.Add(at(x, y)); } } } else if (direction.x == -1) { for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { traversal.Add(at(x, y)); } } } else if (direction.y == 1) { for (int y = h - 1; y >= 0; y--) { for (int x = 0; x < w; x++) { traversal.Add(at(x, y)); } } } else if (direction.y == -1) { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { traversal.Add(at(x, y)); } } } else // Null move { tileMoved = true; // Behave as if a move was made } bool comboBroken = true; int garbageToSend = 0; int timesToIntensify = 0; foreach (Tile t in traversal) { if (!t) { continue; } tileMoved = t.move(direction) || tileMoved; if (!t && combo > 0) { comboBroken = false; } else if (t.mergedThisMove) { combo++; comboBroken = false; Debug.Log("Combo: " + combo + "; Speedup: " + comboSpeedup() + "; Speedup Max Mult: " + comboSpeedupMaxMultiplier); timesToIntensify += Mathf.FloorToInt(Mathf.Log(t.val, 2)); if (combo >= 3) { garbageToSend += Mathf.FloorToInt(Mathf.Log(combo - 1, 2)); } /* * comboBroken = false; * combo = true; * matchesMade++; * garbageToSend += t.val / 16; */ if (t.val == 512) { hasWon = true; winLossCode = WinLossCode.MADE256; } } } timesToIntensify /= 4; if (enableGarbage) { if (hasGarbage()) { for (int i = 0; i < garbageToSend + timesToIntensify; i++) { neutralizeGarbage(); } } else { opponent.sendGarbage(garbageToSend, timesToIntensify); } /* * if (hasGarbage()) * { * for (int i = 0; i < matchesMade; i++) * neutralizeGarbage(); * } * else * { * opponent.sendGarbage(garbageToSend, matchesMade); * } */ } if (!tileMoved) { return; } comboTimer = 0; lagTimer = lagLength; if (comboBroken) { /* * if (checkGarbageLoss()) * { * hasLost = true; * winLossCode = WinLossCode.GARBAGEFULL; * } */ breakCombo(); } if (addTileAfterMove) { addTile(); } if (combo == 0) { if (checkLoss()) { hasLost = true; winLossCode = WinLossCode.OUTOFMOVES; } } }