自动打怪 c#

其中思路很简单,单线程的一个乱七八糟的游戏

预计会更新背包,背包这个估计会用一个vector来存

图形的话,我得催催我的美工大人,她会帮我弄吧,哇哈哈

界面:

自动打怪 c#
  1 namespace auttompk
  2 {
  3     partial class Form1
  4     {
  5         /// <summary>
  6         /// 必需的设计器变量。
  7         /// </summary>
  8         private System.ComponentModel.IContainer components = null;
  9 
 10         /// <summary>
 11         /// 清理所有正在使用的资源。
 12         /// </summary>
 13         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
 14         protected override void Dispose(bool disposing)
 15         {
 16             if (disposing && (components != null))
 17             {
 18                 components.Dispose();
 19             }
 20             base.Dispose(disposing);
 21         }
 22 
 23         #region Windows 窗体设计器生成的代码
 24 
 25         /// <summary>
 26         /// 设计器支持所需的方法 - 不要
 27         /// 使用代码编辑器修改此方法的内容。
 28         /// </summary>
 29         private void InitializeComponent()
 30         {
 31             this.button1 = new System.Windows.Forms.Button();
 32             this.button2 = new System.Windows.Forms.Button();
 33             this.label1 = new System.Windows.Forms.Label();
 34             this.label2 = new System.Windows.Forms.Label();
 35             this.label3 = new System.Windows.Forms.Label();
 36             this.label6 = new System.Windows.Forms.Label();
 37             this.label4 = new System.Windows.Forms.Label();
 38             this.explabel = new System.Windows.Forms.Label();
 39             this.attacklabel = new System.Windows.Forms.Label();
 40             this.hplabel = new System.Windows.Forms.Label();
 41             this.levellabel = new System.Windows.Forms.Label();
 42             this.fightbox = new System.Windows.Forms.TextBox();
 43             this.splitter1 = new System.Windows.Forms.Splitter();
 44             this.SuspendLayout();
 45             // 
 46             // button1
 47             // 
 48             this.button1.Location = new System.Drawing.Point(575, 254);
 49             this.button1.Name = "button1";
 50             this.button1.Size = new System.Drawing.Size(189, 62);
 51             this.button1.TabIndex = 0;
 52             this.button1.Text = "开始";
 53             this.button1.UseVisualStyleBackColor = true;
 54             this.button1.Click += new System.EventHandler(this.button1_Click);
 55             // 
 56             // button2
 57             // 
 58             this.button2.Location = new System.Drawing.Point(575, 322);
 59             this.button2.Name = "button2";
 60             this.button2.Size = new System.Drawing.Size(189, 64);
 61             this.button2.TabIndex = 1;
 62             this.button2.Text = "停止";
 63             this.button2.UseVisualStyleBackColor = true;
 64             this.button2.Click += new System.EventHandler(this.button2_Click);
 65             // 
 66             // label1
 67             // 
 68             this.label1.AutoSize = true;
 69             this.label1.Location = new System.Drawing.Point(573, 71);
 70             this.label1.Name = "label1";
 71             this.label1.Size = new System.Drawing.Size(41, 12);
 72             this.label1.TabIndex = 2;
 73             this.label1.Text = "生命值";
 74             // 
 75             // label2
 76             // 
 77             this.label2.AutoSize = true;
 78             this.label2.Location = new System.Drawing.Point(575, 107);
 79             this.label2.Name = "label2";
 80             this.label2.Size = new System.Drawing.Size(0, 12);
 81             this.label2.TabIndex = 3;
 82             // 
 83             // label3
 84             // 
 85             this.label3.AutoSize = true;
 86             this.label3.Location = new System.Drawing.Point(574, 106);
 87             this.label3.Name = "label3";
 88             this.label3.Size = new System.Drawing.Size(41, 12);
 89             this.label3.TabIndex = 4;
 90             this.label3.Text = "攻击力";
 91             // 
 92             // label6
 93             // 
 94             this.label6.AutoSize = true;
 95             this.label6.Location = new System.Drawing.Point(575, 40);
 96             this.label6.Name = "label6";
 97             this.label6.Size = new System.Drawing.Size(29, 12);
 98             this.label6.TabIndex = 9;
 99             this.label6.Text = "等级";
100             // 
101             // label4
102             // 
103             this.label4.AutoSize = true;
104             this.label4.Location = new System.Drawing.Point(575, 141);
105             this.label4.Name = "label4";
106             this.label4.Size = new System.Drawing.Size(41, 12);
107             this.label4.TabIndex = 12;
108             this.label4.Text = "经验值";
109             // 
110             // explabel
111             // 
112             this.explabel.AutoSize = true;
113             this.explabel.ImageAlign = System.Drawing.ContentAlignment.BottomCenter;
114             this.explabel.Location = new System.Drawing.Point(645, 140);
115             this.explabel.Name = "explabel";
116             this.explabel.Size = new System.Drawing.Size(41, 12);
117             this.explabel.TabIndex = 13;
118             this.explabel.Text = "label5";
119             // 
120             // attacklabel
121             // 
122             this.attacklabel.AutoSize = true;
123             this.attacklabel.Location = new System.Drawing.Point(647, 106);
124             this.attacklabel.Name = "attacklabel";
125             this.attacklabel.Size = new System.Drawing.Size(41, 12);
126             this.attacklabel.TabIndex = 14;
127             this.attacklabel.Text = "label7";
128             // 
129             // hplabel
130             // 
131             this.hplabel.AutoSize = true;
132             this.hplabel.Location = new System.Drawing.Point(645, 71);
133             this.hplabel.Name = "hplabel";
134             this.hplabel.Size = new System.Drawing.Size(41, 12);
135             this.hplabel.TabIndex = 15;
136             this.hplabel.Text = "label8";
137             // 
138             // levellabel
139             // 
140             this.levellabel.AutoSize = true;
141             this.levellabel.Location = new System.Drawing.Point(647, 40);
142             this.levellabel.Name = "levellabel";
143             this.levellabel.Size = new System.Drawing.Size(41, 12);
144             this.levellabel.TabIndex = 16;
145             this.levellabel.Text = "label9";
146             // 
147             // fightbox
148             // 
149             this.fightbox.Location = new System.Drawing.Point(30, 30);
150             this.fightbox.Multiline = true;
151             this.fightbox.Name = "fightbox";
152             this.fightbox.Size = new System.Drawing.Size(492, 375);
153             this.fightbox.TabIndex = 17;
154             // 
155             // splitter1
156             // 
157             this.splitter1.Location = new System.Drawing.Point(0, 0);
158             this.splitter1.Name = "splitter1";
159             this.splitter1.Size = new System.Drawing.Size(3, 438);
160             this.splitter1.TabIndex = 18;
161             this.splitter1.TabStop = false;
162             // 
163             // Form1
164             // 
165             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
166             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
167             this.ClientSize = new System.Drawing.Size(803, 438);
168             this.Controls.Add(this.splitter1);
169             this.Controls.Add(this.fightbox);
170             this.Controls.Add(this.levellabel);
171             this.Controls.Add(this.hplabel);
172             this.Controls.Add(this.attacklabel);
173             this.Controls.Add(this.explabel);
174             this.Controls.Add(this.label4);
175             this.Controls.Add(this.label6);
176             this.Controls.Add(this.label3);
177             this.Controls.Add(this.label2);
178             this.Controls.Add(this.label1);
179             this.Controls.Add(this.button2);
180             this.Controls.Add(this.button1);
181             this.Name = "Form1";
182             this.Text = "挂机传奇";
183             this.ResumeLayout(false);
184             this.PerformLayout();
185 
186         }
187 
188         #endregion
189 
190         private System.Windows.Forms.Button button1;
191         private System.Windows.Forms.Button button2;
192         private System.Windows.Forms.Label label1;
193         private System.Windows.Forms.Label label2;
194         private System.Windows.Forms.Label label3;
195         private System.Windows.Forms.Label label6;
196         private System.Windows.Forms.Label label4;
197         private System.Windows.Forms.Label explabel;
198         private System.Windows.Forms.Label attacklabel;
199         private System.Windows.Forms.Label hplabel;
200         private System.Windows.Forms.Label levellabel;
201         private System.Windows.Forms.TextBox fightbox;
202         private System.Windows.Forms.Splitter splitter1;
203     }
204 }
View Code

新的类:

自动打怪 c#
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace auttompk
 8 {
 9     class monster
10     {
11         public string name;
12         public int hp;
13         public int attack;
14         public int money;
15         public int exp;
16         public int max_hp;
17     }
18 }
View Code

具体代码:

自动打怪 c#
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 
 11 namespace auttompk
 12 {
 13     public partial class Form1 : Form
 14     {
 15         monster shilaimu=new monster();
 16 
 17         int level = 1;
 18         int max_hp = 50;
 19         int now_hp = 50;
 20         int attack = 3;
 21         int now_exp = 0;
 22         int ful_exp = 50;
 23         int flag = 0;
 24 
 25         private void start()
 26         { 
 27             shilaimu.name="史莱姆";
 28             shilaimu.hp=10;
 29             shilaimu.attack=3;
 30             shilaimu.money=1;
 31             shilaimu.exp=1;
 32             shilaimu.max_hp = 10;
 33         }
 34         public Form1()
 35         {
 36             
 37             InitializeComponent();
 38             start();
 39             show();
 40         }
 41 
 42         private void show()
 43         {
 44             levellabel.Text = (level).ToString();
 45             hplabel.Text = now_hp.ToString() + "/" + max_hp.ToString();
 46             attacklabel.Text = (attack).ToString();
 47             explabel.Text = now_exp.ToString() + "/" + max_hp.ToString();
 48         }
 49 
 50         private void find()
 51         {
 52             fightbox.Text += "你遇见了"+shilaimu.name.ToString()+"\r\n";
 53             pk(shilaimu);
 54         }
 55 
 56         private void pk(monster a)
 57         {
 58             while (true)
 59             {
 60                 if (flag == 0)
 61                 {
 62                     break;
 63                 }
 64                 timeDelay(1);
 65                 fightbox.Text += "你对" + a.name.ToString() + "造成了" + attack.ToString() + "伤害\r\n";
 66                 a.hp-=attack;
 67                 if (a.hp <= 0)
 68                 {
 69                     fightbox.Text += "你干死了" + a.name.ToString() + "\r\n";
 70                     fightbox.Text += "获得了" + a.money.ToString() + "块钱\r\n";
 71                     fightbox.Text += "获得了" + a.exp.ToString() + "经验\r\n\r\n\r\n\r\n";
 72                     now_exp += a.exp;
 73                     if (now_exp >= ful_exp)
 74                     {
 75                         now_exp -= ful_exp;
 76                         ful_exp *= 2;
 77                         level += 1;
 78                         attack *= 2;
 79                     }
 80                     a.hp = a.max_hp;
 81                     show();
 82                     break;
 83                 }
 84                 timeDelay(1);
 85                 fightbox.Text += a.name.ToString() + "还剩下" + a.hp.ToString()+"HP\r\n";
 86                 if (flag == 0)
 87                 {
 88                     break;
 89                 }
 90                 timeDelay(1);
 91                 if (flag == 0)
 92                 {
 93                     break;
 94                 }
 95                 fightbox.Text += a.name.ToString() + "对你造成了" + attack.ToString() + "伤害\r\n";
 96 
 97                 now_hp -= a.attack;
 98                 if (now_hp <= 0)
 99                 {
100                     fightbox.Text += "你挂了\r\n";
101                     fightbox.Text += "你损失了一半经验值\r\n\r\n\r\n\r\n";
102                     now_exp /= 2;
103                     now_hp = max_hp;
104                     a.hp = a.max_hp;
105                     show();
106                     break;
107                 }
108      
109                 show();
110                 timeDelay(1);
111             }
112         }
113 
114         private void button1_Click(object sender, EventArgs e)
115         {
116 
117             fightbox.Text += "开始挂机\r\n\r\n\r\n\r\n";
118             flag=1;
119             while (flag == 1)
120             {
121                 find();
122             }
123         }
124         private void timeDelay(double secend)
125         {
126             DateTime tempTime = DateTime.Now;
127             while(tempTime.AddSeconds(secend).CompareTo(DateTime.Now) > 0)
128             Application.DoEvents();
129             
130         }
131 
132         private void button2_Click(object sender, EventArgs e)
133         {
134             fightbox.Text += "停止挂机\r\n\r\n";
135             flag = 0;
136         } 
137     }
138 }
View Code

 

自动打怪 c#

上一篇:C#调用耗时函数时显示进度条浅探


下一篇:暴风雨的礼物·MySQL03:DML语言