Example #1
0
        private static CellObject[][] parseBoard(char[][] rawBoard)
        {
            CellObject[][] board = new CellObject[rawBoard.Length][];
            for (int i = 0; i < rawBoard.Length; i++)
            {
                CellObject[] row = new CellObject[rawBoard[0].Length];
                for (int j = 0; j < row.Length; j++) {
                    switch (rawBoard[i][j]) {
                        case '>' :
                            row[j] = new Arrow(new Direction(1, 0));
                            break;

                        case '<' :
                            row[j] = new Arrow(new Direction(-1, 0));
                            break;

                        case '^' :
                            row[j] = new Arrow(new Direction(0, -1));
                            break;

                        case 'V' :
                            row[j] = new Arrow(new Direction(0, 1));
                            break;

                        case '\\':
                            row[j] = new Mirror(false);
                            break;

                        case '+':
                            row[j] = new ScoreModifier(1);
                            break;

                        case '-':
                            row[j] = new ScoreModifier(-1);
                            break;

                        case '.':
                            row[j] = new Checkpoint();
                            break;

                        case ' ':
                            row[j] = new CellObject();
                            break;
                    }

                }
                board[i] = row;
            }
            return board;
        }
Example #2
0
 private static void runGame(CellObject[][] board)
 {
     Cat cat = new Cat();
     while (true) {
         cat.move();
         if (!inBounds(cat, board)) break;
         Position p = cat.getPosition();
         board[p.y][p.x].apply(cat);
     }
     Console.ReadLine();
 }
Example #3
0
 private static bool inBounds(Cat cat, CellObject[][] board)
 {
     Position p = cat.getPosition();
     if (p.y < 0 || p.y > board.Length-1 || p.x < 0 || p.x > board[0].Length-1) return false;
     return true;
 }