private Image GetNotice(GameBoard gameboard, int x_len, int y_len) { System.Drawing.Image img = new System.Drawing.Bitmap(y_len * blocksize, x_len * blocksize); int stringheight = 40; int nums_x = 15, nums_y = x_len * blocksize - 50, tab_x = 45; int money_width = 26, money_height = 4; System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); //Font font = new Font("Bauhaus 93", 24); g.DrawString(gameboard.level.ToString("00"), font, level, y_len * blocksize - 60, x_len * blocksize - 50); if (is_tab_down) { g.DrawString("Floor - ", font, level, y_len * blocksize - 180, x_len * blocksize - 50); } g.DrawString(gameboard.player.hp.ToString("00"), font, money, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Many Coins You Have", font, money, nums_x + tab_x, nums_y); } nums_y += 3; for (int i = 0; i < gameboard.player.hp; i++) { nums_y -= money_height + 1; g.FillRectangle(money, nums_x + 14, nums_y, money_width, money_height); } for (int i = 0; i < gameboard.player.moneylimit - gameboard.player.hp; i++) { nums_y -= money_height + 1; } nums_y -= 6; g.FillRectangle(moneylimit, nums_x + 10, nums_y, 34, 2); nums_y -= stringheight; g.DrawString(gameboard.player.moneylimit.ToString("00"), font, moneylimit, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Many Coins You Can Carry", font, moneylimit, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(gameboard.player.attack.ToString("00"), font, damage, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Much Damage Each Coin Does", font, damage, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(((int)(Math.Ceiling(gameboard.sight))).ToString("00"), font, sight, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Far Away You Can See", font, sight, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(gameboard.rednoticedist.ToString("00"), font, rednoticedist, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Far Away Red Notice You", font, rednoticedist, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(gameboard.newredgen.ToString("00"), font, newredgen, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Often New Red Arrives", font, newredgen, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(gameboard.coinsonfloor.ToString("00"), font, coinsonfloor, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Much Coins On Each Floor", font, coinsonfloor, nums_x + tab_x, nums_y); } nums_y -= stringheight; g.DrawString(gameboard.player.diamond.ToString("00"), font, diamond, nums_x, nums_y); if (is_tab_down) { g.DrawString(" - How Diamonds You Have", font, diamond, nums_x + tab_x, nums_y); } //g.DrawString(gameboard.diamonds.ToString("00"), font, brush, nums_x, nums_y); //Console.WriteLine("diaoy"); return(img); }
private Image GetFullImage(GameBoard gameboard, double x_st, double y_st, int x_len, int y_len)//获取显示的画面 { System.Drawing.Image img = new System.Drawing.Bitmap(y_len * blocksize, x_len * blocksize); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); if (gameboard.player.is_hurt) { g.FillRectangle(hurt, 0, 0, y_len * blocksize, x_len * blocksize); gameboard.player.is_hurt = false; return(img); } System.Drawing.Image notice = GetNotice(gameboard, x_len, y_len); //获得绘制开始的格子和绘制大小 //如果在运动中,则先绘制大一圈的图像,然后显示其一部分 int x, y; x = Math.Max((int)Math.Floor(x_st), 0); y = Math.Max((int)Math.Floor(y_st), 0); if (x_st > x) { x_len++; } if (y_st > y) { y_len++; } //Console.WriteLine(x_st + " " + x + " " + y_st + " " + y); //绘制静止对象 System.Drawing.Image whole_img = new System.Drawing.Bitmap(y_len * blocksize, x_len * blocksize); System.Drawing.Graphics whole_g = System.Drawing.Graphics.FromImage(whole_img); for (int i = x; i < x + x_len; i++) { for (int j = y; j < y + y_len; j++) { whole_g.DrawImage(GetUnmoveableImage(gameboard, i, j), blocksize * (j - y), blocksize * (i - x), blocksize, blocksize); } } //绘制画面(运动中则取其一部分) whole_g.DrawImage(gameboard.player.GetImage(), (int)(blocksize * (gameboard.player.y_drawposition - y)), (int)(blocksize * (gameboard.player.x_drawposition - x)), blocksize, blocksize); //绘制敌人 foreach (Enemy enemy in gameboard.enemies) { if (enemy.Distance(gameboard.player.x, gameboard.player.y) <= gameboard.sight) { whole_g.DrawImage(enemy.GetImage(), (int)(blocksize * (enemy.y_drawposition - y)), (int)(blocksize * (enemy.x_drawposition - x)), blocksize, blocksize); } else { enemy.FreshDrawPosition(); } } //绘制子弹 foreach (Bullet bullet in gameboard.bullets) { if (gameboard.player.Distance((int)bullet.x, (int)bullet.y) <= gameboard.sight) { whole_g.DrawImage(bullet.GetImage(), (int)(blocksize * (bullet.y_drawposition - y)), (int)(blocksize * (bullet.x_drawposition - x)), blocksize, blocksize); } } g.DrawImage(whole_img, (int)(-(y_st - y) * blocksize), (int)(-(x_st - x) * blocksize)); g.DrawImage(notice, 0, 0); g.DrawImage(GetTopNotice(gameboard, x_len, y_len), 0, 0); return(img); }
private Image GetTopNotice(GameBoard gameboard, int x_len, int y_len) { string notice; Type type; Brush brush = Brushes.Red; if (gameboard.noticelist.Count == 0 && gameboard.is_playerdead == false && gameboard.is_win == false) { return(new System.Drawing.Bitmap(y_len * blocksize, x_len * blocksize)); } if (gameboard.is_playerdead == true) { notice = "You Died ! Press Any Key To Restart"; notice_frame = 0; type = typeof(Space); } else if (gameboard.is_win == true) { notice = "You Win ! Press Any Key To Restart"; notice_frame = 0; type = typeof(Space); brush = win; } else { (notice, type) = gameboard.noticelist[0]; } System.Drawing.Image img = new System.Drawing.Bitmap(y_len * blocksize, x_len * blocksize); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); int notice_stopframe = notice_enemystopframe; if (type.IsSubclassOf(typeof(Shop))) { notice_stopframe = notice_shopstopframe; } if (type == typeof(MoneyLimit_Shop)) { brush = moneylimit; } else if (type == typeof(Damage_Shop)) { brush = damage; } else if (type == typeof(Sight_Shop)) { brush = sight; } else if (type == typeof(RedNoticeDist_Shop)) { brush = rednoticedist; } else if (type == typeof(NewRedGen_Shop)) { brush = newredgen; } else if (type == typeof(CoinOnFloor_Shop)) { brush = coinsonfloor; } else if (type == typeof(Diamond_Shop)) { brush = diamond; } if (is_showing_topnotice) { if (notice_y == notice_endy && notice_frame < notice_stopframe) { notice_frame++; } else if (notice_y == notice_endy && notice_frame >= notice_stopframe) { notice_frame = 0; notice_y += noticespeed; } else { notice_y += noticespeed; } if (notice_y > notice_endy) { notice_y = notice_endy; noticespeed = -noticespeed; } else if (notice_y < notice_starty) { notice_y = notice_starty; noticespeed = -noticespeed; is_showing_topnotice = false; gameboard.noticelist.RemoveAt(0); } } else { notice_y = notice_starty; is_showing_topnotice = true; SizeF sizeF = g.MeasureString(notice, font); notice_x = (y_len * blocksize - sizeF.Width) / 2; } g.DrawString(notice, font, brush, notice_x, notice_y); return(img); }