| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1110 人关注过本帖
标题:求助大神帮忙改错填充程序 ,交作业时间快截止了 题目在下面 用的easyx图形 ...
取消只看楼主 加入收藏
遗情处有诗章
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2017-3-10
结帖率:75%
收藏
 问题点数:0 回复次数:0 
求助大神帮忙改错填充程序 ,交作业时间快截止了 题目在下面 用的easyx图形库
程序代码:
// ConsoleApplication68.cpp : 定义控制台应用程序的入口点。
//


// ConsoleApplication65.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>
#include<cstdlib>
#include<iostream>
#include<ctime>
using namespace std;
#define DISTANCE 70

/*   2013 11 14
乌龟
快速爬行
50%
前进3m/s

滑倒
20%
后退6m/s

缓慢爬行
30%
前进1m/s
*/
enum { RUNNING, REACH };
IMAGE wugui, tuzi;
class animal
{
protected:
    int distance;//距离终点的距离
    int time;//耗费的总时间
    int state;//状态
public:
    virtual char* classname() { return ""; }
    virtual void draw(int x, int y, int w, int h) {}
    int getstate()const { return state; }
    int getDistance() { return distance; }
    bool reach()
    {
        if (distance <= 0)
        {
            distance = 0;
            state = REACH;
            return true;
        }
        cout << distance << "" << endl;
        return false;
    }
    void goForward(int s)
    {
        distance -= s;
        distance = distance > 0 ? distance : 0;
        time++;
    }
    void prepare(int s)
    {
        distance = s;
        time = 0;
        state = RUNNING;
    }
    int gettime()const
    {
        return time;
    }
    virtual void fastspeed() {}
    virtual void slide() {}
    virtual void slowSpeed() {}
    virtual void bigStep() {}
    virtual void sleep() {}
    virtual void bigSlide() {}
    virtual void smallSlide() {}
    virtual void smallStep() {}
    virtual ~animal() {}

};
class tortoise :public animal
{
private:
    const int FASTSPEED;//快速移动
    const int SLIDE;//滑倒
    const int SLOWSPEED;//慢速移动

public:
    virtual char* classname() { return "乌龟"; }
    tortoise(int fs, int s, int ss) :FASTSPEED(fs), SLIDE(s), SLOWSPEED(ss) {}
    void prepare(int s);
    void fastspeed() { goForward(FASTSPEED); }
    void slide() { goForward(SLIDE); }
    void slowSpeed() { goForward(SLOWSPEED); }
    virtual void draw(int x, int y, int w, int h)
    {
        putimage(x, y, x + w, y + h, &wugui, 0, 0, SRCCOPY);
    }

};
class rabbit :public animal {
private:
    const int BIGSTEP;//大步移动
    const int SLEEP; //
    const int BIGSLIDE;//慢速移动
    const int SMALLSLIDE;//小步滑倒
    const int SMALLSTEP;//小步前进

public:
    virtual void draw(int x, int y, int w, int h)
    {
        putimage(x, y, x + w, y + h, &tuzi, 0, 0, SRCCOPY);
    }
    virtual char* classname() { return "兔子"; }
    rabbit(int bst, int s, int bsl, int ssl, int sst);
    void bigStep() { goForward(BIGSTEP); }
    void sleep() { goForward(SLEEP); }
    void bigSlide() { goForward(BIGSLIDE); }
    void smallSlide() { goForward(SMALLSLIDE); }
    void smallStep() { goForward(SMALLSTEP); }
};
rabbit::rabbit(int bst, int s, int bsl, int ssl, int sst) :
    BIGSTEP(bst), SLEEP(s), BIGSLIDE(bsl), SMALLSLIDE(ssl), SMALLSTEP(sst)
{}

    class match {
        vcetor <player*>playerlist;
        int Second;
    public:
        int getsecond() { return Second; }
        void start();
        void nextSecond();
        void add(player* p);
        void show()const;
        void draw(int HMAEGIN, int VMARGIN, int W, int H);
        void clear(int HMAEGIN, int VMARGIN, int W, int H);
    };


    void match::show()const {
        for (size_t i = 0; i < playerlist.size(); i++)
            cout << i << "" << playerlist[i]->classname() << "" << playerlist[i]->gettime;
    }
    void match::add(player* p) { playerlist.push_back(p); }
    void match::start()
    {
        for (size_t i = 0; i < playerlist.size(); i++)
            playerlist[i]->prepare(DISTANCE);
        srand(int(::time(0)));
        Second = 0;
    }
    void match::draw(int HMARGIN, int VMARGIN, int W, int H)
    {
        int pw = 50;
        int ph = 50;
        for (size_t i = 0; i < playerlist.size(); i++)
        {
            playerlist[i]->draw(HMARGIN) + ((W - 2 * HMARGIN) / DISTANCE*(DISTANCE - playerlist[i]));
        }
    }
    void match::clear(int HMARGIN, int VMARGIN, int W, int H)
    {
        const int W = 50;
        const int h = 50;
        for (size_t i = 0; i < playerlist.size(); i++)
        {
            clearrectangle(HMARGIN) + ((W - 2 * HMARGIN) / DISTANCE*(DISTANCE - playerlist[i]));
        }
    }
    bool match::stop()
    {
        for (size_t i = 0; i < playerlist.size(); i++)
        {
            if (playerlist[i]->getstate != REACH)
                return false;
        }
        cout << "比赛已经结束" << endl;
        return true;
    }

    void match::nextSecond()
    {
        Second++;
        int n;
        clearrectangle(0, 0, 800, 400);
        for (size_t i = 0; i < playerlist.size(); i++)
        {
            player& p = *playerlist[i];
            if (p.reach())
                continue;
            n = rand();
            if (typeid(p)-typeid(tortoise)) {
                switch (n % 10)
                {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:p.fastSpeed(); cout << "乌龟快速跑动,前进3米" << endl;  break;
                case 5:
                case 6:p.slide(); cout << "乌龟滑倒,后退6米" << endl;  break;
                case 7:
                case 8:
                case 9:p.slowSpeed(); cout << "乌龟慢速跑动,前进1米" << endl; break;
                }
            }
            else
                switch (n % 10)
                {
                case 0:p.bigSlide(); cout << "兔子大步滑倒,后退12米" << endl;  break;
                case 1:
                case 2:p.sleep(); cout << "兔子睡觉,原地踏步" << endl;  break;
                case 3:
                case 4:p.bigStep(); cout << "兔子大步跳跃,前进9米" << endl;  break;
                case 5:
                case 6:
                case 7: p.smallStep(); cout << "兔子小步跳跃,前进1米" << endl; break;
                case 8:
                case 9:p.smallSlide(); cout << "兔子小步滑倒,后退2米" << endl; break;
                }
        }draw(100, 100, 800, 400);

    }
   



int main(void)
{
    rabbit r(9, 0, -12, -2, 1);
    tortoise t(3, -6, 1);
    rabbit r2(10, 0, -9, -3, 3);
    tortoise t2(4, -5, 2);
    loadimage(&wugui, _T("w.jpg"));
    loadimage(&tuzi, _T("t.jpg"));

    Resize(&wugui, 50, 50);
    Resize(&tuzi, 50, 50);
    match game;
    game.add(&r);
    game.add(&t2);
    game.add(&t2);
    cout << "按回车键开始龟兔赛跑,跑到总长度" << DISTANCE << endl;
    cin.get();
    initgraph(800, 400, SHOWCONSOLE);
    game.start();
    do {
        cout << "" << game.getsecond() << "" << endl;
        game.nextSecond();
        Sleep(300);
        cout << "***********************\n";
    } while (!game.stop);
    cout << "比赛结果:" << endl;
    game.show();
    system("pause");
    return 0;
}

1考虑以下动物比赛,请写一个程序,在字符界面上演示比赛结果。假设比赛跑道长度为70米,以秒为单位回合制,其中一个到达终点则游戏结束,判断出胜负

 

 

动物
 

运动类型
 

几率
 

效果

乌龟
 

快速爬行
 

50%
 

前进3m/s

 
 

滑倒
 

20%
 

后退6m/s

 
 

缓慢爬行
 

30%
 

前进1m/s

兔子
 

睡觉
 

20%
 

原地不动

 
 

大步跳
 

20%
 

前进9m/s

 
 

大步滑倒
 

10%
 

后退12m/s

 
 

小步跳
 

30%
 

前进1m/s

 
 

小步滑倒
 

20%
 

后退2m/s

 

srand((unsigned)time(0)); 参数为种子,一般取系统时间为种子

rand();获得一个随机数,若要为0-10之间的,则rand()%10

Sleep函数,参数为停留的毫秒数,包含头文件windows.h

 

设计一个乌龟类,设计一个兔子类,模拟他们之间的赛跑。可以用一个专门的类来管理他们的赛跑。

 
搜索更多相关主题的帖子: int virtual void cout case 
2017-12-24 14:23
快速回复:求助大神帮忙改错填充程序 ,交作业时间快截止了 题目在下面 用的easy ...
数据加载中...
 
   



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

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