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); }
public void logicBorderEnable(ClsSnake snake, ref bool increacefree, ClsFood food, int width, int height, bool ischangespeed, Timer time) { if (increacefree) { active.afterConlideBigFood(snake, ref increacefree, food, width, height); } else if (this.collideFood(snake, food)) { active.afterCollideFood(snake, ref increacefree, food, width, height, ischangespeed, time); } if (this.collideSnake(snake) || this.collideBorder(snake, width, height)) { active.afterCollideSnakeOrBorder(snake); } else { snake.moveSnake(); } }
private bool collideFood(ClsSnake snake, ClsFood food) { return(food.Coor.X == snake.Coor[0].X && food.Coor.Y == snake.Coor[0].Y); }