public void SpawnPiece(object sender, ElapsedEventArgs e) { if (GameFinished) { _spawnPieceTimer.Stop(); _spawnPieceTimer.Elapsed -= new ElapsedEventHandler(SpawnPiece); } else { Random rnd = new Random(); int x = rnd.Next(_boardWidth); int y = rnd.Next(_goalAreaLength, _goalAreaLength + _taskAreaLength); var currentField = ((TaskField)_boardList[x][y]); //if theres no piece in this location if (_pieces.FirstOrDefault(p => p.Location.x == x && p.Location.y == y) == null) { _pieceIdCounter++; currentField.pieceId = _pieceIdCounter; currentField.pieceIdSpecified = true; var piece = new Xsd2.Piece() { id = _pieceIdCounter }; piece.type = (rnd.NextDouble() <= _shamProbability) ? PieceType.sham : PieceType.normal; AddPiece(piece, new Location() { x = (uint)x, y = (uint)y }); } } }
public void CreateNextPiece(ref ulong pieceIdCounter, int goalAreaLength, int taskAreaLength, List <List <Field> > boardList) { int boardWidth = boardList.Count; Random rnd = new Random(); while (true) { int x = rnd.Next(boardWidth); int y = rnd.Next(goalAreaLength, goalAreaLength + taskAreaLength); if (((TaskField)boardList[x][y]).pieceIdSpecified == false) { ((TaskField)boardList[x][y]).pieceId = pieceIdCounter++; ((TaskField)boardList[x][y]).pieceIdSpecified = true; var piece = new Xsd2.Piece() { id = pieceIdCounter }; piece.type = (rnd.NextDouble() <= _shamProbability) ? PieceType.sham : PieceType.normal; AddPiece(piece, new Location() { x = (uint)x, y = (uint)y }); break; } } }
//for tests now public void AddPiece(Xsd2.Piece piece, Xsd2.Location location) { _pieces.Add(new PieceInfo(location, piece)); }