| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 456 人关注过本帖
标题:想写个赛跑的应有程序,但是就是调不通。
只看楼主 加入收藏
zybnrq
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-9-25
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
想写个赛跑的应有程序,但是就是调不通。
Day of race.rar (115.61 KB)
请高手帮我看看。
搜索更多相关主题的帖子: 赛跑 
2010-10-15 11:00
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:10 
尝试修改成如下:
----------------------------
程序代码:
/*Dogrun.*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Day_of_race
{
    public class Dogrun
    {
        public int StartPosition;
        public int RacetrackLength;
        public PictureBox MypictureBox;
        public int Location = 0;
        public Random Randomizer;

        public bool RUN()
        {
            Point startLocation = MypictureBox.Location;

            Random Randomizer = new Random();
            Location = Randomizer.Next(0, 10);              // 每次移动的像素大小
            RacetrackLength = 800;                          // 像素总大小

            for (int i = StartPosition; i <= RacetrackLength; i += Location)
            {
                MypictureBox.Location = new Point(MypictureBox.Location.X + i, MypictureBox.Location.Y/* + i*/);

            }
            if (MypictureBox.Location.X >= RacetrackLength)
            {
                MessageBox.Show(MypictureBox.Name + "end the race");
                MypictureBox.Location = startLocation;
            }
            return true;
        }

        /*
         * 添加构造函数,实例化所有对象
         */
        public Dogrun(PictureBox pb)
        {
            if (pb != null)
            {
                this.MypictureBox = pb;
            }
            else
            {
                throw new System.ArgumentNullException( "PictureBox");
            }
        }
    }
}
/*From*/
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Day_of_race;

namespace Day_of_race
{
    public partial class Form1 : Form
    {
        Dogrun Dog;
        public Form1()
        {
           
            InitializeComponent();
            Dog = new Dogrun( this.pictureBox2);
            Dog.StartPosition = pictureBox2.Location.X;
            Dog.RacetrackLength = pictureBox1.Location.Y;

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Dog.RUN();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}



2010-10-15 13:18
一氧化碳
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:132
专家分:335
注 册:2007-8-13
收藏
得分:10 
你报的是什么错?

2010-10-15 13:34
一氧化碳
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:132
专家分:335
注 册:2007-8-13
收藏
得分:0 
我晕,你的代码是抄来的吧!
里面的参数都没设置,怎么调通?

    public class Dogrun
    {
        public int StartPosition;
        public int RacetrackLength;
        public PictureBox MypictureBox;
        public int Location = 0;
        public Random Randomizer;
        public bool RUN()
        {
            Random Randomizer=new Random();
            Location=Randomizer.Next(0,10);
            RacetrackLength = 75;

            for (int i = StartPosition; i <= 524; i += Location)
            {
                MypictureBox.Location = new Point(StartPosition + i, RacetrackLength);
                if (MypictureBox.Location.X >= 524)
                {
                    MessageBox.Show(MypictureBox.Name + "end the race");
                    return true;
                }
            }

            return true;
            }
        }

-------------------------
namespace Day_of_race
{
    public partial class Form1 : Form
    {
        Dogrun Dog;
        public Form1()
        {
            
            InitializeComponent();
            Dog = new Dogrun();
            Dog.StartPosition = pictureBox2.Location.X;
            Dog.RacetrackLength = pictureBox1.Location.Y;
            Dog.MypictureBox = pictureBox2;

        }
。。。。。

2010-10-15 14:13
快速回复:想写个赛跑的应有程序,但是就是调不通。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039807 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved