private void UpdateCells(GameBoardResponse gameBoard, bool full = false) { var height = 2 + gameBoard.GameBoardSize.Height; var width = 2 + gameBoard.GameBoardSize.Width; if (Cells is null || full && (height != Cells.Count() || width != Cells.Count())) { Cells = new ObservableCollection <ObservableCollection <CellType> >(); for (int i = 0; i < height; ++i) { ObservableCollection <CellType> Row = new ObservableCollection <CellType>(); for (int j = 0; j < width; ++j) { if (j == 0 || j + 1 == width || i == 0 || i + 1 == height) { Row.Add(CellType.WALL); } else { Row.Add(CellType.EMPTY); } } Cells.Add(Row); } }
private async void GameStep(object sender, EventArgs e) { _GameBoard = await client.GetGameBoardAsync(); roundInfo.Players.Clear(); UpdateCells(_GameBoard, roundInfo.Round != _GameBoard.RoundNumber); roundInfo.Round = _GameBoard.RoundNumber; _eventAggregator.GetEvent <RoundEvent>().Publish(roundInfo); }
private async void GameStart(GameStartInfo gameStartInfo) { if (!gameStartInfo.isStarted) { return; } _Nickname = gameStartInfo.Nickname; roundInfo.Players = new ObservableCollection <User>(); client = gameStartInfo.client; Token = gameStartInfo.Token; _GameBoard = await client.GetGameBoardAsync(); client.PostSnakeDirection(Token, "Left"); DispatcherTimer timer1 = new DispatcherTimer(); timer1.Tick += new EventHandler(GameStep); timer1.Interval = TimeSpan.FromMilliseconds(_GameBoard.TurnTimeMilleseconds); timer1.Start(); }