游戏之 空中接球。。。。。

感想:
从最先学的球接触面使之反弹的简单小程序(额,,应该是几句代码),再到设计的一个小游戏(额,,其实也就是多了点操作的)。其目的在于两点。一是巩固原学过的东西且在借助游戏增加功能的同时学习引用新的东西,二是借助游戏的设计提升自己的设计性(,,虽然并没有牛逼的东西,,)但初学嘛,什么都会是最有用的,多多益善。。。

内容:
在最原始的让球能够在遇到边缘的时候能反弹会来的基础上,增加了一些具有操作功能的东西,如 ,,,,,移动,界面,加速,时间,,,,等等简单的东西。

代码:

public partial class Form1 : Form
    {
        int ox, oy;
        int a = 3;
        int step = 30;
        Random d = new Random();
        int i = 0 ;



        public Form1()
        {
            InitializeComponent();
            label2.Text = "■■■■■";
            button1.Text = "start";
            int[] array = { - 1,1 };
            oy = array[d.Next(2)];
            ox = array[d.Next(2)];
            textBox1.Visible = false;
            label1.Text = "ready";
            label3.Text = "now time:";
            label4.Text = "游戏说明\n   本游戏通过实现移动挡板来让黑点反弹而\n不掉下去,目标:看谁坚持更久时间,也\n可以改变速度增加挑战性.欢迎来挑战\n游戏操作说明\n   进入游戏请按w键,a,d分别控制\n左右移动方向。游戏默认为最慢的速度若\n要更改速度,请单击不同难度的按键或按\nz,x,c来实现简单,中等,困难的难\n度的增加。退出游戏按q键。";


        }


        private void Form1_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //以下注释为开挂软件。取消注释即可。哈哈哈
            //if (timer1.Enabled)
            //   timer1.Stop();
            //else
                timer1.Start();
                label4.Text = "";
                label2.Location = new Point(175, 234);

            timer2.Start();
            i = 0;



        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            //up
            if (oy == -1 &&
                pictureBox1.Location.Y <= 0)
                oy = 1;

            //right
            if ((pictureBox1.Location.X + pictureBox1.Width >= this.ClientRectangle.Width) && ox == 1)
                ox = -1;

            //left
            if (pictureBox1.Location.X <= 0 && ox == -1)
                ox = 1;

            //down
            if (oy == 1 &&
               (pictureBox1.Location.Y + pictureBox1.Size.Height + 10 >= label2.Location.Y) && 
               (pictureBox1.Location.X + 5 <= label2.Location.X + label2.Size.Width) &&
               (label2.Location.X <= pictureBox1.Location.X))
                oy = -1;

            //出界
            if (pictureBox1.Location.Y  >= label2.Location.Y)
            {
                pictureBox1.Location = new Point(150 , 10);
                timer1.Stop();
                timer2.Stop();
                MessageBox.Show("你输了,垃圾");

            }



            pictureBox1.Location = new Point(pictureBox1.Location.X + ox * a, pictureBox1.Location.Y + oy * a);
        }


        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //向左移动
            if (e.KeyChar == 'a')
                label2.Location = new Point(label2.Location.X - step, label2.Location.Y);

            //向右移动
            if (e.KeyChar == 'd')
                label2.Location = new Point(label2.Location.X + step, label2.Location.Y);

            //开始键
            if (e.KeyChar == 'w')
                button1_Click(null, null);

            //调试简单速度
            if (e.KeyChar == 'z')
                button3_Click(null, null);

            //调试中等速度
            if (e.KeyChar == 'x')
                button4_Click(null, null);

            //调试困难速度
            if (e.KeyChar == 'c')
                button5_Click(null, null);

            //退出游戏
            if (e.KeyChar == 'q')
                button6_Click(null, null);
        }


        private void button3_Click(object sender, EventArgs e)
        {
            a = 3;
            step = 30;
            int[] array = { -1, 1 };
            oy = array[d.Next(2)];
            ox = array[d.Next(2)];
        }


        private void button4_Click(object sender, EventArgs e)
        {
            a = 4;
            step = 40;
            int[] array = { -1, 1 };
            oy = array[d.Next(2)];
            ox = array[d.Next(2)];
        }


        private void button5_Click(object sender, EventArgs e)
        {
            a = 5;
            step = 50;
            int[] array = { -1, 1 };
            oy = array[d.Next(2)];
            ox = array[d.Next(2)];
        }


        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {


            i = i + 1;
            label1.Text = i.ToString();



        }


    }

效果图如下:
这里写图片描述

目的:
就这样咯。。。。。简单,益操作了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值