C:\> Rostislav Persion's Projects

.:: Tiger Lights Out Game ::.
Tiger Lights Out game writted in C#




This is a C# version of the popular Lights Out game

SOFTWARE WRITTEN IN C#
   1:  using System;
   2:  using System.Collections;
   3:  using System.Threading;
   4:   
   5:  namespace A123
   6:  {
   7:      class MainClass
   8:      {
   9:          public static void Main (string[] args)
  10:          {
  11:   
  12:              LightsOutBoard lo1 = new LightsOutBoard();
  13:              lo1.Grid[0, 2] = true;
  14:              lo1.Grid[2, 2] = true;
  15:              lo1.Grid[4, 2] = true;
  16:   
  17:              while (!lo1.DidWin())
  18:              {
  19:                  Console.Clear();
  20:                  Console.WriteLine(lo1.ToStr());
  21:   
  22:                  Console.Write("X COORD: ");
  23:                  int xx = Convert.ToInt32(Console.ReadLine())-1;
  24:                  Console.Write("Y COORD: ");
  25:                  int yy = Convert.ToInt32(Console.ReadLine())-1;
  26:                  lo1.Press(xx, yy);
  27:              }
  28:   
  29:              Console.WriteLine("You Win!!!");
  30:              Console.ReadLine();
  31:          }
  32:      }
  33:   
  34:   
  35:      class LightsOutBoard
  36:      {
  37:          public bool[,] Grid = new bool[5, 5];
  38:   
  39:          public bool DidWin()
  40:          {
  41:              int cnt = 0;
  42:              for (int y = 0; y < 5; y++)
  43:              {
  44:                  for (int x = 0; x < 5; x++)
  45:                  {
  46:                      if (Grid[x, y] == true) { cnt++; }
  47:                  }
  48:              }
  49:   
  50:              bool ret = false;
  51:              if (cnt < 1) { ret = true; } else { ret = false; }
  52:              return ret;
  53:          }
  54:   
  55:   
  56:          public void Press(int x, int y)
  57:          {
  58:   
  59:              Grid[x, y] = !Grid[x, y];
  60:   
  61:              if ((x - 1) >= 0)
  62:              {
  63:                  Grid[x - 1, y] = !Grid[x - 1, y];
  64:              }
  65:   
  66:              if ((x + 1) <= 4)
  67:              {
  68:                  Grid[x + 1, y] = !Grid[x + 1, y];
  69:              }
  70:   
  71:              if ((y - 1) >= 0)
  72:              {
  73:                  Grid[x, y - 1] = !Grid[x, y - 1];
  74:              }
  75:   
  76:              if ((y + 1) <= 4)
  77:              {
  78:                  Grid[x, y + 1] = !Grid[x, y + 1];
  79:              }
  80:   
  81:          }
  82:   
  83:   
  84:   
  85:          public string ToStr()
  86:          {
  87:              string ret = "";
  88:              for (int y = 0; y < 5; y++)
  89:              {
  90:                  for (int x = 0; x < 5; x++)
  91:                  {
  92:                      if (Grid[x, y] == true)
  93:                      {
  94:                          ret += "X ";
  95:                      }
  96:                      else
  97:                      {
  98:                          ret += "- ";
  99:                      }
 100:                  }
 101:   
 102:                  ret += "\n\n";
 103:   
 104:              }
 105:   
 106:              return ret;
 107:          }
 108:   
 109:   
 110:      }
 111:   
 112:   
 113:  }
 114:   
 115:   


C# Lights Out solver....



   1:  using System;
   2:  using System.Collections;
   3:  using System.Threading;
   4:   
   5:  namespace A123
   6:  {
   7:      class MainClass
   8:      {
   9:          public static void Main (string[] args)
  10:          {
  11:   
  12:   
  13:              LightsOutBoard lo1 = new LightsOutBoard();
  14:              lo1.Grid[0, 2] = true;
  15:              lo1.Grid[2, 2] = true;
  16:              //lo1.Grid[4, 2] = true;
  17:   
  18:              Console.Clear();
  19:              Console.WriteLine("PRESS ENTER TO START...");
  20:              Console.ReadLine();
  21:   
  22:   
  23:   
  24:              while (true)
  25:              {
  26:   
  27:                  for (int yy = 1; yy < 5; yy++)
  28:                  {
  29:   
  30:   
  31:                      for (int xx = 0; xx < 5; xx++)
  32:                      {
  33:   
  34:   
  35:                          // show while working
  36:                          Console.Clear();
  37:                          Console.ForegroundColor = ConsoleColor.Yellow;
  38:                          Console.WriteLine(lo1.ToStr());
  39:                          Thread.Sleep(50);
  40:   
  41:   
  42:                          if (lo1.Grid[xx, yy - 1] == true)
  43:                          {
  44:                              lo1.Press(xx, yy);
  45:                          }
  46:                      }
  47:   
  48:   
  49:   
  50:   
  51:                  }
  52:   
  53:                  if (lo1.DidWin() == false)
  54:                  {
  55:   
  56:                      bool worked = false;
  57:   
  58:                      if ((lo1.Grid[0, 4] == true) && (worked == false))
  59:                      {
  60:                          worked = true;
  61:                          lo1.Press(3, 0);
  62:                          lo1.Press(4, 0);
  63:                      }
  64:                      if ((lo1.Grid[1, 4] == true) && (worked == false))
  65:                      {
  66:                          worked = true;
  67:                          lo1.Press(1, 0);
  68:                          lo1.Press(4, 0);
  69:                      }
  70:                      if ((lo1.Grid[2, 4] == true) && (worked == false))
  71:                      {
  72:                          worked = true;
  73:                          lo1.Press(3, 0);
  74:                      }
  75:   
  76:                      if (worked == false)
  77:                      {
  78:                          Random rnd1 = new Random();
  79:                          int rnd2 = rnd1.Next(0, 5);
  80:                          lo1.Press(rnd2, 0);
  81:                      }
  82:   
  83:   
  84:   
  85:                  }
  86:                  else
  87:                  {
  88:                      Console.WriteLine("YOU WIN!!!!!");
  89:                      Console.ReadLine();
  90:                  }
  91:   
  92:   
  93:                  Thread.Sleep(500);
  94:              }
  95:   
  96:   
  97:   
  98:   
  99:   
 100:   
 101:          }
 102:      }
 103:   
 104:   
 105:      class LightsOutBoard
 106:      {
 107:          public bool[,] Grid = new bool[5, 5];
 108:   
 109:          public bool DidWin()
 110:          {
 111:              int cnt = 0;
 112:              for (int y = 0; y < 5; y++)
 113:              {
 114:                  for (int x = 0; x < 5; x++)
 115:                  {
 116:                      if (Grid[x, y] == true) { cnt++; }
 117:                  }
 118:              }
 119:   
 120:              bool ret = false;
 121:              if (cnt < 1) { ret = true; } else { ret = false; }
 122:              return ret;
 123:          }
 124:   
 125:   
 126:          public void Press(int x, int y)
 127:          {
 128:   
 129:              Grid[x, y] = !Grid[x, y];
 130:   
 131:              if ((x - 1) >= 0)
 132:              {
 133:                  Grid[x - 1, y] = !Grid[x - 1, y];
 134:              }
 135:   
 136:              if ((x + 1) <= 4)
 137:              {
 138:                  Grid[x + 1, y] = !Grid[x + 1, y];
 139:              }
 140:   
 141:              if ((y - 1) >= 0)
 142:              {
 143:                  Grid[x, y - 1] = !Grid[x, y - 1];
 144:              }
 145:   
 146:              if ((y + 1) <= 4)
 147:              {
 148:                  Grid[x, y + 1] = !Grid[x, y + 1];
 149:              }
 150:   
 151:          }
 152:   
 153:   
 154:   
 155:          public string ToStr()
 156:          {
 157:              string ret = "";
 158:              for (int y = 0; y < 5; y++)
 159:              {
 160:                  for (int x = 0; x < 5; x++)
 161:                  {
 162:                      if (Grid[x, y] == true)
 163:                      {
 164:                          ret += "X ";
 165:                      }
 166:                      else
 167:                      {
 168:                          ret += "- ";
 169:                      }
 170:                  }
 171:   
 172:                  ret += "\n\n";
 173:   
 174:              }
 175:   
 176:              return ret;
 177:          }
 178:   
 179:   
 180:      }
 181:   
 182:   
 183:  }
 184:   
 185: