/// <summary> /// Create a congratulation menu /// </summary> /// <param name="tetris"></param> /// <param name="score"></param> /// <param name="level"></param> /// <param name="nextMenu"></param> public CongratulationMenu(Tetris tetris, int score, int level, IMenus nextMenu) { this.frameCount = 0; this.tetris = tetris; this.score = score; this.level = level; this.nextMenu = nextMenu; this.selectedIndexCharCursor = 0; this.selectedIndexChar = new int[6]; for (int i = 0; i < selectedIndexChar.Length; i++) { this.selectedIndexChar[i] = 0; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); IsMouseVisible = true; graphics.PreferredBackBufferWidth = (int)G.ScreenWidth - 160; graphics.PreferredBackBufferHeight = (int)G.ScreenHeight - 90; graphics.IsFullScreen = false; // @@@ graphics.ApplyChanges(); tetris = new Tetris { tetroTexture = blockTexture, highlightTexture = blockHighlightTexture, }; }
public bool CheckIfCoordsAreFree(CoOrd[] coords,int width,Tetris.mapVal[,] map) { for (int i = 0; i < coords.Length; i++) { if (pos.xCord + coords[i].xCord < 0 || pos.xCord + coords[i].xCord >= width || map[pos.xCord + coords[i].xCord, pos.yCord + coords[i].yCord].cubeInPos && !CheckIfCoOrdInBlock(new CoOrd(pos.xCord + coords[i].xCord, pos.yCord + coords[i].yCord))) { return false; } } return true; }
public bool CheckIsAboverid(Tetris tetris) { for (int x = 0; x < gridwidth; ++x) { foreach (Transform t in tetris.transform) { Vector3 pos = Round(t.position); if (pos.y > gridheight + grid_pos.y) { return(true); } } } return(false); }
public GameViewModel(ArtificialIntelligence ai, Tetris game) { AI = ai; Game = game; Game.GameSpeed = 10; for (int x = 0; x < 10; x++) { CellList.Add(new ObservableCollection <Cell>()); for (int y = 21; y >= 0; y--) { CellList[x].Add(Game.Matrix[x, y]); } } }
private void начатьНовуюИгруToolStripMenuItem_Click(object sender, EventArgs e) { if (tetris != null) { tetris.WipeOffFeeld(); tetris.Dispose(); } стопToolStripMenuItem.Enabled = true; стопToolStripMenuItem.Enabled = true; tetris = new Tetris(level); tetris.SetArea(this.CreateGraphics(), this.BackColor, this.Width, this.Height, 20, 50); tetris.GenerateFigure(); tetris.DrawOllField(); tetris.Start(); }
public bool CheckIsAboveGrid(Tetris tetris) { for (int x = 0; x < gridWidth; ++x) { foreach (Transform mino in tetris.transform) { Vector2 pos = Round(mino.position); if (pos.y > gridHeight - 1) { return(true); } } } return(false); }
static void Solve(V256 board, V256 piece, int step, int score) { while ((board & (piece << Tetris.width)) == 0) { piece <<= Tetris.width; } board |= piece; Tetris.RemoveFullLines(ref board, ref score); if (score > maxScoreFound) { maxScoreFound = score; Console.WriteLine($"new max score={maxScoreFound} at depth {maxStepFound} after processing {processedMoves:N0} moves at {timer.Elapsed}"); Console.WriteLine($" {GetMovesAsString()}"); } Solve(board, step + 1, score); }
void updateGameOverState(Resource res) { Tetris tetris = res.tetris; if (false == tetris.isGameOver()) { return; } Vector2 offset = res.offset; res.gameoverMark.SetActive(true); Stage stage = res.tetris.getStage(); res.gameoverMark.transform.position = new Vector3(stage.getBoardWidth() / 2 + offset.x, stage.getBoardHeight() / 2 + offset.y, 0); }
async Task Rotate(int rotation) { try { if (rotation == 0 || !Piece.Active) { return; } Console.Write($"Starting Rotation {rotation}"); int newRotation = (Piece.Rotation + 90) % 360; Console.Write($":{newRotation}deg"); Tetris newTetris = Tetris.FromNumber(Number, newRotation); Console.Write($":Piece Pos X {Piece.Position.x}:Grid X {newTetris.GridX}: Grid H {newTetris.GridHeight}"); int dx = 0; if (Piece.Position.x + newTetris.GridX < 3) { dx = 3 - (Piece.Position.x + newTetris.GridX); } else if (Piece.Position.x + newTetris.GridWidth > 13) { dx = 13 - (Piece.Position.x + newTetris.GridX); } if (Piece.Position.x + newTetris.GridHeight >= LastRow) { Console.WriteLine($"rotation not possible : Line {Piece.Position.x + newTetris.GridHeight}"); } Console.Write($":dx {dx}"); Piece.Rotation = newRotation; await Piece.SetTetris(newTetris); await Piece.SetPosition(Piece.Position.x + dx, Piece.Position.y, LastRow); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("******** ROTATION ERROR **********"); Console.WriteLine(ex); throw; } }
/// <summary> /// Загрузка формы. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { tetris = new Tetris(Graphics.FromHwnd(this.Handle), 20, 10); this.Width = tetris.Dx + tetris.ColCount * tetris.CellWidth + tetris.CellWidth * 6 + 25; this.Height = tetris.Dy + tetris.RowCount * tetris.CellWidth + 37; lPause.Left = tetris.Dx + (tetris.ColCount * tetris.CellWidth - lPause.Width) / 2; lPause.Top = tetris.Dy + (tetris.RowCount * tetris.CellWidth - lPause.Height) / 2; this.Controls.Add(tetris.lLevel); this.Controls.Add(tetris.lLines); this.Controls.Add(tetris.lScope); sp.Stream = Properties.Resources.Music; sp.Play(); }
static void Main() { // Create IP Connection and connect it IPConnection ipcon = new IPConnection(); ipcon.Connect(Config.HOST, Config.PORT); // Create Tetris object and start game loop tetris = new Tetris(ipcon); if (tetris.IsOkay()) { System.Console.WriteLine("Press q to exit"); tetris.RunGameLoop(); } ipcon.Disconnect(); }
/** * 自動プレイ用インスタンスを作成 */ public static Tetris CreateGameAutoPlay(List <int> bitList = null) { Tetris tetris; Tetrimino tetrimino = new Tetrimino(); int min_index = 0; int max_index = tetrimino.getTypeMax(); Generator generator = new Generator(min_index, max_index); InputBase input = new InputAuto(bitList); //落下ブロックは内部で固定でも良いのでは? //生成クラスでの範囲指定に、落下ブロックの情報が必要だから中で生成すると厳しい //ひとまずは外に出しておく //ファクトリで作成するので外部からは呼ぶだけだし tetris = new Tetris(BOARD_SIZE_W, BOARD_SIZE_H, tetrimino, generator, input); return(tetris); }
public ShapeProps SpawnNext() { _spawnedObj.transform.SetParent(transform); _spawnedObj.transform.position = transform.position; var lowestPoint = _spawnedSp.LowestPoint(); int deltaY = Tetris.PositionY(transform) - (int)Mathf.Round(lowestPoint.y); if (deltaY > 0) { _spawnedObj.transform.position = new Vector3(transform.position.x, transform.position.y + deltaY, 0); } ShapeProps sp = _spawnedSp; NextShape(); return(sp); }
public void Update(Tetris tetris) { UpdateQueue(tetris); int diff = 0 - tree.root.state.tetRng.index; void ResetAll(Node node) { node.state.tetRng.index += diff; node.depth -= 1; foreach (Node child in node.children) { ResetAll(child); } } ResetAll(tree.root); maxDepth = 0; }
void InstantiateTetris() { if (init) { int tetromino = Random.Range(0, blocks_name.Count); GameObject tetris = Instantiate(Resources.Load("Prefabs/" + blocks_name[tetromino])) as GameObject; last_tetris = tetris.GetComponent <Tetris>(); tetris.transform.position = new Vector3(2, 23, 2); init = false; } else if (!last_tetris.init) { int tetromino = Random.Range(0, blocks_name.Count); GameObject tetris = Instantiate(Resources.Load("Prefabs/" + blocks_name[tetromino])) as GameObject; last_tetris = tetris.GetComponent <Tetris>(); tetris.transform.position = new Vector3(2, 23, 2); } }
public void UpdateGrid(Tetris currentBlock) { for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridHeight; j++) { if (FaceGrid[i, j] != null) { if (FaceGrid[i, j].parent == currentBlock.transform) { FaceGrid[i, j] = null; } } } } if (y_rotation == 0) { foreach (Transform cubeTransform in currentBlock.transform) { Vector3 pos = Round(cubeTransform.position); if (pos.y - y_offset < gridHeight) { int xInGridSystem = (int)Mathf.Round(pos.x - _LowerLeftxOffset - x_offset); int yInGridSystem = (int)Mathf.Round(pos.y - y_offset); FaceGrid[xInGridSystem, yInGridSystem] = cubeTransform; } } } else if (y_rotation == 90) { foreach (Transform cubeTransform in currentBlock.transform) { Vector3 pos = Round(cubeTransform.position); if (pos.y - y_offset < gridHeight) { //if rotation is 90 we need to check z int xInGridSystem = (int)Mathf.Round(pos.z - _LowerLeftxOffset - z_offset); int yInGridSystem = (int)Mathf.Round(pos.y - y_offset); FaceGrid[xInGridSystem, yInGridSystem] = cubeTransform; } } } }
// Use this for initialization void Start() { scoreData = new Score(); leaderboardsData = new Leaderboards(); foreach (var loadedLeaderboard in LeaderboardsDataManager.Load()) { leaderboardsData.SetLeaderboard(loadedLeaderboard.leaderboard); } currUI = Instantiate(uiControllerPrefab); currUI.Initialize( leaderboardsData, scoreData, this ); currTetris = Instantiate(tetrisPrefab); }
public async Task <bool> SetTetris(Tetris tetris) { await semaphoreSlim.WaitAsync(); try { _tetris = tetris; return(true); } catch (Exception ex) { Console.WriteLine(ex); return(false); } finally { semaphoreSlim.Release(); } }
void Awake() { if (C != null) { GameObject.Destroy(C); } else { C = this; } DontDestroyOnLoad(this); Tetris.C.board = new int[Tetris.BOARD_WIDTH, Tetris.BOARD_HEIGHT]; for (int i = 0; i < 6; i++) { Tetris.C.tetrominoQueue.Enqueue((int)(Random.value * 7 + 1)); } }
void Start() { tetris = gameObject.GetComponent <Tetris>(); tetrisColor[0] = new Color32(30, 144, 255, 255); tetrisColor[1] = new Color32(50, 205, 50, 255); tetrisColor[2] = new Color32(222, 184, 135, 255); tetrisColor[3] = new Color32(64, 224, 208, 255); GrayGrid(); NewSnake(); tetrisColor[4] = new Color32(255, 215, 0, 255); tetrisColor[5] = new Color32(220, 20, 60, 255); tetrisColor[6] = new Color32(255, 105, 180, 255); curR = -1; InvokeRepeating("CustomUpdate", time, time); }
static void Main(string[] args) { Tetris tetris = new Tetris(25, 15); tetris.CreateBlock(); tetris.StartGettingInput(); while (tetris.IsGameOver == false) { tetris.PrintGame(); tetris.FallBlock(); System.Threading.Thread.Sleep(75); System.Console.Clear(); } System.Console.Write("Game Over"); System.Threading.Thread.Sleep(1750); }
public override bool ProcessKeyboard(KeyboardInfo info) { if (info.IsKeyDown(Keyboard.Key.Down)) { State = Tetris.DoMoveDown(State); } else if (info.IsKeyDown(Keyboard.Key.Left)) { State = Tetris.DoMoveLeft(State); } else if (info.IsKeyDown(Keyboard.Key.Right)) { State = Tetris.DoMoveRight(State); } else if (info.IsKeyDown(Keyboard.Key.Up)) { State = Tetris.DoRotate(State); } return(false); }
public TetrisState DoMove(TetriminoState move, Pathfinder.MoveNode moveNode, bool hold) { CustomTetrisRNG childRng = new CustomTetrisRNG(tetRng); Tetris child = new Tetris(tetris, childRng); if (hold) { child.Hold(); } Tetrimino tetrimino = child.current; child.pieceX = move.x; child.pieceY = move.y; child.pieceRotation = move.rot; child.HardDrop(); child.tspin = moveNode.tspin; return(new TetrisState(child, childRng) { usesHeld = hold, tetrimino = tetrimino }); }
public GameController(int height, int width) { HEIGHT = height <= 28 ? height : 28; WIDTH = width <= 14 ? width : 14; CONTAINER_SIZE = HEIGHT * WIDTH; // 遊戲物件 m_tetris = new Tetris(HEIGHT, WIDTH); // 載入block原型 m_blockArray = new UnityEngine.Object[8]; LoadBlockPrefabe(); m_unity_container = new GameObject[CONTAINER_SIZE]; m_unity_next_block = new GameObject[4 * 4]; m_now_used_block_count = 0; m_move_to_left = false; m_move_to_right = false; m_rotate = false; m_move_to_down = false; m_game_over = false; }
// Update Text private void UpdateText() { // Objects Tetris T = Tetris.GetInstance(); TetrisPerceptronManager TPM = TetrisPerceptronManager.GetInstance(); // Text setters _TickText.text = T.GetTickCounter().ToString(); _CurrentPiece.text = Tetris._Piece._Type.ToString(); _NextPiece.text = Tetris._Piece._NextType.ToString(); _GenerationText.text = TetrisPerceptronManager.GetEpochManager().GetGeneration().ToString(); _EpochText.text = (TetrisPerceptronManager.GetEpochManager().GetEpochIndex().ToString() + "/" + TetrisPerceptronManager.GetEpochManager().GetMaxEpochs().ToString()); _LinesText.text = Tetris._Lines.ToString(); _TotalLinesText.text = Tetris._TotalLines.ToString(); _FitnessText.text = Tetris._Fitness.ToString(); // Move Text is updated internally if (LimitPieces <= 0) { _PiecesUsedText.text = Tetris._PiecesUsed.ToString(); } else { _PiecesUsedText.text = Tetris._PiecesUsed.ToString() + '/' + LimitPieces.ToString(); } _BestSoFar.text = _Histogram.GetMaxValue().ToString(); _SimulationSpeed.text = UpdatesPerFrame.ToString(); if (!PauseMenu.GetInstance().getActive()) { int time = (int)(Time.time - PauseMenu.GetInstance()._PauseTime); string seconds = (time % 60).ToString("00"); string minutes = (time / 60 % 60).ToString("00"); string hours = (time / 3600).ToString("0000"); _TimeText.text = hours + ':' + minutes + ':' + seconds; } }
// UPDATE CALL void Update() { // Only update is not paused and saving thread is not running if (!PauseMenu.GetInstance().getActive() && SavingThread.GetInstance().checkThreadRunning() == false ) { Tetris.GetInstance().Update(); } UpdateText(); // Change Simulation Speed if (Input.GetKey(KeyCode.Alpha1)) { UpdatesPerFrame = 1; } else if (Input.GetKey(KeyCode.Alpha2)) { UpdatesPerFrame = 10; } else if (Input.GetKey(KeyCode.Alpha3)) { UpdatesPerFrame = 100; } else if (Input.GetKey(KeyCode.Alpha4)) { UpdatesPerFrame = 500; } else if (Input.GetKey(KeyCode.Alpha5)) { UpdatesPerFrame = 1000; } else if (Input.GetKey(KeyCode.Alpha6)) { UpdatesPerFrame = 5000; } }
public bool CheckOutOfBounds(int limit, bool left, Tetris.mapVal[,] map) { CoOrd[] coords = GetInhabitedCoords(); for (int i = 0; i < coords.Length; i++) { if(left){ if (coords[i].xCord - 1 < limit || (map[coords[i].xCord - 1, coords[i].yCord].cubeInPos && !CheckIfCoOrdInBlock(new CoOrd(coords[i].xCord - 1, coords[i].yCord)))) { //Debug.Log(additionalPos[i].xCord - 1 > limit); return false; } } else { if (coords[i].xCord + 1 >= limit || (map[coords[i].xCord + 1, coords[i].yCord].cubeInPos && !CheckIfCoOrdInBlock(new CoOrd(coords[i].xCord + 1, coords[i].yCord)))) { //Debug.Log(additionalPos[i].xCord - 1 > limit); return false; } } } return true; }
public static bool DoMove(Tetris tetris, Move move) { bool ret = false; switch (move) { case Move.LEFT: return(tetris.MoveLeft()); case Move.RIGHT: return(tetris.MoveRight()); case Move.ROT_LEFT: return(tetris.TurnLeft()); case Move.ROT_RIGHT: return(tetris.TurnRight()); case Move.SONIC_DROP: while (tetris.SoftDrop()) { ret = true; } break; } return(ret); }
public void HandleKey(ConsoleKeyInfo?cki2) { ConsoleKeyInfo cki = (ConsoleKeyInfo)cki2; if (cki.Key == ConsoleKey.D1) { Hide(); Snake snake = new Snake(this); return; } else if (cki.Key == ConsoleKey.D2) { Hide(); Tetris tetris = new Tetris(); return; } else if (cki.Key == ConsoleKey.D3) { Hide(); Pong pong = new Pong(true); return; } else if (cki.Key == ConsoleKey.D4) { Hide(); Pong pong = new Pong(false); return; } else if (cki.Key == ConsoleKey.D5) { } else if (cki.Key == ConsoleKey.Q) { Environment.Exit(0); } getKey(); }
public void Tetris_RemoveOneLine() { V256 board = Tetris.board; V256 piece = Tetris.PIECES[0][0]; piece >>= 3; while ((board & (piece << Tetris.width)) == 0) { piece <<= Tetris.width; } board |= piece; piece = Tetris.PIECES[0][0]; piece <<= 3; while ((board & (piece << Tetris.width)) == 0) { piece <<= Tetris.width; } board |= piece; piece = Tetris.PIECES[0][1]; piece >>= 1; while ((board & (piece << Tetris.width)) == 0) { piece <<= Tetris.width; } board |= piece; piece = Tetris.PIECES[0][1]; while ((board & (piece << Tetris.width)) == 0) { piece <<= Tetris.width; } board |= piece; int score = 0; Tetris.RemoveFullLines(ref board, ref score); Assert.AreEqual(1, score); }
public void UpdateGrid(Tetris tetris) { for (int y = 0; y < gridHeight; ++y) { for (int x = 0; x < gridWidth; ++x) { if (grid [x, y] != null) { if (grid[x, y].parent == tetris.transform) { grid[x, y] = null; } } } } foreach (Transform mino in tetris.transform) { Vector2 pos = Round(mino.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } }
public void RotateBlock(int limit, Tetris.mapVal[,] map) { switch (shape) { case Shapes.LShape: CoOrd[] verticalOffsets = new CoOrd[3]; CoOrd[] horizontalOffsets = new CoOrd[3]; verticalOffsets[0] = new CoOrd(0, 1); verticalOffsets[1] = new CoOrd(0, -1); verticalOffsets[2] = new CoOrd(1, -1); horizontalOffsets[0] = new CoOrd(1, 0); horizontalOffsets[1] = new CoOrd(-1, 0); horizontalOffsets[2] = new CoOrd(-1, -1); SetRotationOffsets(verticalOffsets, horizontalOffsets, limit, map); break; case Shapes.IShape: verticalOffsets = new CoOrd[3]; horizontalOffsets = new CoOrd[3]; verticalOffsets[0] = new CoOrd(0, -1); verticalOffsets[1] = new CoOrd(0, 1); verticalOffsets[2] = new CoOrd(0, 2); horizontalOffsets[0] = new CoOrd(-1, 0); horizontalOffsets[1] = new CoOrd(1, 0); horizontalOffsets[2] = new CoOrd(2, 0); SetRotationOffsets(verticalOffsets, horizontalOffsets, limit, map); break; case Shapes.CubeShape: //Do nothing break; case Shapes.TShape: verticalOffsets = new CoOrd[3]; horizontalOffsets = new CoOrd[3]; verticalOffsets[0] = new CoOrd(0, -1); verticalOffsets[1] = new CoOrd(1, 0); verticalOffsets[2] = new CoOrd(-1, 0); horizontalOffsets[0] = new CoOrd(0, -1); horizontalOffsets[1] = new CoOrd(0, 1); horizontalOffsets[2] = new CoOrd(-1, 0); SetRotationOffsets(verticalOffsets, horizontalOffsets, limit, map); break; case Shapes.JShape: verticalOffsets = new CoOrd[3]; horizontalOffsets = new CoOrd[3]; verticalOffsets[0] = new CoOrd(0, 1); verticalOffsets[1] = new CoOrd(0, -1); verticalOffsets[2] = new CoOrd(-1, -1); horizontalOffsets[0] = new CoOrd(1, 0); horizontalOffsets[1] = new CoOrd(-1, 0); horizontalOffsets[2] = new CoOrd(-1, 1); SetRotationOffsets(verticalOffsets, horizontalOffsets, limit, map); break; } }
public DropedBox[,] stageBoxs; // 已落下的方块数组 #endregion Fields #region Constructors /// <summary> /// 根据位置和大小初始化一个游戏舞台 /// </summary> /// <param name="bounds"></param> public GameStage(Rectangle bounds, Tetris game) : base(game) { Bounds = bounds; stageBoxs = new DropedBox[Bounds.Height / DropBox.size, Bounds.Width / DropBox.size]; }
public BigStage(Tetris game) : base(game) { }
public AbstractComponents(Tetris game) { setGame(game); init(); }
private void setGame(Tetris game) { this.game = game; }
public int point; // 当前分数 #endregion Fields #region Constructors public PointStage(Tetris game) : base(game) { }
int wait = 5; // n倍减速绘制 #endregion Fields #region Constructors public DropedBox(Tetris game) : base(game) { }
int gameStageWidth = 250; // 游戏舞台宽度 #endregion Fields #region Constructors /// <summary> /// 构造函数 /// </summary> /// <param name="tetris">俄罗斯方块主类</param> public Controller(Tetris tetris) { this.tetris = tetris; }
private void SetRotationOffsets(CoOrd[] verticalOffsets, CoOrd[] horizontalOffsets, int limit, Tetris.mapVal[,] map) { if (rotation == 0 && CheckIfCoordsAreFree(horizontalOffsets, limit, map)) { for (int i = 0; i < offsets.Length; i++) { offsets[i] = horizontalOffsets[i]; } rotation = 90; } else if (rotation == 90) { CoOrd[] flippedCoords = new CoOrd[3]; for (int i = 0; i < flippedCoords.Length; i++) { flippedCoords[i].xCord = verticalOffsets[i].xCord * -1; flippedCoords[i].yCord = verticalOffsets[i].yCord * -1; } if (CheckIfCoordsAreFree(flippedCoords, limit, map)) { for (int i = 0; i < offsets.Length; i++) { offsets[i] = flippedCoords[i]; } } rotation = 180; } else if (rotation == 180) { CoOrd[] flippedCoords = new CoOrd[3]; for (int i = 0; i < flippedCoords.Length; i++) { flippedCoords[i].xCord = horizontalOffsets[i].xCord * -1; flippedCoords[i].yCord = horizontalOffsets[i].yCord * -1; } if (CheckIfCoordsAreFree(flippedCoords, limit, map)) { for (int i = 0; i < offsets.Length; i++) { offsets[i] = flippedCoords[i]; } } rotation = 270; } else if (rotation == 270 && CheckIfCoordsAreFree(verticalOffsets, limit, map)) { for (int i = 0; i < offsets.Length; i++) { offsets[i] = verticalOffsets[i]; } rotation = 0; } }