static char[,] FrogUpdate(Container container, char[,] mappos, Frog frog) { int y = frog.y; int x = frog.x; frog.jumpduring = DateTime.Now;//跳跃时间计算 if (frog.jump == true) { if (frog.Be_Brick(frog.x, frog.y - 1, container) || frog.y - 1 <= 1)//在空中撞到砖块或者边界,马上下降 { frog.jump = false; } else { if (frog.y >= frog.starty - 4) //如果在跳跃高度内,往上跳 { double c = TimeGo(frog.jumpduring, frog.jumpstart); //与起跳时间的秒数差 frog.y -= (int)Math.Round(-0.444 * c * c + 2.666 * c + 1); Clear(mappos); mappos[frog.y, frog.x] = 'm'; } else if (frog.y < frog.starty - 3)//超越跳跃最高点了 { frog.jump = false; } } }//跳跃 if (frog.Be_Reporter(frog.x, frog.y, container) || frog.Be_Water(frog.x, frog.y + 1, container)) { frog.hp = 0; }//青蛙碰怪或者碰到水 if (!frog.Be_Brick(frog.x, frog.y + 1, container) && frog.jump == false) { frog.y++; Clear(mappos); mappos[frog.y, frog.x] = 'm'; }//青蛙脚下没有砖块 if (mappos[frog.y + 1, frog.x] == '@') { mappos[frog.y + 1, frog.x] = ' '; container.re.Remove((frog.y + 1) * 100 + frog.x); }//青蛙脚下是怪 if (container.bu.Count > 0) { List <Bullet> disappear = new List <Bullet>(); BulletClear(mappos); foreach (var bullet in container.bu) { if (bullet.x - bullet.startx > 10 || bullet.Be_Brick(bullet.x + 1, bullet.y, container) || bullet.Be_Reporter(bullet.x, bullet.y, container)) { disappear.Add(bullet); } else { bullet.x++; mappos[bullet.y, bullet.x] = '>'; } } foreach (var bullet in disappear) { container.bu.Remove(bullet); } } //子弹判定(如果子弹超过射程或者子弹碰墙或者子弹碰到怪便消失) return(mappos); } //青蛙的更新
static char[,] FrogMove(Container container, char[,] mappos, Frog frog)//判断青蛙运动 { ConsoleKeyInfo keyInfo = Console.ReadKey(true); int y = frog.y; int x = frog.x; if (keyInfo.Key == ConsoleKey.RightArrow || keyInfo.Key == ConsoleKey.LeftArrow)//如果往左或者往右运动,就计算按键时差 { float oversecond = 0, startsecond = 0; startsecond = DateTime.Now.Millisecond; if (System.Math.Abs(startsecond - oversecond) < 100) { return(mappos); } else { if (!frog.Be_Brick(frog.x, frog.y + 1, container) && frog.airmove <= 0) { return(mappos); } else { frog.airmove--; oversecond = startsecond; if (keyInfo.Key == ConsoleKey.RightArrow) { if (frog.Be_Brick(frog.x + 1, frog.y, container)) { return(mappos); } //往左撞墙 else { frog.x++; Clear(mappos); mappos[frog.y, frog.x] = 'm'; } } else if (keyInfo.Key == ConsoleKey.LeftArrow) { if (frog.Be_Brick(frog.x - 1, frog.y, container)) { return(mappos); } //往右撞墙 else if (frog.x - 1 < 0) { frog.x++; return(mappos); } else { frog.x--; Clear(mappos); mappos[frog.y, frog.x] = 'm'; } } } } } if (keyInfo.Key == ConsoleKey.UpArrow && frog.Be_Brick(frog.x, frog.y + 1, container))//如果按键跳跃就计算是否站在地面上,是则跳跃,否则不跳跃 { frog.jump = true; frog.starty = frog.y; frog.airmove = 5; frog.jumpstart = DateTime.Now; } if (frog.Be_Glasses(frog.x, frog.y, container))//如果碰到眼镜,则捡到武器 { frog.arm = true; } if (keyInfo.Key == ConsoleKey.Spacebar && frog.arm == true)//如果持有武器且按键,则射击 { frog.attack = true; Bullet bullet = new Bullet(); container.bu.Add(bullet); bullet.x = frog.x; bullet.y = frog.y; bullet.startx = frog.x; } if (frog.Be_Timecoin(frog.x, frog.y, container))//碰到硬币 { container.ti.Remove((y + 1) * 100 + x); frog.timecoin++; } if (frog.Be_Brick(frog.x, frog.y + 1, container)) { frog.airmove = 5; } return(mappos); }