public async Task DealCards() { GameStatus = GameStatus.Playing; RiverPokers = new List <Poker>(); _openRiverPokers = new List <Poker>(); int index = 0; foreach (var player in Players) { player.Poker1 = AllPokers[index++]; player.Poker2 = AllPokers[index++]; await Dealing?.Invoke(player); Thread.Sleep(500); } for (int i = 0; i < 5; i++) { RiverPokers.Add(_backPoker); _openRiverPokers.Add(AllPokers[index++]); Thread.Sleep(500); await GameUpdated?.Invoke(this); } Start(); }
/// <summary> /// Where the grabber updates every x seconds and data is parsed /// </summary> private void Pulse(object sender, ElapsedEventArgs e) { gameGrabber.UpdateGames(); List <Game> updates = new List <Game>(); if (gameGrabber.Games.Length > 0) { if (gameUpdateTimes.Keys.Count > 0) { foreach (int id in gameUpdateTimes.Keys) { Game game = IdMatch(id); if (game != null) { if (game.LastUpdate != gameUpdateTimes[id] || game.LastUpdate > gameUpdateTimes[id] || game.BoxScore.LastUpdate > gameUpdateTimes[id]) { updates.Add(game); } } } } } foreach (Game game in updates) { gameUpdateTimes[game.Id] = game.BoxScore.LastUpdate; if (GameUpdated != null) { GameUpdated.Invoke(game); } } }
private void ThreadAwake() { GameStatusUpdate gameStatusUpdate = _gameStatusRetriever.GetCurrentStatus(); GameUpdated?.Invoke(gameStatusUpdate); ChangeDelay(gameStatusUpdate.GameStatus); }
public void TryRotate() { if (CanRotationBeMade()) { ClearPreviousCurrentShapePosition(); CurrentShape.Rotate(); PlaceCurrentShape(); GameUpdated?.Invoke(this, EventArgs.Empty); } }
public void GameCycle() { while (_running) { //Game loop GameUpdated?.Invoke(this, EventArgs.Empty); Thread.Sleep(50); } }
private void OnGameUpdated(List <GameUpdateEvent> updates) { if (!IsEventBufferEnabled) { GameUpdated?.Invoke(this, new GameUpdatedEventArgs(updates)); } else { GameUpdatesEventBuffer.AddRange(updates); } }
private void CreateNewShape() { ClearPreviousCurrentShapePosition(); CurrentShape = ShapeFactory.CreateRandomShape(); //check if the position we want to place current shape is occupied by another item foreach (var item in CurrentShape) { if (GameArray[item.Row, item.Column] != null) { PlayerLost?.Invoke(this, EventArgs.Empty); return; } } PlaceCurrentShape(); GameUpdated?.Invoke(this, EventArgs.Empty); }
public async Task Run() { while (true) { GameUpdated?.Invoke(this); List <Move> moves = GetPossibleMoves(Chips).Select(i => new Move(i)).ToList(); Move selectedMove = (CurrentChip == Chip.Mouse ? await Controller1.Select(this, moves) : await Controller2.Select(this, moves)); if (MoveAndCheckForWin(Chips, CurrentChip, WIN, selectedMove.ColumnIndex)) { GameUpdated?.Invoke(this); Window.SetTimeout(() => { Window.Alert($"{CurrentChip} wins!"); }); break; } CurrentChip = (CurrentChip == Chip.Mouse ? Chip.Cat : Chip.Mouse); } }
public static void InvokeGameUpdated(int timeLeft) { GameUpdated?.Invoke(timeLeft); }
/// <summary> /// Try and move the shape /// </summary> /// <param name="movement"></param> public void Move(Movement movement) { if (CurrentShape == null) { return; } //"sensitive" area lock (lockerObject) { //check if shape can be moved if (CanMovementCanBeMade(movement)) { //nullify its previous position in the array ClearPreviousCurrentShapePosition(); //update all pieces' row or column information according to the movement requested switch (movement) { case Movement.Left: for (int i = 0; i < CurrentShape.Count; i++) { CurrentShape[i].Column--; } break; case Movement.Bottom: for (int i = 0; i < CurrentShape.Count; i++) { CurrentShape[i].Row++; } break; case Movement.Right: for (int i = 0; i < CurrentShape.Count; i++) { CurrentShape[i].Column++; } break; default: break; } //move the current shape in the array PlaceCurrentShape(); GameUpdated?.Invoke(this, EventArgs.Empty); } else//movement cannot be made { //item cannot be moved //if the requested movement is bottom, this means that the shape cannot move even further //so we need to 1. check if any row(s) are full of pieces, i.e. there exists a horizontal line //2. remove these lines //3. move all the rest lines towards the bottom of the array //4. request another shape if (movement == Movement.Bottom) { CurrentShape = null; //check and clear lines //move pieces below ClearLinesAndMovePiecesBelow(); //create new shape CreateNewShape(); } } } }