zoukankan      html  css  js  c++  java
  • 2019年春第四次课程设计实验报告

    2019年春第四次课程设计实验报告
    实验项目名称:
    双人游戏
    功能描述:
    由玩家操控飞机进行游戏并累计得分。
    项目结构模块介绍:
    1.全局变量
    int ball_x,ball_y; // 小球的坐标
    int ball_vx,ball_vy; // 小球的速度
    int radius; // 小球的半径
    int bar1_left,bar1_right,bar1_top,bar1_bottom; // 挡板1的上下左右位置坐标
    int bar2_left,bar2_right,bar2_top,bar2_bottom; // 挡板2的上下左右位置坐标
    int bar_height,bar_width; // 挡板的高度、宽度

    2.数据初始化
    void startup() // 数据初始化
    {
    ball_x = Width/2;
    ball_y = High/2;
    ball_vx = 1;
    ball_vy = 1;
    radius = 20;
    bar_width = Width/30;
    bar_height = High/2;
    bar1_left = Width * 1/20;
    bar1_top = High/4;
    bar1_right = bar1_left + bar_width;
    bar1_bottom = bar1_top + bar_height;
    bar2_left = Width * 18.5/20;
    bar2_top = High/4;
    bar2_right = bar2_left + bar_width;
    bar2_bottom = bar2_top + bar_height;
    initgraph(Width,High);
    BeginBatchDraw();
    }
    3.消除画面
    void clean() // 消除画面
    {
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillcircle(ball_x, ball_y, radius);
    fillcircle(ball_x, ball_y, radius);
    bar(bar1_left,bar1_top,bar1_right,bar1_bottom);
    bar(bar2_left,bar2_top,bar2_right,bar2_bottom);
    }

    4.显示画面
    void show() // 显示画面
    {
    setcolor(GREEN);
    setfillcolor(GREEN);
    fillcircle(ball_x, ball_y, radius); // 绘制绿圆
    setcolor(YELLOW);
    setfillcolor(YELLOW);
    bar(bar1_left,bar1_top,bar1_right,bar1_bottom); // 绘制黄色挡板
    bar(bar2_left,bar2_top,bar2_right,bar2_bottom);
    FlushBatchDraw();
    // 延时
    Sleep(3);
    }
    5.与用户输入无关的更新
    void updateWithoutInput() // 与用户输入无关的更新
    {
    // 挡板和小圆碰撞,小圆反弹
    if (ball_x+radius>=bar2_left && ball_y+radius>=bar2_top && ball_y+radius<=bar2_bottom)
    ball_vx = -ball_vx;
    else if (ball_x-radius<=bar1_right && ball_y+radius>=bar1_top && ball_y+radius<=bar1_bottom)
    ball_vx = -ball_vx;
    // 更新小圆坐标
    ball_x = ball_x + ball_vx;
    ball_y = ball_y + ball_vy;
    if ((ball_x<=radius)||(ball_x>=Width-radius))
    ball_vx = -ball_vx;
    if ((ball_y<=radius)||(ball_y>=High-radius))
    ball_vy = -ball_vy;
    }

    6.与用户输入有关的更新
    void updateWithInput() // 与用户输入有关的更新
    {
    int step = 1;
    if (GetAsyncKeyState(0x57) & 0x8000 ) // w
    bar1_top-=step;
    if ((GetAsyncKeyState(0x53) & 0x8000)) //s
    bar1_top+=step;
    if ((GetAsyncKeyState(VK_UP) & 0x8000)) // 上方向键
    bar2_top-=step;
    if ((GetAsyncKeyState(VK_DOWN) & 0x8000)) // 下方向键
    bar2_top+=step;
    bar1_bottom = bar1_top + bar_height;
    bar2_bottom = bar2_top + bar_height;
    }
    void gameover()
    {
    EndBatchDraw();
    closegraph();
    }

    代码托管连接
    https://gitee.com/wjx0229/difficult_team/blob/master/双人游戏.cpp
    实验总结:
    这周电脑出现了一些小故障导致git和easyx都卸载了,所以暂无截图。

  • 相关阅读:
    testNg vs junit 4.X @Test
    lombok+slf4j+logback SLF4J和Logback日志框架详解
    IntelliJ IDEA 当pom.xml更新时,自动加载pom.xml
    运算符重载具体解释
    设计模式之十八:桥接模式(Bridge)
    无限层级的组织机构
    实战Jquery(一)--username校验
    Android错误之--Error retrieving parent for item: No resource found that matches the given name &#39;Theme.A
    hibernate 缓存
    android --多线程下载
  • 原文地址:https://www.cnblogs.com/wjx0229/p/11058115.html
Copyright © 2011-2022 走看看