private void CheckIfLose() { if (blocks.Count() == 16) { bool same = false; var table = new int[4, 4]; foreach (var block in blocks) { table[block.to.X, block.to.Y] = block.GetValue(); } for (int x = 0; x < 4; x++) { for (int y = 0; y < 3; y++) { same = same || (table[x, y] == table[x, y + 1]); } } if (!same) { for (int y = 0; y < 4; y++) { for (int x = 0; x < 3; x++) { same = same || (table[x, y] == table[x + 1, y]); } } } if (!same) { toDraw = ToDraw.Lose; } } }
public void Reset() { blocks.Clear(); AddNew(); AddNew(); toDraw = ToDraw.Nothing; is2048Already = false; anythingHappened = false; points = 0; }
/// <summary> /// Finishes move made by MakeMove() - destroying and upgrading blocks /// </summary> private void FinishMove() { blocks.RemoveAll((Block x) => { return(x.state == BlockState.Destroy); }); blocks.Where(block => block.state == BlockState.Upgrade) .ToList() .ForEach(block => points += block.Upgrade()); if (!is2048Already && blocks.Any(block => block.GetValue() == 2048)) { is2048Already = true; toDraw = ToDraw.Win; } CheckIfLose(); }
// Called when a portal is triggered. public static void ChangeRoom(Room newRoom, Vector2 newPosition) { if (newRoom != CurrentRoom) { // Clear out the lists because they will be repopulated for the new room. ToUpdate.Clear(); ToDraw.Clear(); InputManager.RegisteredActors.Clear(); CurrentRoom = newRoom; FocusObject.OnCreate(); // This is normally called in the constructor to add the object to lists. } FocusObject.Body.Position = newPosition; }
public void Start() { while (Window.IsOpen) { Window.DispatchEvents(); Window.Clear(Color.White); if (Background != null) { Window.Draw(new RectangleShape(new Vector2f(1, 1).Multiply(Window.GetView().Size)) { Texture = Background }); } foreach (var drawable in ToDraw.Reverse()) { drawable.DrawWidget(Window); } Window.Display(); } }