Example #1
0
                /*                         --IMPORTANT NOTE--
                 *              If any of the following returns a FALSE,
                 * it means that there is NO NEED to MOVE the display area component
                 *
                 *        Otherwise DO MOVE it, in the direction of the pointer
                 */

                public bool MoveUp(TextboxDisplayArea displayArea, List <List <char?> > characterMap)
                {
                    int absX = Anchor.X + displayArea.Anchor.X;
                    int absY = Anchor.Y + displayArea.Anchor.Y;

                    if (absY == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        if (absX > characterMap[absY - 1].Count)
                        {
                            absX = characterMap[absY - 1].Count;
                        }

                        absY--;
                    }

                    Anchor.X = absX - displayArea.Anchor.X;
                    Anchor.Y = absY - displayArea.Anchor.Y;

                    if (Anchor.X < displayArea.Width && Anchor.Y < displayArea.Height)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
Example #2
0
                public bool MoveRight(TextboxDisplayArea displayArea, List <List <char?> > characterMap)
                {
                    int absX = Anchor.X + displayArea.Anchor.X;
                    int absY = Anchor.Y + displayArea.Anchor.Y;

                    if (absX == characterMap[absY].Count)
                    {
                        if (absY == characterMap.Count - 1)
                        {
                            return(false);
                        }
                        else
                        {
                            absX = 0;
                            absY++;
                        }
                    }
                    else
                    {
                        absX++;
                    }

                    Anchor.X = absX - displayArea.Anchor.X;
                    Anchor.Y = absY - displayArea.Anchor.Y;

                    if (Anchor.X < displayArea.Width && Anchor.Y < displayArea.Height)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
Example #3
0
                public char ParseAndExecute(ConsoleKeyInfo keyPressed,
                                            TextboxDisplayArea parentComponent, ref List <List <char?> > characterMap)
                {
                    switch (keyPressed.Key)
                    {
                    /*
                     * If pointer succeed in moving in whatever direction, it gives no feedback
                     * If fail, then pass out the reason
                     * "w" for up; "s" for down; "a" for left; "d" for right; "n" for "NO CHANGE"
                     * "0" for not using the key
                     */

                    case ConsoleKey.UpArrow:
                        if (MoveUp(parentComponent, characterMap))
                        {
                            return('w');
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (MoveDown(parentComponent, characterMap))
                        {
                            return('s');
                        }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (MoveLeft(parentComponent, characterMap))
                        {
                            return('a');
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (MoveRight(parentComponent, characterMap))
                        {
                            return('d');
                        }
                        break;

                    default:
                        return('0');
                    }

                    return('n');
                }