Exemple #1
0
 public void go(ref GameBoard gameboard)
 {
     if (human)
         human_go(ref gameboard);
     else
         ai_go(ref gameboard);
 }
Exemple #2
0
 public GamePlay()
 {
     rules = new GameRules();
     gameboard = new GameBoard();
     displayboard = new DisplayBoard();
     players = new List<GamePlayer>();
 }
        public void show_board(GameBoard board)
        {
            Console.Clear();
            string cell_contents = "";

            Console.WriteLine("  1   2   3   4   5   6   7");
            for (int y = 0; y < board.rows; y++)
            {
                Console.WriteLine("-----------------------------");
                Console.Write("| ");
                for (int x = 0; x < board.columns; x++)
                {
                    cell_contents = board.get_cell(x, y);
                    if (!cell_contents.Equals(" "))
                        Console.BackgroundColor = (cell_contents.Equals("1")) ? ConsoleColor.Blue : ConsoleColor.Red;

                    Console.Write(" ");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Write(" | ");
                }
                Console.WriteLine("");
            }
            Console.WriteLine("-----------------------------");
            Console.WriteLine(_message);

            if (!string.IsNullOrEmpty(_message))
                _message = "";
        }
Exemple #4
0
        public bool check_for_win(GameBoard board, string dobber_win)
        {
            if (check_Horizontal_win(board, dobber_win) || check_vertical_win(board, dobber_win) || check_diagnal_win(board, dobber_win))
                return true;

            return false;
        }
Exemple #5
0
        private bool check_diagnal(GameBoard board, int x, int y, string dobber_win, Func<int, int> Xdel, Func<int, int> Ydel)
        {
            string current_diag = board.get_diagnal(x, y, Xdel, Ydel);
            if (check_win(current_diag, dobber_win))
                return true;

            return false;
        }
Exemple #6
0
 private bool check_vertical_win(GameBoard board, string dobber_win)
 {
     for (int x = 0; x < board.columns; x++)
     {
         if (check_win(board.get_column(x), dobber_win))
             return true;
     }
     return false;
 }
Exemple #7
0
        private bool check_Horizontal_win(GameBoard board, string dobber_win)
        {
            for (int y = 0; y < board.rows; y++)
            {
                if (check_win(board.get_row(y), dobber_win))
                    return true;
            }

            return false;
        }
Exemple #8
0
        private void ai_go(ref GameBoard gameboard)
        {
            bool find_position = true;
            Random r = new Random(DateTime.Now.Millisecond);
            int computer_position = 0;

            while (find_position)
            {
                computer_position = r.Next(7);
                if (gameboard.drop_dobber(computer_position, dobber()))
                    find_position = false;
            }
        }
Exemple #9
0
        private bool check_diagnal_win(GameBoard board, string dobber_win)
        {
            for (int y = 0; y < board.rows; y++)
            {
                for (int x = 0; x < board.columns; x++)
                {//the contents of this loop assume that we need a min of 4 to win, remove the if's and it will go a low as you want
                    if (x < 4 && y < 3)
                    {//South east / north west possible
                        if (check_diagnal(board, x, y, dobber_win, (Coord) => { return ++Coord; }, (Coord) => { return ++Coord; }))
                            return true;
                    }

                    if (x > 2 && y < 3)
                    {//South west / north east possible
                        if (check_diagnal(board, x, y, dobber_win, (Coord) => { return --Coord; }, (Coord) => { return ++Coord; }))
                            return true;
                    }
                }
            }
            return false;
        }
        public void play_drops_dobber_into_the_first_row()
        {
            GameBoard board = new GameBoard();
            board.init();

            Assert.AreEqual(board.drop_dobber(0, "h"), true);
        }
 public void testInit()
 {
     rules = new GameRules();
     board = new GameBoard();
     board.init();
 }
Exemple #12
0
        private void human_go(ref GameBoard gameboard)
        {
            int pos = -1;
            bool flag = false;

            get_cursor_position();

            do
            {
                flag = get_position_from_user(ref pos);
                if (flag)
                {
                    if (!gameboard.drop_dobber(pos - 1, dobber()))
                    {
                        reset_cursor();
                        Console.WriteLine("Error with column, please select a new column");
                        flag = false;
                    }
                }
            } while (!flag);
        }
Exemple #13
0
 void create_diagnal_win(ref GameBoard board, int size, int startX, int startY, Func<int, int> Xdel, Func<int, int> Ydel)
 {
     for (int x = 0; x < size; ++x)
     {
         board.insert(startX, startY, "h");
         startX = Xdel(startX);
         startY = Ydel(startY);
     }
 }
Exemple #14
0
 void create_vertical_win(ref GameBoard board, int startX, int startY)
 {
     for (int x = 0; x < 4; ++x)
     {
         board.insert(startX, startY++, "h");
     }
 }
Exemple #15
0
 void create_hotizontal_win(ref GameBoard board, int startX, int startY)
 {
     for (int x = 0; x < 4; ++x)
     {
         board.insert(startX++, startY, "h");
     }
 }