最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)簡單打字小游戲

 更新時間:2020年05月14日 08:46:21   作者:oOo!!!!!----蔚楠  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡單打字小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)簡單打字小游戲的具體代碼,供大家參考,具體內(nèi)容如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace 打字游戲
{
 public partial class Form1 : Form
 {
 public Form1()
 {
  InitializeComponent();
 }
 Random r = new Random();
 //游戲區(qū)
 Panel Gamearea = new Panel();
 //控制區(qū)
 Panel area = new Panel();
 //裝鳥的盒子
 PictureBox Bird = new PictureBox();
 //字母出現(xiàn)定時器
 Timer zimu = new Timer();
 //飛鳥與字母下落定時器
 Timer fly = new Timer();
 //開始/暫停按鈕
 Button button = new Button();
 //積分器
 Label scoring = new Label();
 //血條
 Label Bar = new Label();
 //尾翼
 PictureBox wei = new PictureBox();
 PictureBox weiyi = new PictureBox();
 //裝字母的盒子
 List<Label> zmbox = new List<Label>();
 private void Form1_Load(object sender, EventArgs e)
 {
  //button設(shè)置
  this.KeyPreview = true;
  //最大化窗口
  this.WindowState = FormWindowState.Maximized;
  //背景圖
  this.BackgroundImage = Image.FromFile("../../img/背景 (2).jpg");
  //拉伸
  this.BackgroundImageLayout = ImageLayout.Stretch;
  //游戲區(qū)設(shè)置
  Gamearea.Size = new Size(1000,750);
  //游戲區(qū)位置
  Gamearea.Location = new Point(30,30);
  this.Controls.Add(Gamearea);
  Gamearea.Tag = "game";
  //控制區(qū)設(shè)置
  area.Size = new Size(300,750);
  //控制區(qū)位置
  area.Location = new Point(Gamearea.Left+Gamearea.Width+20,30);
  area.BackColor = Color.Cyan;
  this.Controls.Add(area);
  //開始/暫停按鈕
  //Button button = new Button();
  button.Text = "開始";
  this .KeyPreview = true;
  //字體大小
  button.Font = new Font("",20);
  //按鈕大小
  button.Size = new Size(100,50);
  //按鈕顏色
  button.BackColor = Color.Blue;
  //按鈕位置
  button.Location = new Point(100,20);
  area.Controls.Add(button);
  //按鈕點(diǎn)擊事件
  button.Click += Button_Click;
  //積分器
  //Label scoring = new Label();
  scoring.Text = "積分:0";
  scoring.Font = new Font("",15);
  scoring.Location = new Point(100,100);
  area.Controls.Add(scoring);
  //裝鳥的盒子設(shè)置
  Bird.Tag = "niao";
  Bird.Size = new Size(200,200);
  Bird.Location = new Point(0,0);
  //動畫放入盒子
  Bird.Image = imageList1.Images[0];
  Gamearea.Controls.Add(Bird);
  //飛鳥與字母下落定時器
  //Timer fly = new Timer();
  fly.Interval = 80;
  fly.Tick += Fly_Tick;
  //fly.Start();
  //字母出現(xiàn)定時器
  //Timer zimu = new Timer();
  zimu.Interval = 1000;
  zimu.Tick += Zimu_Tick;
  //zimu.Start();
  //鍵盤
  this.KeyPress += Form1_KeyPress1;
  //飛機(jī)
  //PictureBox plane = new PictureBox();
  plane.Tag = "plane";
  //盒子大小
  plane.Size = new Size(100,100);
  //放進(jìn)圖片
  plane.Image = Image.FromFile("../../img/RP03.png");
  //圖片自適應(yīng)
  plane.SizeMode = PictureBoxSizeMode.StretchImage;
  //飛機(jī)位置
  plane.Location = new Point(Gamearea.Width/2-plane.Width/2,Gamearea.Height-plane.Height-60);
  Gamearea.Controls.Add(plane);
  //血條
  //Label Bar = new Label();
  Bar.Tag = "bar";
  Bar.Size = new Size(100, 10);
  Bar.BackColor = Color.Red;
  //位置
  Bar.Left = plane.Left + plane.Width - Bar.Width;
  Bar.Top = plane.Top - Bar.Height;
  Gamearea.Controls.Add(Bar);
  //尾翼  
  wei.Tag = "wei";  
  wei.Size = new Size(30, 40);
  //位置
  wei.Left = plane.Left + plane.Width / 2;  
  wei.Top = plane.Top + plane.Height; 
  //圖片集放進(jìn)盒子
  wei.Image = imageList3.Images[0];  
  Gamearea.Controls.Add(wei);  
  weiyi.Tag = "weiji";
  //圖片集放進(jìn)盒子
  weiyi.Image = imageList3.Images[0];  
  weiyi.Size = new Size(30, 40);
  //位置
  weiyi.Left = plane.Left + plane.Width /2-28;  
  weiyi.Top = plane.Top + plane.Height;
  Gamearea.Controls.Add(weiyi);
 }
 //按鈕設(shè)置
 private void Button_Click(object sender, EventArgs e)
 {
  if (button.Text=="開始")
  {
  fly.Start();
  zimu.Start();
  button.Text = "暫停";
  }
  else if (button.Text=="暫停")
  {
  fly.Stop();
  zimu.Stop();
  button.Text = "開始";
 
  }
 }
 //飛機(jī)
 PictureBox plane = new PictureBox();
 //鍵盤事件
 private void Form1_KeyPress1(object sender, KeyPressEventArgs e)
 {
  //遍歷游戲區(qū)內(nèi)所有控件
  foreach (Control item in Gamearea.Controls)
  {
  //找到name為Label的控件
  if (item.GetType().Name == "Label")
  {
   //判斷按鍵與字母是否相同
   if (item.Text == e.KeyChar.ToString()&& item.Tag.ToString() == "zm")
   {
   ////消除字母
   //item.Dispose();
   plane.Left = item.Left + item.Width / 2 - plane.Width / 2;
   //血條隨飛機(jī)
   Bar.Left = plane.Left + plane.Width - Bar.Width;
   Bar.Top = plane.Top - Bar.Height;
   //尾翼隨飛機(jī)
   wei.Left = plane.Left + plane.Width / 2;
   wei.Top = plane.Top + plane.Height;
   weiyi.Left = plane.Left + plane.Width / 2 - 28;
   weiyi.Top = plane.Top + plane.Height;
   item.Tag = "bj";
   //創(chuàng)造子彈
   PictureBox bullet = new PictureBox();
   bullet.Tag = "bullet";
   bullet.Size = new Size(10,30);
   //放進(jìn)圖片
   bullet.Image = Image.FromFile("../../img/Ammo1.png");
   //圖片自適應(yīng)
   bullet.SizeMode = PictureBoxSizeMode.StretchImage;
   //子彈位置
   bullet.Location = new Point(plane.Left+plane.Width/2-bullet.Width/2,plane.Top-bullet.Height);
   Gamearea.Controls.Add(bullet);
   return;
   }
  }
  }
 }
 
 //字母
 private void Zimu_Tick(object sender, EventArgs e)
 {
  //判斷飛鳥出現(xiàn)屏幕字母開始下落
  if (Bird.Left >= 0 && Bird.Left <= Gamearea.Width - Bird.Width)
  {
  Label zm = new Label();
  zm.Tag = "zm";
  //隨機(jī)字母
  zm.Text =((char)r.Next(97,123)).ToString();
  //隨機(jī)大小
  zm.Font = new Font("",r.Next(10,45));
  //字體自適應(yīng)
  zm.AutoSize = true;
  //隨機(jī)顏色
  zm.ForeColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
  //隨著鳥的位置下落
  zm.Top = Bird.Height;
  zm.Left = Bird.Left + Bird.Width / 2 - zm.Width / 2;
  //添加進(jìn)游戲區(qū)
  Gamearea.Controls.Add(zm);
  zmbox.Add(zm);
  }
 }
 //播放飛鳥動畫
 int bo = 0;
 //積分
 int fen = 0;
 int t = 0, y = 0;
 private void Fly_Tick(object sender, EventArgs e)
 {
  //飛鳥動畫播放
  Bird.Image = imageList1.Images[bo];
  bo++;
  //圖片播放完重零開始重新播放
  if (bo >= imageList1.Images.Count)
  {
  bo = 0;
  }
  //遍歷控件
  foreach (Control item in Gamearea.Controls)
  {
  //鳥飛
  if (item.Tag.ToString()=="niao")
  {
   item.Left += 10;
   //超出邊界重新開始飛
   if (item.Left>=Gamearea.Width)
   {
   item.Left = -item.Width;
   }
  }
  //字母下落
  if (item.Tag.ToString() == "zm"||item.Tag.ToString()=="bj")
  {
   item.Top += 10;
   //超出下邊界清除
   if (item.Top+item.Height>=Gamearea.Height)
   {
   
   item.Dispose();
   Bar.Width -= 10;
   //判斷血條為零時
   if (Bar.Width==0)
   {
    fly.Stop();
    zimu.Stop();
    //彈框
    if ( MessageBox.Show("游戲結(jié)束,積分為:"+fen,"Game Over", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
    {
    fly.Stop();
    zimu.Stop();
    //滿血條
    Bar.Width = 100;
    //按鈕變開始
    button.Text = "開始";
    //積分清零
    scoring.Text = "積分:0";
    //鳥回歸原位
    Bird.Location = new Point(0, 0);
    //清屏
    qingping();
    }
    else
    {
    this.Close();
    }
   }
   }
  }
  //子彈上升
  if (item.Tag.ToString() == "bullet")
  {
   item.Top -= 10;
   //超出上邊界清除
   if (item.Top==-item.Top)
   {
   item.Dispose();
   }
   //重新遍歷
   foreach (Control letter in Gamearea.Controls)
   {
   //找到字母
   if (letter.Tag.ToString() == "bj")
   {
    //判斷字母與子彈相遇
    if (item.Top <= letter.Top + letter.Height && item.Left + item.Width / 2 == letter.Left + letter.Width / 2)
    {
    item.Dispose();
    letter.Dispose();
    //積分自加
    fen++;
    //寫入控制區(qū)
    scoring.Text = "積分:" + fen;
    //創(chuàng)造爆炸
    PictureBox detonate = new PictureBox();
    //記錄播放圖片從零開始
    detonate.Tag = 0;
    //盒子大小
    detonate.Size = new Size(50,50);
    //將圖片放進(jìn)盒子
    detonate.Image = imageList2.Images[0];
    //圖片自適應(yīng)
    detonate.SizeMode = PictureBoxSizeMode.StretchImage;
    //爆炸位置
    detonate.Location = new Point(letter.Left + letter.Width / 2 - detonate.Width / 2, letter.Top + letter.Height / 2 - detonate.Height / 2);
    Gamearea.Controls.Add(detonate);
    //爆炸timer
    Timer zha = new Timer();
    //爆炸圖片放進(jìn)timer
    zha.Tag = detonate;
    zha.Interval = 100;
    zha.Tick += Zha_Tick;
    zha.Start();
    }
   }
   }
  }
  //尾翼動畫播放
  wei.Image = imageList3.Images[t];
  t++; 
  if (t >= imageList3.Images.Count) 
  {
   t = 0; 
  }
  weiyi.Image = imageList3.Images[y]; 
  y++; 
  if (y >= imageList3.Images.Count) 
  {
   y = 0; 
  }
  }
 }
 
 private void Zha_Tick(object sender, EventArgs e)
 {
  //獲取timer
  Timer zha = (Timer)sender;
  //從盒子獲取圖片集
  PictureBox picture = (PictureBox)zha.Tag;
  //獲取imageList2中圖片
  picture.Image = imageList2.Images[(int)picture.Tag];
  //圖片播放
  picture.Tag = (int)picture.Tag + 1;
  //一組爆炸圖播完清除  
  if ((int)picture.Tag == 32)
  {
  zha.Dispose();
  picture.Dispose();
  
  }
 }
 //清屏字母
 private void qingping()
 {
  foreach (Label lazm in zmbox)
  {
  lazm.Dispose();
  }
 }
 }
}

更多有趣的經(jīng)典小游戲?qū)崿F(xiàn)專題,也分享給大家:

C++經(jīng)典小游戲匯總

python經(jīng)典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經(jīng)典游戲 玩不停

java經(jīng)典小游戲匯總

javascript經(jīng)典小游戲匯總

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • c#和sql如何獲得時間間隔的方法

    c#和sql如何獲得時間間隔的方法

    這篇文章主要介紹了c#和sql如何獲得時間間隔的方法,有需要的朋友可以參考一下
    2013-12-12
  • 為什么哈希存取比較快?使用它需要付出什么代價

    為什么哈希存取比較快?使用它需要付出什么代價

    本文主要介紹為什么哈希存取比較快的原理,有需要的朋友可以參考一下。
    2016-06-06
  • C#泛型集合類System.Collections.Generic

    C#泛型集合類System.Collections.Generic

    這篇文章介紹了C#中的泛型集合類System.Collections.Generic,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • C#中實(shí)現(xiàn)插入、刪除Excel分頁符的方法

    C#中實(shí)現(xiàn)插入、刪除Excel分頁符的方法

    這篇文章主要給大家介紹了關(guān)于在C#中實(shí)現(xiàn)插入、刪除Excel分頁符的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • C# Double轉(zhuǎn)化為String時的保留位數(shù)及格式方式

    C# Double轉(zhuǎn)化為String時的保留位數(shù)及格式方式

    這篇文章主要介紹了C# Double轉(zhuǎn)化為String時的保留位數(shù)及格式方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • C#中神器類BlockingCollection的實(shí)現(xiàn)詳解

    C#中神器類BlockingCollection的實(shí)現(xiàn)詳解

    如果你想玩轉(zhuǎn)C#?里面多線程,工廠模式,生產(chǎn)者/消費(fèi)者,隊(duì)列等高級操作,就可以和我一起探索這個強(qiáng)大的線程安全提供阻塞和限制功能的C#神器類BlockingCollection吧
    2023-02-02
  • C#中的反射(System.Reflection)

    C#中的反射(System.Reflection)

    這篇文章介紹了C#中的反射(System.Reflection),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • C# WebApi Get請求方式傳遞實(shí)體參數(shù)的方法示例

    C# WebApi Get請求方式傳遞實(shí)體參數(shù)的方法示例

    這篇文章主要給大家介紹了關(guān)于C# WebApi Get請求方式傳遞實(shí)體參數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 關(guān)于C#中的字體別名問題

    關(guān)于C#中的字體別名問題

    在C#中使用Graphics對象的DrawString方法繪制文本時,可以通過設(shè)置TextRenderingHint屬性來控制字體混疊效果,對于14號或更大的字體,建議使用AntiAliasGridFit;對于8到14點(diǎn)之間的字體,建議使用AntiAlias;對于小于8點(diǎn)的字體,建議使用ClearTypeGridFit
    2025-01-01
  • Unity實(shí)現(xiàn)圓形Image組件

    Unity實(shí)現(xiàn)圓形Image組件

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)圓形Image組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評論

胶州市| 西华县| 大悟县| 南开区| 镇江市| 瑞金市| 西乌珠穆沁旗| 万州区| 驻马店市| 吴旗县| 麻栗坡县| 禄丰县| 通州区| 云安县| 黑龙江省| 青铜峡市| 信宜市| 英吉沙县| 泰和县| 普兰县| 双辽市| 临洮县| 青河县| 集贤县| 菏泽市| 玉门市| 外汇| 同心县| 沽源县| 太仆寺旗| 新绛县| 灵石县| 宿州市| 科技| 乡城县| 长武县| 萍乡市| 高阳县| 永胜县| 宣威市| 五大连池市|