自动打怪 c#

时间:2023-12-27 13:12:31

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

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

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

界面:

 namespace auttompk
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.explabel = new System.Windows.Forms.Label();
this.attacklabel = new System.Windows.Forms.Label();
this.hplabel = new System.Windows.Forms.Label();
this.levellabel = new System.Windows.Forms.Label();
this.fightbox = new System.Windows.Forms.TextBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "开始";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(, );
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(, );
this.button2.TabIndex = ;
this.button2.Text = "停止";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "生命值";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(, );
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(, );
this.label2.TabIndex = ;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(, );
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(, );
this.label3.TabIndex = ;
this.label3.Text = "攻击力";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(, );
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(, );
this.label6.TabIndex = ;
this.label6.Text = "等级";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(, );
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(, );
this.label4.TabIndex = ;
this.label4.Text = "经验值";
//
// explabel
//
this.explabel.AutoSize = true;
this.explabel.ImageAlign = System.Drawing.ContentAlignment.BottomCenter;
this.explabel.Location = new System.Drawing.Point(, );
this.explabel.Name = "explabel";
this.explabel.Size = new System.Drawing.Size(, );
this.explabel.TabIndex = ;
this.explabel.Text = "label5";
//
// attacklabel
//
this.attacklabel.AutoSize = true;
this.attacklabel.Location = new System.Drawing.Point(, );
this.attacklabel.Name = "attacklabel";
this.attacklabel.Size = new System.Drawing.Size(, );
this.attacklabel.TabIndex = ;
this.attacklabel.Text = "label7";
//
// hplabel
//
this.hplabel.AutoSize = true;
this.hplabel.Location = new System.Drawing.Point(, );
this.hplabel.Name = "hplabel";
this.hplabel.Size = new System.Drawing.Size(, );
this.hplabel.TabIndex = ;
this.hplabel.Text = "label8";
//
// levellabel
//
this.levellabel.AutoSize = true;
this.levellabel.Location = new System.Drawing.Point(, );
this.levellabel.Name = "levellabel";
this.levellabel.Size = new System.Drawing.Size(, );
this.levellabel.TabIndex = ;
this.levellabel.Text = "label9";
//
// fightbox
//
this.fightbox.Location = new System.Drawing.Point(, );
this.fightbox.Multiline = true;
this.fightbox.Name = "fightbox";
this.fightbox.Size = new System.Drawing.Size(, );
this.fightbox.TabIndex = ;
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(, );
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(, );
this.splitter1.TabIndex = ;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.splitter1);
this.Controls.Add(this.fightbox);
this.Controls.Add(this.levellabel);
this.Controls.Add(this.hplabel);
this.Controls.Add(this.attacklabel);
this.Controls.Add(this.explabel);
this.Controls.Add(this.label4);
this.Controls.Add(this.label6);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "挂机传奇";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label explabel;
private System.Windows.Forms.Label attacklabel;
private System.Windows.Forms.Label hplabel;
private System.Windows.Forms.Label levellabel;
private System.Windows.Forms.TextBox fightbox;
private System.Windows.Forms.Splitter splitter1;
}
}

新的类:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace auttompk
{
class monster
{
public string name;
public int hp;
public int attack;
public int money;
public int exp;
public int max_hp;
}
}

具体代码:

 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 auttompk
{
public partial class Form1 : Form
{
monster shilaimu=new monster(); int level = ;
int max_hp = ;
int now_hp = ;
int attack = ;
int now_exp = ;
int ful_exp = ;
int flag = ; private void start()
{
shilaimu.name="史莱姆";
shilaimu.hp=;
shilaimu.attack=;
shilaimu.money=;
shilaimu.exp=;
shilaimu.max_hp = ;
}
public Form1()
{ InitializeComponent();
start();
show();
} private void show()
{
levellabel.Text = (level).ToString();
hplabel.Text = now_hp.ToString() + "/" + max_hp.ToString();
attacklabel.Text = (attack).ToString();
explabel.Text = now_exp.ToString() + "/" + max_hp.ToString();
} private void find()
{
fightbox.Text += "你遇见了"+shilaimu.name.ToString()+"\r\n";
pk(shilaimu);
} private void pk(monster a)
{
while (true)
{
if (flag == )
{
break;
}
timeDelay();
fightbox.Text += "你对" + a.name.ToString() + "造成了" + attack.ToString() + "伤害\r\n";
a.hp-=attack;
if (a.hp <= )
{
fightbox.Text += "你干死了" + a.name.ToString() + "\r\n";
fightbox.Text += "获得了" + a.money.ToString() + "块钱\r\n";
fightbox.Text += "获得了" + a.exp.ToString() + "经验\r\n\r\n\r\n\r\n";
now_exp += a.exp;
if (now_exp >= ful_exp)
{
now_exp -= ful_exp;
ful_exp *= ;
level += ;
attack *= ;
}
a.hp = a.max_hp;
show();
break;
}
timeDelay();
fightbox.Text += a.name.ToString() + "还剩下" + a.hp.ToString()+"HP\r\n";
if (flag == )
{
break;
}
timeDelay();
if (flag == )
{
break;
}
fightbox.Text += a.name.ToString() + "对你造成了" + attack.ToString() + "伤害\r\n"; now_hp -= a.attack;
if (now_hp <= )
{
fightbox.Text += "你挂了\r\n";
fightbox.Text += "你损失了一半经验值\r\n\r\n\r\n\r\n";
now_exp /= ;
now_hp = max_hp;
a.hp = a.max_hp;
show();
break;
} show();
timeDelay();
}
} private void button1_Click(object sender, EventArgs e)
{ fightbox.Text += "开始挂机\r\n\r\n\r\n\r\n";
flag=;
while (flag == )
{
find();
}
}
private void timeDelay(double secend)
{
DateTime tempTime = DateTime.Now;
while(tempTime.AddSeconds(secend).CompareTo(DateTime.Now) > )
Application.DoEvents(); } private void button2_Click(object sender, EventArgs e)
{
fightbox.Text += "停止挂机\r\n\r\n";
flag = ;
}
}
}