Example #1
0
 public CellControl(int id, Game game, ImageBalls ball)
 {
     InitializeComponent();
     this.id = id;
     this.game = game;
     Ball = ball;
 }
Example #2
0
File: Game.cs Project: ZuTa/Othello
        private List<CellControl> GetValidCells(CellControl cell, ImageBalls ball)
        {
            List<CellControl> result = new List<CellControl>();
            int x = cell.ID / (int)level;
            int y = cell.ID % (int)level;

            for (int i = 0; i < 8; i++)
                result.AddRange(DoStepStuff(x, y, dx[i], dy[i], ball));

            return result;
        }
Example #3
0
File: Game.cs Project: ZuTa/Othello
 private List<CellControl> DoStepStuff(int x, int y, int dx, int dy, ImageBalls ball)
 {
     List<CellControl> result = new List<CellControl>();
     int oldX = x;
     int oldY = y;
     x += dx;
     y += dy;
     while (x >= 0 && y >= 0 && y < (int)level && x < (int)level &&
             cellCollection[x * (int)level + y].Ball != ball &&
             cellCollection[x * (int)level + y].Ball != ImageBalls.None)
     {
         x += dx;
         y += dy;
     }
     if (x >= 0 && y >= 0 && y < (int)level && x < (int)level && cellCollection[x * (int)level + y].Ball == ball)
     {
         x -= dx;
         y -= dy;
         while (x != oldX || y != oldY)
         {
             if (!result.Contains(cellCollection[x * (int)level + y]))
                 result.Add(cellCollection[x * (int)level + y]);
             x -= dx;
             y -= dy;
         }
     }
     return result;
 }
Example #4
0
File: Game.cs Project: ZuTa/Othello
        private bool DoStepStuff(CellControl cell, ImageBalls ball)
        {
            bool didStuff = false;
            List<CellControl> result = GetValidCells(cell, ball);

            if (result.Count > 0)
            {
                didStuff = true;
                cell.Ball = ball;
                switch (ball)
                {
                    case ImageBalls.BlueBall:
                        CountRedBalls -= result.Count;
                        CountBlueBalls += result.Count + 1;
                        break;
                    case ImageBalls.RedBall:
                        CountRedBalls += result.Count + 1;
                        CountBlueBalls -= result.Count;
                        break;
                    default:
                        break;
                }
                foreach (CellControl c in result)
                {
                    c.Ball = ball;
                }
            }
            return didStuff;
        }