zoukankan      html  css  js  c++  java
  • 我罗斯方块最终篇

    这个作业属于哪个课程 2020年面向对象程序设计
    这个作业要求在哪里 我罗斯方块最终篇
    这个作业的目标 收尾工作
    小组成员 031902642谢敬琪 031902643 赵威威 031902635陈诗昀
    仓库 https://github.com/XINJIUXJ/block

    首先我们并没有完成双人版的设计,改动了两次,第一版只有一边能玩(相当于单人版了),第二版不知道为什么方块在游戏地图中显示不出来

    1.截图展示

    第一版
    第二版

    2.代码要点

    怎么说呢,有尝试过写类,最终还是决定写函数来实现...

    初始化窗口

    void initEnvironment()
    {
    	// 窗口设置
    	initgraph(1200, 540);
    	HWND hwnd = GetHWnd();
    	SetWindowText(hwnd, L"我罗斯方块");
    	SetWindowPos(hwnd, HWND_TOP, 700, 20, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
    
    	// 绘图模式设置
    	setbkmode(TRANSPARENT);
    
    	// 随机数种子
    	srand(time(NULL));
    }
    

    划分游戏区域

    void drawGameBG()
    {
    	// 划分区域(游戏区域、计分区域)
    	// 方块尺寸——36 * 36(单位:像素)
    	// 游戏尺寸——10 * 15(单位:方块)
    	// 下一个方块显示区域——4 * 4(单位:方块)
    
    	COLORREF tmp = getlinecolor();
    	for (int i = 0; i < 541; ++i)
    	{
    		setlinecolor(RGB(255, 179, 166));
    		line(0, 540 - i, 600, 540 - i);
    	}
    	for (int i = 0; i < 541; ++i)
    	{
    		setlinecolor(RGB(143, 188, 220 - i / 15));
    		line(601, i, 1200, i);
    	}
    	setlinecolor(tmp);
    }
    

    游戏界面的字及其他

    void drawSide()
    {
    	tmp_line_color = getlinecolor();
    	getlinestyle(&tmp_line_style);
    	tmp_text_color = getlinecolor();
    	gettextstyle(&tmp_text_style);
    
    	settextcolor(RGB(65, 105, 225));      	settextcolor(RGB(65, 105, 225));
    	settextstyle(20, 0, L"黑体");           	settextstyle(20, 0, L"黑体");
    	outtextxy(360 + 48, 300, L"左移:A");       outtextxy(960 + 48, 300, L"左移:←");
    	outtextxy(360 + 48, 330, L"右移:D");	    outtextxy(960 + 48, 330, L"右移:→");
    	outtextxy(360 + 48, 360, L"变形:W");   	outtextxy(960 + 48, 360, L"变形:↑");
    	outtextxy(360 + 48, 390, L"下落:S");       outtextxy(960 + 48, 390, L"下落:↓");
    
    	setlinecolor(WHITE);
    	rectangle(360 + 48, 36, 600 - 48, 36 + 144);
    	drawSquareNext();
    	setlinecolor(0x7FFFAA);
    	rectangle(360 + 48, 36, 600 - 48, 36 + 144);
    
    	setlinecolor(WHITE);
    	rectangle(960 + 48, 36, 1200 - 48, 36 + 144);
    	drawSquareNext();
    	setlinecolor(0x7FFFAA);
    	rectangle(960 + 48, 36, 1200 - 48, 36 + 144);
    
    	swprintf(score_tips, 29, L"得分:%d", score * 100);   swprintf(score_tips1, 29, L"得分:%d", score1 * 100);
    	outtextxy(360 + 48, 200, score_tips);               outtextxy(960 + 48, 200, score_tips1);
    
    	setlinecolor(tmp_line_color);
    	setlinestyle(&tmp_line_style);
    	settextcolor(tmp_text_color);
    	settextstyle(&tmp_text_style);
    }
    

    画方块

    void drawItem(int x, int y, COLORREF c)
    {
    	// 方块设计
    	// 实际尺寸:32 * 32(单位:像素)
    	// 边框颜色:白色
    	// 圆角半径:4(单位:像素)
    	// 内部间距:2(单位:像素)
    	tmp_fill_color = getfillcolor();
    
    	const int r = 6;
    	const int p = 2;
    
    	int up_l_x = x + p + r;
    	int up_r_x = x + 36 - p - r;
    	int up___y = y + p;
    
    	int down_l_x = x + p + r;
    	int down_r_x = x + 36 - p - r;
    	int down___y = y + 36 - p;
    
    	int left_u_y = y + p + r;
    	int left_d_y = y + 36 - p - r;
    	int left___x = x + p;
    
    	int right_u_y = y + p + r;
    	int right_d_y = y + 36 - p - r;
    	int right___x = x + 36 - p;
    
    	line(up_l_x, up___y, up_r_x, up___y);
    	line(down_l_x, down___y, down_r_x, down___y);
    	line(left___x, left_u_y, left___x, left_d_y);
    	line(right___x, right_u_y, right___x, right_d_y);
    	arc(x + p, y + p, x + p + 2 * r, y + p + 2 * r, pi / 2, pi);
    	arc(x + 36 - p, y + p, x + 36 - p - 2 * r, y + p + 2 * r, 0, pi / 2);
    	arc(x + p, y + 36 - p, x + p + 2 * r, y + 36 - p - 2 * r, -pi, -pi / 2);
    	arc(x + 36 - p, y + 36 - p, x + 36 - p - 2 * r, y + 36 - p - 2 * r, -pi / 2, 0);
    
    	setfillcolor(c);
    	floodfill(x + p + r + 1, y + p + r + 1, WHITE);
    
    	setfillcolor(tmp_fill_color);
    }
    

    还有很多就不一一展示,请移步到仓库

    3.依旧存在的问题

    双人界面的方块无法显示,导致并不能玩这个游戏

    4.收获与心得

    其实在这个过程中有学到很多东西,学到了很多目前在课堂上或者书本上没有提到知识,我认为通过做我罗斯方块所收获的要比做题多得多。
    而且在开发的过程中,发现团队合作也很重要,刚开始我们分好工就很少交流了,于是在最后整合阶段发现太乱了不得不改变策略。后来3个人一起学习同一篇源码,一起交流,但是已经比较迟了。总的来说,这次也是个教训,相信以后会更有经验。

    爱学习是一个程序员的基本品德,多学多写,相信有一天我们会成为一名合格的程序员。

    高亮:这个游戏还是会继续填的

  • 相关阅读:
    yii 引入文件
    CodeForces 621C Wet Shark and Flowers
    面试题题解
    POJ 2251 Dungeon Master
    HDU 5935 Car(模拟)
    HDU 5938 Four Operations(暴力枚举)
    CodeForces 722C Destroying Array(并查集)
    HDU 5547 Sudoku(dfs)
    HDU 5583 Kingdom of Black and White(模拟)
    HDU 5512 Pagodas(等差数列)
  • 原文地址:https://www.cnblogs.com/XINJIUXJ/p/13121820.html
Copyright © 2011-2022 走看看