Continous Integration in der Praxis Gruppenarbeit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MiniGames.Shared.Models
  7. {
  8. public class TicTacToeBrett
  9. {
  10. public const int LEER = -1;
  11. int[,] Felder;
  12. public TicTacToeBrett()
  13. {
  14. Felder = new[,]
  15. {
  16. { LEER, LEER, LEER },
  17. { LEER, LEER, LEER },
  18. { LEER, LEER, LEER },
  19. };
  20. }
  21. public TicTacToeBrett(int[,] felder)
  22. {
  23. Felder = felder;
  24. }
  25. public bool Gleich(TicTacToeBrett anderes)
  26. {
  27. for (int i = 0; i < 3; i++)
  28. {
  29. for (int j = 0; j < 3; j++)
  30. {
  31. if (Felder[i, j] != anderes.Felder[i, j])
  32. {
  33. return false;
  34. }
  35. }
  36. }
  37. return true;
  38. }
  39. public bool Set(int pos, int wert)
  40. {
  41. int x = pos / 3;
  42. int y = pos % 3;
  43. try
  44. {
  45. if (Felder[x, y] == LEER)
  46. {
  47. Felder[x, y] = wert;
  48. return true;
  49. }
  50. }
  51. catch (IndexOutOfRangeException e)
  52. {
  53. // absichtlich leer
  54. }
  55. return false;
  56. }
  57. public bool Voll()
  58. {
  59. for (int i = 0; i < 3; i++)
  60. {
  61. for (int j = 0; j < 3; j++)
  62. {
  63. if (Felder[i, j] == LEER)
  64. {
  65. return false;
  66. }
  67. }
  68. }
  69. return true;
  70. }
  71. public int Gewinner()
  72. {
  73. for (int i = 0; i < 3; i++)
  74. {
  75. if (Felder[i, 0] == Felder[i, 1] && Felder[i, 1] == Felder[i, 2] && Felder[i, 0] != LEER)
  76. {
  77. return Felder[i, 0];
  78. }
  79. }
  80. return LEER;
  81. }
  82. }
  83. }