整天待在机房是不是,一直保持学术的态度就比较的难啊~

所以本蒟蒻就在学术之余学了些奇技淫巧,然后就写了一些奇奇怪怪的程序啊,比如让我们小组dalao们都颓得不亦乐乎的2048~~

当然,2048的实现还是非常简单的对不对,我的写法估计更麻烦,我相信会有更方便的方式实现。。。

当然了,OI界学习的信息组dalao们写的程序多半是Console Application啊,就一个黑洞洞的窗口,画个图只能是字符画,看上去会很无聊,缺少图形的界面,于是,本蒟蒻学习了一种奇妙的东西——easyx

当然了,这种有趣的东西机房弱爆了的DEV C++是不滋磁的啊,所以本蒟蒻又引进了一个非常强大的IDE啊,Visual Studio。。

这个东西非常的强大,当然平时写写Console的我等是体会不到它的高端的,每写一个程序还要建一个项目,就显得特别蠢~~

但是,真正建个什么颓废的项目的时候,VS的强大就体现了。。。

//我是不是扯淡太多了

终于,今天下午能愉快的放假回家了,就在这里贴一贴代码啊~

开发环境:vs2015Professional  语言:C/C++

//2048  源码
#pragma once #include
#include
#include
#include
#include
#include
#include
#include
#include const COLORREF bkcolor = 0xFFF070;
const COLORREF cmdcolor = 0xFFA080;
const COLORREF emptycolor = 0xE0F0FF;
const COLORREF scorecolor = 0xE0F0FF; const int wndWidth = 470;
const int wndHeight = 640;
const int PicWidth = 100; const int PicX[4] = { 20,130,240,350 };
const int PicY[4] = { 190,300,410,520 }; const int Point[11] = { 2,4,8,16,32,64,128,256,512,1024,2048 }; #define t_srand srand((unsigned)time(NULL))
#define my_rand ((rand()|rand()<<16)%1000000007) IMAGE image[12];
IMAGE number[10]; int board[4][4] = { {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0} }; BOOL play[4][4]; BOOL End = FALSE;
int total = 0;
int record = 0; const char* FILENAME = "Image\\010.bmp"; //Function.h
#pragma once #include "Preparation.h" void Game_Init();
void Load_Image();
int Get_Highest();
void Load_Highest();
void New_Number();
void Msg_React();
void Move_Up();
void Move_Down();
void Move_Left();
void Move_Right();
void Put_Number(int, BOOL); void Game_Init()
{
Load_Image();
record=Get_Highest(); initgraph(wndWidth, wndHeight);
setbkcolor(bkcolor);
cleardevice();
setfillcolor(cmdcolor);
fillrectangle(-1, -1, wndWidth + 1, 171);
setfillcolor(emptycolor);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
fillrectangle(PicX[i], PicY[j], PicX[i] + PicWidth, PicY[j] + PicWidth);
}
fillrectangle(wndWidth - 180, 40, wndWidth - 20, 80);
fillrectangle(wndWidth - 180, 90, wndWidth - 20, 130);
Put_Number(record, 1);
Put_Number(0, 0);
New_Number();
New_Number();
} void Load_Image() //A AA
{
loadimage(&image[1], _T("Image\\2.bmp"), PicWidth, PicWidth);
loadimage(&image[2], _T("Image\\4.bmp"), PicWidth, PicWidth);
loadimage(&image[3], _T("Image\\8.bmp"), PicWidth, PicWidth);
loadimage(&image[4], _T("Image\\16.bmp"), PicWidth, PicWidth);
loadimage(&image[5], _T("Image\\32.bmp"), PicWidth, PicWidth);
loadimage(&image[6], _T("Image\\64.bmp"), PicWidth, PicWidth);
loadimage(&image[7], _T("Image\\128.bmp"), PicWidth, PicWidth);
loadimage(&image[8], _T("Image\\256.bmp"), PicWidth, PicWidth);
loadimage(&image[9], _T("Image\\512.bmp"), PicWidth, PicWidth);
loadimage(&image[10], _T("Image\\1024.bmp"), PicWidth, PicWidth);
loadimage(&image[11], _T("Image\\2048.bmp"), PicWidth, PicWidth); loadimage(&number[0], _T("Image\\000.bmp"), 20, 40);
loadimage(&number[1], _T("Image\\001.bmp"), 20, 40);
loadimage(&number[2], _T("Image\\002.bmp"), 20, 40);
loadimage(&number[3], _T("Image\\003.bmp"), 20, 40);
loadimage(&number[4], _T("Image\\004.bmp"), 20, 40);
loadimage(&number[5], _T("Image\\005.bmp"), 20, 40);
loadimage(&number[6], _T("Image\\006.bmp"), 20, 40);
loadimage(&number[7], _T("Image\\007.bmp"), 20, 40);
loadimage(&number[8], _T("Image\\008.bmp"), 20, 40);
loadimage(&number[9], _T("Image\\009.bmp"), 20, 40);
} int Get_Highest()
{
using namespace std;
fstream gamefile;
int game_point;
gamefile.open(FILENAME, ios::in);
if (!gamefile)
{
gamefile.open(FILENAME, ios::out);
gamefile << 0;
return 0;
}
gamefile >> game_point;
if (game_point > 100000000 || game_point % 4)
return 0;
return game_point;
} void Load_Highest()
{
if (total < record)
return;
using namespace std;
fstream gamefile;
gamefile.open(FILENAME, ios::out);
gamefile << total;
record = total;
Put_Number(total, 1);
} void New_Number()
{ if (End) return;
t_srand;
int type = abs(my_rand) % 10;
int Number = 0;
int NumberX = 4, NumberY = 4; if (type < 7)
Number = 1;
else
Number = 2; do
{
NumberX = abs(my_rand) % 4;
NumberY = abs(my_rand) % 4;
type++;
} while (board[NumberX][NumberY]); board[NumberX][NumberY] = Number; BeginBatchDraw();
putimage(PicX[NumberY], PicY[NumberX], &image[Number]);
EndBatchDraw();
} void Msg_React()
{
if (End) return;
int k1 = _getch();
int k2 = 0;
switch (k1)
{
case 224:
k2 = _getch();
switch (k2)
{
case 72:
Move_Up();
break;
case 80:
Move_Down();
break;
case 75:
Move_Left();
break;
case 77:
Move_Right();
default:
break;
}
break;
case 87:
case 119:
Move_Up();
break;
case 83:
case 115:
Move_Down();
break;
case 65:
case 97:
Move_Left();
break;
case 68:
case 100:
Move_Right();
break;
default:
break;
}
Load_Highest();
} void Move_Up()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
play[i][j] = FALSE;
BOOL flag = FALSE;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (!board[i][j]) continue;
int find = i - 1;
int data = board[i][j];
while (find >= 0)
{
if (!board[find][j])
{
board[find][j] = board[find + 1][j];
board[find + 1][j] = 0;
flag = TRUE;
find--;
}
else if (board[find][j] == data && !play[find][j])
{
board[find][j] = data + 1;
total += Point[data];
board[find + 1][j] = 0;
play[find][j] = true;
flag = TRUE;
find--;
}
else find = -1;
}
}
}
BeginBatchDraw();
int Empty_Count = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (board[i][j])
{
putimage(PicX[j], PicY[i], &image[board[i][j]]);
}
else
{
fillrectangle(PicX[j], PicY[i], PicX[j] + PicWidth, PicY[i] + PicWidth);
Empty_Count++;
}
}
}
Put_Number(total, 0);
EndBatchDraw();
if (!Empty_Count)
{
End = TRUE;
return;
}
if (flag)
New_Number();
} void Move_Down()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
play[i][j] = FALSE;
BOOL flag = FALSE;
for (int i = 2; i >= 0; i--)
{
for (int j = 0; j < 4; j++)
{
if (!board[i][j]) continue;
int find = i + 1;
int data = board[i][j];
while (find <= 3)
{
if (!board[find][j])
{
board[find][j] = board[find - 1][j];
board[find - 1][j] = 0;
flag = TRUE;
find++;
}
else if (board[find][j] == data && !play[find][j])
{
board[find][j] = data + 1;
total += Point[data];
board[find - 1][j] = 0;
play[find][j] = true;
flag = TRUE;
find++;
}
else find = 4;
}
}
}
BeginBatchDraw();
int Empty_Count = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (board[i][j])
{
putimage(PicX[j], PicY[i], &image[board[i][j]]);
}
else
{
fillrectangle(PicX[j], PicY[i], PicX[j] + PicWidth, PicY[i] + PicWidth);
Empty_Count++;
}
}
}
Put_Number(total, 0);
EndBatchDraw();
if (!Empty_Count)
{
End = TRUE;
return;
}
if (flag)
New_Number();
} void Move_Left()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
play[i][j] = FALSE;
BOOL flag = FALSE;
for (int j = 1; j < 4; j++)
{
for (int i = 0; i < 4; i++)
{
if (!board[i][j]) continue;
int find = j - 1;
int data = board[i][j];
while (find >= 0)
{
if (!board[i][find])
{
board[i][find] = board[i][find + 1];
board[i][find + 1] = 0;
flag = TRUE;
find--;
}
else if (board[i][find] == data)
{
board[i][find] = data + 1;
total += Point[data];
board[i][find + 1] = 0;
play[i][find] = TRUE;
flag = TRUE;
find--;
}
else find = -1;
}
}
}
BeginBatchDraw();
int Empty_Count = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (board[i][j])
{
putimage(PicX[j], PicY[i], &image[board[i][j]]);
}
else
{
fillrectangle(PicX[j], PicY[i], PicX[j] + PicWidth, PicY[i] + PicWidth);
Empty_Count++;
}
}
}
Put_Number(total, 0);
EndBatchDraw();
if (!Empty_Count)
{
End = TRUE;
return;
}
if (flag)
New_Number();
} void Move_Right()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
play[i][j] = FALSE;
BOOL flag = FALSE;
for (int j = 2; j >= 0; j--)
{
for (int i = 0; i < 4; i++)
{
if (!board[i][j]) continue;
int find = j + 1;
int data = board[i][j];
while (find <= 3)
{
if (!board[i][find])
{
board[i][find] = board[i][find - 1];
board[i][find - 1] = 0;
flag = TRUE;
find++;
}
else if (board[i][find] == data && !play[i][find])
{
board[i][find] = data + 1;
total += Point[data];
board[i][find - 1] = 0;
play[i][find] = TRUE;
flag = TRUE;
find++;
}
else find = 4;
}
}
}
BeginBatchDraw();
int Empty_Count = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (board[i][j])
{
putimage(PicX[j], PicY[i], &image[board[i][j]]);
}
else
{
fillrectangle(PicX[j], PicY[i], PicX[j] + PicWidth, PicY[i] + PicWidth);
Empty_Count++;
}
}
}
Put_Number(total, 0);
EndBatchDraw();
if (!Empty_Count)
{
End = TRUE;
return;
}
if (flag)
New_Number();
} void Put_Number(int NUMBER,BOOL flag)
{
if (flag)
{
for (int i = 1; i <= 8; i++)
{
putimage(wndWidth - (20 + 20 * i), 40, &number[NUMBER % 10]);
NUMBER /= 10;
}
}
else
{
for (int i = 1; i <= 8; i++)
{
putimage(wndWidth - (20 + 20 * i), 90, &number[NUMBER % 10]);
NUMBER /= 10;
}
}
} //main.cpp
#include "Preparation.h"
#include "function.h" void main()
{
Game_Init();
while (!End)
{
Msg_React();
}
Sleep(500);
closegraph();
}

上面提到的图片??
其实你们可以自己找哦~~
上面是2048的每个数字~~下面的是显示高分的数字。。看你们的心情咯~~

【颓废篇】easyx--2048的更多相关文章

  1. 【颓废篇】Py:从零开始的poj自动提交

    之前学习了一些python的爬虫技术... 已经可以通过python来水blog的阅读量了 你知道的太多了, 然而你看我这个blog惨不忍睹的访问量, 有人吗? 有人吗? 今天突然又双叒叕心血来潮想写 ...

  2. 【颓废篇】人生苦短,我用python(一)

    谁渴望来一场华(ang)丽(zang)的python交易! 最近突然产生了系统学习python的想法. 其实自从上次luogu冬日绘板dalao们都在写脚本就有这种想法了. 最近被计算几何势力干翻的我 ...

  3. 【颓废篇】人生苦短, 我用python(二)

    当时产生学习python的欲望便是在看dalao们写脚本的时候… 虽然dalao们好像用的是js来着.. 不过现在好像很多爬虫也可以用python写啊… 所以学python没什么不妥. 而且csdn整 ...

  4. 【游戏】2048及各种变种大集合汇总【更新ing~新版Floppy2048 - 恒星聚变版 - 恶搞改数据】

    threes - 鼻祖 手机版:http://asherv.com/threes/ js版:http://threesjs.com/ 2048 - 原版 http://gabrielecirulli. ...

  5. 2048小游戏代码解析 C语言版

    2048小游戏,也算是风靡一时的益智游戏.其背后实现的逻辑比较简单,代码量不算多,而且趣味性强,适合作为有语言基础的童鞋来加强编程训练.本篇分析2048小游戏的C语言实现代码. 前言 游戏截图:  游 ...

  6. python学习笔记(四) 思考和准备

    一.zip的坑 zip()函数接收多个可迭代数列,将数列中的元素重新组合,在3.0中返回迭代器指向 数列首地址,在3.0以下版本返回List类型的列表数列.我用的是3.5版本python, 所以zip ...

  7. TGL站长关于常见问题的回复

    问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...

  8. cocos2d-x 3.2 之 2048 —— 第二篇

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  9. cocos2d-x 3.2 之 2048 —— 第五篇

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

随机推荐

  1. NX二次开发-UFUN创建镜像体UF_MODL_create_mirror_body

    NX11+VS2013 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建块 UF_FEATURE_SIGN ...

  2. NX二次开发-UFUN特征找体UF_MODL_ask_feat_body

    NX11+VS2013 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建块 UF_FEATURE_SIGN ...

  3. 5、 postman的鉴权

    什么是鉴权? 鉴权(authentication)是指验证用户是否拥有访问系统的权利.常用的有两种鉴权方式,一种是session鉴权,一种是jwt鉴权,相对而言,后者居多. 实例: 比如有一个添加角色 ...

  4. AT指令集之Call

    1.//unsolicited result code,URC表示BP->AP+ESIPCPI:<call_id>,<dir>,<sip_msg_type>, ...

  5. java中的反射机制和javaBean

    反射 反射:就是通过一个类加载进方法区时加载到栈内存中的Class字节码文件对这个类进行解剖 通过反射可以获取到一个类的构造方法,成员方法,成员变量 反射将一个类的各个部分映射成相应的类 反射获取构造 ...

  6. c++实现写一个函数,求2个整数的和,要求在函数体内不得使用+,-* /

    #include <iostream> using namespace std; int add(int x, int y) { return x+y; } int addmove(int ...

  7. python中字典排序

    一.Python的排序 1.reversed() 这个很好理解,reversed英文意思就是:adj. 颠倒的:相反的:(判决等)撤销的 print list(reversed(['dream','a ...

  8. 《转》python(7)列表

    转自 http://www.cnblogs.com/BeginMan/p/3153842.html 一.序列类型操作符 1.切片[]和[:] 2.成员关系操作符(in ,not in ) 1: s1 ...

  9. drools决策表的使用

    决策表我们在drools规则引擎初探里做了简单介绍,这里主要是介绍如何通过java代码来把这个excel文件和drools关联起来,如何使其达到我们想要的效果. 这里假设我们在resources目录下 ...

  10. Algo: maxSubArray vs. maxProduct

    这两个问题类似,都可利用动态规划思想求解. 一.最大连续子序列和 https://leetcode.com/problems/maximum-subarray/description/ https:/ ...