fork download
  1. using System;
  2.  
  3. namespace Balloons_Pops_Game_Variant_Four
  4. {
  5. public class FillGameBoard
  6. {
  7. const int GameBoardRows = 5;
  8. const int GameBoardColumns = 10;
  9. private readonly string[,] gameBoard =
  10. new string[GameBoardRows, GameBoardColumns];
  11. static readonly Random randomNumber = new Random();
  12.  
  13. private int GenerateRandomBallonNumber()
  14. {
  15. return randomNumber.Next(4) + 1;
  16. }
  17.  
  18. public FillGameBoard()
  19. {
  20. for (int i = 0; i < GameBoardRows; i++)
  21. {
  22. for (int j = 0; j < GameBoardColumns; j++)
  23. {
  24. gameBoard[i, j] =
  25. GenerateRandomBallonNumber().ToString();
  26. }
  27. }
  28. }
  29.  
  30. private void SetColour(int colour)
  31. {
  32. switch (colour)
  33. {
  34. case (int)BallonColours.Red:
  35. Console.ForegroundColor = ConsoleColor.Red;
  36. break;
  37. case (int)BallonColours.Blue:
  38. Console.ForegroundColor = ConsoleColor.Blue;
  39. break;
  40. case (int)BallonColours.Green:
  41. Console.ForegroundColor = ConsoleColor.Green;
  42. break;
  43. case (int)BallonColours.Yellow:
  44. Console.ForegroundColor = ConsoleColor.Yellow;
  45. break;
  46. default:
  47. Console.ForegroundColor = ConsoleColor.Gray;
  48. break;
  49. }
  50. }
  51.  
  52. public void GeneratePlot()
  53. {
  54. Console.WriteLine();
  55. Console.Write(" ");
  56. for (int j = 0; j < GameBoardColumns; j++)
  57. {
  58. Console.Write("{0} ", j);
  59. }
  60. Console.WriteLine();
  61. Console.WriteLine(" ---------------------");
  62.  
  63. for (int i = 0; i < GameBoardRows; i++)
  64. {
  65. Console.Write(" {0} | ", i);
  66. for (int j = 0; j < GameBoardColumns; j++)
  67. {
  68. if (gameBoard[i, j] == "")
  69. Console.Write("".PadLeft(2));
  70. else
  71. {
  72. SetColour(Convert.ToInt32(gameBoard[i, j]));
  73. Console.Write("{0} ", gameBoard[i, j]);
  74. SetColour(0);
  75. }
  76. }
  77. Console.Write("|");
  78. Console.WriteLine();
  79. }
  80. Console.WriteLine(" ---------------------");
  81. Console.WriteLine();
  82. SetColour(0);
  83. }
  84.  
  85. public bool IsEmpty()
  86. {
  87. for (int i = 0; i < GameBoardRows; i++)
  88. {
  89. for (int j = 0; j < GameBoardColumns; j++)
  90. {
  91. if(gameBoard[i, j] != "")
  92. return false;
  93. }
  94. }
  95. return true;
  96. }
  97.  
  98. public bool IsMoveAllowed(Move move)
  99. {
  100. if (gameBoard[move.Row, move.Col] == "")
  101. return false;
  102. return true;
  103. }
  104.  
  105. public void Refresh(Move move)
  106. {
  107. string colour = gameBoard[move.Row, move.Col];
  108. gameBoard[move.Row, move.Col] = "";
  109. PopsTheNeighbors(move.Row, move.Col, colour);
  110. FillTheEmptyCellsDown();
  111. }
  112.  
  113. private void PopsTheNeighbors(int row, int col, string colour)
  114. {
  115. if (row - 1 >= 0 && gameBoard[row - 1, col] == colour)
  116. {
  117. gameBoard[row - 1, col] = "";
  118. PopsTheNeighbors(row - 1, col, colour);
  119. }
  120. if (row + 1 < 5 && gameBoard[row + 1, col] == colour)
  121. {
  122. gameBoard[row + 1, col] = "";
  123. PopsTheNeighbors(row + 1, col, colour);
  124. }
  125. if (col - 1 >= 0 && gameBoard[row, col - 1] == colour)
  126. {
  127. gameBoard[row, col - 1] = "";
  128. PopsTheNeighbors(row, col - 1, colour);
  129. }
  130. if (col + 1 < 10 && gameBoard[row, col + 1] == colour)
  131. {
  132. gameBoard[row, col + 1] = "";
  133. PopsTheNeighbors(row, col + 1, colour);
  134. }
  135. }
  136.  
  137. private void FillTheEmptyCellsDown()
  138. {
  139. for (int j = 0; j < GameBoardColumns; j++)
  140. {
  141. for (int i = GameBoardRows - 1; i >= 0; i--)
  142. {
  143. if (gameBoard[i, j] == "")
  144. {
  145. int k = i;
  146. while (k > 0)
  147. {
  148. if (gameBoard[k - 1, j] != "")
  149. {
  150. gameBoard[i, j] = gameBoard[k - 1, j];
  151. gameBoard[k - 1, j] = "";
  152. break;
  153. }
  154. k--;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(98,35): error CS0246: The type or namespace name `Move' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(105,29): error CS0246: The type or namespace name `Move' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty