Ejemplo n.º 1
0
 public ClsKeyCode(ClsKeyCode key)
 {
     this.UpCode    = key.UpCode;
     this.DownCode  = key.DownCode;
     this.LeftCode  = key.LeftCode;
     this.RightCode = key.RightCode;
 }
Ejemplo n.º 2
0
        public FrmOption()
        {
            InitializeComponent();

            this.BGcolor_Option     = 14;
            this.snakeColor1_Option = 3;
            this.snakeColor2_Option = 0;
            this.foodColor_Option   = 5;

            this.BackgroundImage       = new Bitmap(Application.StartupPath + ClsParameter.LinkBackground + ClsParameter.Extension);
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.pictureBoxMapColor.BackgroundImageLayout     = ImageLayout.Stretch;
            this.pictureBoxPlayerColor1.BackgroundImageLayout = ImageLayout.Stretch;
            this.pictureBoxPlayerColor2.BackgroundImageLayout = ImageLayout.Stretch;
            this.pictureBoxFoodColor.BackgroundImageLayout    = ImageLayout.Stretch;

            this.isSingle  = true;
            this.mapSize   = ClsParameter.MapSize.Medium;
            this.hasBorder = false;
            this.BGcolor   = ClsParameter.SFColor.getColor(14);

            this.snakeLengh  = ClsParameter.SnakeLenghDefault;
            this.snakeSize   = ClsParameter.SnakeSize.Medium;
            this.snakeColor1 = ClsParameter.SFColor.getColor(3);
            this.snakeColor2 = ClsParameter.SFColor.getColor(4);
            this.foodColor   = ClsParameter.SFColor.getColor(3);

            this.playerKey1 = ClsParameter.PlayerKey1;
            this.playerKey2 = ClsParameter.PlayerKey2;

            this.isSpeedup = false;

            this.display();
        }
Ejemplo n.º 3
0
        public void processEventKey(ClsSnake snake, ClsKeyCode key)
        {
            Direction direction = this.getKeyCode(snake, key);

            if (direction == Direction.NONE)
            {
                return;
            }
            snake.updateCorner(direction);
        }
Ejemplo n.º 4
0
        public FrmMode2(ClsMapWidthHeight winsize,
                        bool hasborder,
                        string color,
                        int lengh,
                        int snakesize,
                        string snakecolor1,
                        string snakecolor2,
                        string foodcolor,
                        bool isspeedup,
                        ClsKeyCode playerkey1,
                        ClsKeyCode playerkey2)
        {
            InitializeComponent();
            this.MapSizeWidth  = winsize.Width;
            this.MapSizeHeight = winsize.Height;
            this.hasBorder     = hasborder;

            this.BackgroundImage                 = new Bitmap(Application.StartupPath + ClsParameter.LinkBackground + ClsParameter.Extension);
            this.BackgroundImageLayout           = ImageLayout.Stretch;
            this.ptbGame.BackgroundImage         = new Bitmap(Application.StartupPath + ClsParameter.LinkBGGame + color + ClsParameter.Extension);
            this.ptbGame.BackgroundImageLayout   = ImageLayout.Stretch;
            this.ptbBorder.BackgroundImage       = new Bitmap(Application.StartupPath + ClsParameter.LinkBDGame + ClsParameter.Extension);
            this.ptbBorder.BackgroundImageLayout = ImageLayout.Stretch;
            this.ptbBorder.Visible               = (this.hasBorder);

            this.snake1 = new ClsSnake(lengh, snakesize, snakecolor1, 1, this.MapSizeWidth, this.MapSizeHeight);
            this.snake2 = new ClsSnake(lengh, snakesize, snakecolor2, 3, this.MapSizeWidth, this.MapSizeHeight);
            this.food   = new ClsFood(foodcolor);

            this.isSpeedup = isspeedup;
            this.key1      = playerkey1;
            this.key2      = playerkey2;

            this.increaceFree1 = false;
            this.increaceFree2 = false;

            this.process = new ClsProcessLogic();
            this.press   = new ClsEventKey();

            this.playerName1 = "";
            this.playerName2 = "";
            this.score1      = 0;
            this.score2      = 0;

            this.setWindow();

            this.timerDelay1.Interval = ClsParameter.DelayDefault;
            this.timerDelay1.Start();
            this.timerDelay2.Interval = ClsParameter.DelayDefault;
            this.timerDelay2.Start();

            this.food.generateFood(snake1, snake2, MapSizeWidth, MapSizeHeight);
        }
Ejemplo n.º 5
0
 private Direction getKeyCode(ClsSnake snake, ClsKeyCode key)
 {
     if (ClsInput.KeyPressed(key.UpCode) && snake.Direct != Direction.UP && snake.Direct != Direction.DOWN)
     {
         return(Direction.UP);
     }
     if (ClsInput.KeyPressed(key.DownCode) && snake.Direct != Direction.UP && snake.Direct != Direction.DOWN)
     {
         return(Direction.DOWN);
     }
     if (ClsInput.KeyPressed(key.LeftCode) && snake.Direct != Direction.LEFT && snake.Direct != Direction.RIGHT)
     {
         return(Direction.LEFT);
     }
     if (ClsInput.KeyPressed(key.RightCode) && snake.Direct != Direction.LEFT && snake.Direct != Direction.RIGHT)
     {
         return(Direction.RIGHT);
     }
     return(Direction.NONE);
 }