/*--------------------------------------------------------- 项目名: 模拟笔记本电脑 功能说明: 模拟电脑的基本功能,实现键盘的输入与键盘的控制,模拟开机,输密,打开软件,关闭电脑 程序结构: |变量区:(数组+变量) |子函数区: ·系统自带函数:光标隐藏+gotoxy ·汉诺塔执行相关函数 ·主程序init函数 ·主程序界面加载函数: ·开机画面 ·关机画面 ·蓝屏画面 ·更多信息画面 ·电脑系统配置画面 ·打砖块执行相关函数 ·主程序功能函数: ·处理返回的字符型按键函数 ·处理返回的功能型按键函数 |主函数: ·主循环 指路区: 1.自制地图插入 前往my_map[][]数组 大概300多行处修改; 2.打砖块抛物线算法解析 前往autochange()函数 1000多行处 ---------------------------------------------------------*/ #include //用于getch() #include #include #include #include #define pi 3.14 const double g = 10; //标准数越模糊,轨迹越连贯。 //初始页面 char start[20][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /~/~/ /"}, {" \\ /~/~/ /"}, {" \\ 计算机大作业 ~ ~ __ /"}, {" \\ \\ /\\ / - _ _| _ _ _ /_ /"}, {" \\ \\/ \\/ | | | |_| |_| \\/\\/ __/ /"}, {" \\ /"}, {" \\ _____________________ /"}, {" \\ │ │ /"}, {" \\ └────────────────────┘ /"}, {" \\ /"}, {" \\ Copyright Θ Microsoft Corporation Microsoft /"}, {" \\ __________________________________________________________________________________________/"}}; //输入页码的页面 char password[20][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ /"}, {" \\ ------------------------------------------------------------------------------------------------------------------ /"}, {" \\ /"}, {" \\ | /"}, {" \\ | /"}, {" \\ | ┌───────────────────────────────────────────── /"}, {" \\ /~/~/ | │┌─────┐ Administrator /"}, {" \\ /~/~/ __XP | ││ [] │ 输入密码 /"}, {" \\ \\ /\\ / - _ _| _ ~ ~ /_ | │└─────┘ 【| 】ck[→] /"}, {" \\ \\/ \\/ | | | |_| |_| \\/\\/ __/ | └─────────────────────────────────────── /"}, {" \\ | /"}, {" \\ 要开始,请单击您的用户名 | /"}, {" \\ | /"}, {" \\ /"}, {" \\ ---------------------------------------------------------------------------------------- /"}, {" \\ __________________________________________________________________________________________/"}}; char desktop[20][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ ───── ───── ───── ┌────┐ ┌────┐ /"}, {" \\ \\ \\ \\ \\ \\ \\ │ │ │ing │ /"}, {" \\ ───── ───── ───── └────┘ └────┘ /"}, {" \\ 汉诺塔 打砖块 我的电脑 相关 待开发 /"}, {" \\ ───── /"}, {" \\ \\ \\ /"}, {" \\ ───── __ --------------- __ __ /"}, {" \\ IE浏览器__-- --- __ -------_ -------_------____ /"}, {" \\ ____ __--__ -- __ -------_ --- - __ --- __ --------------______ /"}, {" \\__ -------_--__ ------- __ ---------- __ ------ __ ------ __ --- __ ---------____ /"}, {" \\ -------_---__ ------- _---- __ -------_ ---_ -------_ -_ ----------_ -_---_ -_ ------_ -_ /"}, {" \\--__ -- __ ----- __ ------ __ -------_ --- ---- __ -------_ -_ ---------_ -_ ------_ -_ ------ /"}, {" \\ -_--__ ------- _---- __ -------_ ------- __ -------_ -- __ -------_ -_ --------__---_ -_ ------/"}, {" \\ _____________________________________________________________________________________________ /"}, {" \\ 开始 \\ qq2010 | | 12:00 /"}, {" \\ __________________________________________________________________________________________/"}}; char game_hnt[20][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ └───────────────────────────────────────────────────────────────────────────────────────────┘ /"}, {" \\ _____________________________________________________________________________________________ /"}, {" \\ 开始 \\ qq2010 | 汉诺塔自动演示小游戏 | | 12:08 /"}, {" \\ __________________________________________________________________________________________/"}}; char MyComputer[20][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ /"}, {" \\ \\系统属性| |?| X / /"}, {" \\ \\= 常规 =|计算机名|硬件|高级|自动更新|远程| / /"}, {" \\ \\ 系统: / /"}, {" \\ \\ +------------+ Microsoft Windows XP/ /"}, {" \\ \\ | /~/~/ | Professional / /"}, {" \\ \\ | /~/~/ | 版本 2.3.3.3 / /"}, {" \\ \\ +------------+ / /"}, {" \\ \\ ---- 绝伦 && 404name / /"}, {" \\ \\ 制造商和技术支持商 : Pentium(R) Core CPU / /"}, {" \\ \\ M i c r o s o f t 2.52GHz, 1.99GB内存 / /"}, {" \\ \\ 技术支持信息(S) / /"}, {" \\ └───────────────────────────────────────────────────────────────────────────────────────────┘ /"}, {" \\ _____________________________________________________________________________________________ /"}, {" \\ 开始 \\ qq2010 | 系统属性 | | 12:08 /"}, {" \\ __________________________________________________________________________________________/"}}; char thinking[30][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ /"}, {" \\ 这里是相关:(最后更新2020.2.11) /"}, {" \\ /"}, {" \\ 寒假太颓废了,没劲学习,游戏玩腻,然后开始发呆。安静下来时才有灵感 ,看着笔记本,就想着我也编一个电脑系统吧 /"}, {" \\ /"}, {" \\ 就想把大一上学到的一些东西总着来练练手。。然后发现写电脑系统就是痴人说梦了,我还是写个模拟计算机吧。 /"}, {" \\ /"}, {" \\ 对着自己笔记本的键盘一个一个的还原,然后思考如何体现屏幕,如何移动键盘,如何读取键盘把信息传给我的 /"}, {" \\ /"}, {" \\ 虚拟电脑,如何模拟开机实现基本功能 ,一口气写完真心爽,最后想做互动游戏的,但这斜着的屏幕,emmm /"}, {" \\ /"}, {" \\ 所以最后电脑只能运行汉诺塔,其他功能实现也简单,但还是把时间放在我突然又燃起的学习小火苗上吧/"}, {" \\ └───────────────────────────────────────────────────────────────────────────────────────────┘ /"}, {" \\ _____________________________________________________________________________________________ /"}, {" \\ 开始 \\ qq2010 | 感想.txt | | 12:15 /"}, {" \\ __________________________________________________________________________________________/"}}; char ending[30][500] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ An unknown error has occurred with Internet explorer due to low computer configuration /"}, {" \\ /"}, {" \\ If this is the first time you've seen this error on screen. /"}, {" \\ Take the computer apart. If this screen appears again,follow thes steps: /"}, {" \\ /"}, {" \\ check to be sure you have enough money. If you have your phone with you, open taobao and choose the most /"}, {" \\ expensive laptop, which has the best components to use. /"}, {" \\ / "}, {" \\ Check the hardware on your new computer, remove the memory and graphics CARDS. and point them at /"}, {" \\ the old computer. If you want to turn on safe mode, buy more new laptops to prevent errors. /"}, {" \\ Once installed, your old computer might be able to run Internet explorer. That's cool. /"}, {" \\ /"}, {" \\ Technical information: /"}, {" \\ ****** STOP 0x0000008E (0xc0000005,0xBF856CA8,0xB0F07A40,0x00000000) /"}, {" \\ ****** win32k.sys - Address BF853CA8 base at BF800000, DateStamp 5900ef5f /"}, {" \\ __________________________________________________________________________________________/"}}; char map[1000][1000] = { {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ /"}, {" \\ __________________________________________________________________________________________/"}, {" ┌──────────────────────────────────────────────────────────────────────────────────────────┐"}, {" │ ──── │"}, {" │──────────────────────────────────────────────────────────────────────────────────────────│"}, {" │┌─────┐ ┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┐ │"}, {" ││ Esc │ │ F1│ F2│ F3│ F4││ F5│ F6│ F7│ F8││ F9│F10│F11│F12││Prt│Scr│Pau│ ┌┐ ┌┐ ┌┐ ┌┐ │"}, {" │└─────┘ └───┴───┴───┴───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┴───┴───┘ └┘ └┘ └┘ └┘ │"}, {" │┌────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┐┌───┬───┬───┐┌───┬───┬───┬───┐│"}, {" ││ `~ │ 1!│ 2@│ 3#│ 4$│ 5%│ 6^│ 7&│ 8*│ 9(│ 0)│ -─│ =+│ ←--││Ins│Hom│Pgu││Num│ / │ * │ - ││"}, {" │├────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬────┤├───┼───┼───┤├───┼───┼───┼───┤│"}, {" ││ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ [{│ ]}│ \\| ││Del│End│Pgd││ 7 │ 8 │ 9 │ ││"}, {" │├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴────┤└───┴───┴───┘├───┼───┼───┤ + ││"}, {" ││ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │ ;:│ \'\"│ Enter │ │ 4 │ 5 │ 6 │ ││"}, {" │├──────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴───────┤ ┌───┐ ├───┼───┼───┼───┤│"}, {" ││ Shift │ Z │ X │ C │ V │ B │ N │ M │ ,<│ .>│ /?│ Shift │ │ ↑│ │ 1 │ 2 │ 3 │ │││"}, {" │├────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴───┴──┬┴───╪───┬──────┤┌───┼───┼───┐├───┴───┼───┤ │││"}, {" ││ Ctr│ win│ Alt│ ──── │ Alt│ Fn│ Ctrl ││← │ ↓│ →││ 0ins │.de│←┘││"}, {" │└────┴────┴────┴───────────────────────────┴────┴───┴──────┘└───┴───┴───┘└───────┴───┴───┘│"}, {" │ ┌───────────────────────────────┐ │"}, {" │ │ │ │"}, {" │ │ │ │"}, {" │ │───────────────┬───────────────│ │"}, {" │ └───────────────┴───────────────┘ │"}, {" └──────────────────────────────────────────────────────────────────────────────────────────┘"}}; //功能数组 int keyboard[20][30] = { //把键盘看成一个地图让move函数在上面移动返回的数值对应下面的 board_place[120][5]是对应按键的全部信息 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 104, 104, 104, 104}, {0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37}, {0, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58}, {0, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 71, 0, 0, 0, 72, 73, 74, 58}, {0, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 86, 86, 0, 87, 0, 88, 89, 90, 91}, {0, 92, 93, 94, 95, 95, 95, 95, 95, 95, 95, 96, 97, 98, 98, 99, 100, 101, 102, 102, 103, 91}, }; int next[9][2] = {{0}, {0}, {0}, {0}, {0}, {-1, 0}, {0, -1}, {1, 0}, {0, 1}}; //给键盘传给虚拟键盘的键盘控制虚拟电脑用 int computer_map[3][8] = {{0, 0, 0, 0, 0}, {0, 1, 2, 3, 4}, {0, 5, 0, 0, 0}}; //对应的移动操作记录 int computer_map_place[6][2] = {{0}, {2, 9}, {2, 19}, {2, 29}, {2, 40}, {6, 12}}; int cx, cy, tcx, tcy, lcx, lcy; int board_place[120][5] = { //这是按键的信息 下标依次对应 -返回值 -按下shift下的返回值2 -键盘字符长度 -字符坐标x -y {0, 0, 0, 0, 0}, //第一项如果是字符那么那就是返回字符 如果是数字1-9那么就是功能按键功能对应如下 {1, 1, 3, 21, 19}, //1-10 {0, 0, 2, 21, 28}, //1 ~ 返回 2 ~删除 3确认 4shift 5上 6左 7下 8又 9开机 {0, 0, 2, 21, 32}, {0, 0, 2, 21, 36}, {0, 0, 2, 21, 40}, {0, 0, 2, 21, 45}, {0, 0, 2, 21, 49}, {0, 0, 2, 21, 53}, {0, 0, 2, 21, 57}, {0, 0, 2, 21, 62}, {0, 0, 3, 21, 65}, // 11 {0, 0, 3, 21, 69}, {0, 0, 3, 21, 73}, {0, 0, 3, 21, 78}, {0, 0, 3, 21, 82}, {0, 0, 3, 21, 86}, {'`', '~', 2, 24, 19}, {'1', '!', 2, 24, 24}, {'2', '@', 2, 24, 28}, {'3', '#', 2, 24, 32}, {'4', '$', 2, 24, 36}, // 21 {'5', '%', 2, 24, 40}, {'6', '^', 2, 24, 44}, {'7', '&', 2, 24, 48}, {'8', '*', 2, 24, 52}, {'9', '(', 2, 24, 56}, {'0', ')', 2, 24, 60}, {'-', '_', 2, 24, 64}, {'=', '+', 2, 24, 68}, {2, 2, 4, 24, 72}, {0, 0, 3, 24, 78}, // 31 {0, 0, 3, 24, 82}, {0, 0, 3, 24, 86}, {0, 0, 3, 24, 91}, {'/', '/', 1, 24, 96}, {'*', '*', 1, 24, 100}, {'-', '-', 1, 24, 104}, {0, 0, 3, 26, 19}, {'q', 'Q', 1, 26, 25}, {'w', 'W', 1, 26, 29}, {'e', 'E', 1, 26, 33}, // 41 {'r', 'R', 1, 26, 37}, {'t', 'T', 1, 26, 41}, {'y', 'Y', 1, 26, 45}, {'u', 'U', 1, 26, 49}, {'i', 'I', 1, 26, 53}, {'o', 'O', 1, 26, 57}, {'p', 'P', 1, 26, 61}, {'[', '{', 2, 26, 65}, {']', '}', 2, 26, 69}, {'\\', '|', 2, 26, 73}, // 51 {0, 0, 3, 26, 78}, {0, 0, 3, 26, 82}, {0, 0, 3, 26, 86}, {'7', '7', 1, 26, 92}, {'8', '8', 1, 26, 96}, {'9', '9', 1, 26, 100}, {'+', '+', 1, 27, 104}, {4, 4, 4, 28, 19}, {'a', 'A', 1, 28, 26}, {'s', 'S', 1, 28, 30}, // 61 {'d', 'D', 1, 28, 34}, {'f', 'F', 1, 28, 38}, {'g', 'G', 1, 28, 42}, {'h', 'H', 1, 28, 46}, {'j', 'J', 1, 28, 50}, {'k', 'K', 1, 28, 54}, {'l', 'L', 1, 28, 58}, {';', ':', 2, 28, 62}, {'\'', '\"', 2, 28, 66}, {3, 3, 5, 28, 70}, // 71 {'4', '4', 1, 28, 92}, {'5', '5', 1, 28, 96}, {'6', '6', 1, 28, 100}, {4, 4, 5, 30, 19}, {'z', 'Z', 1, 30, 27}, {'x', 'X', 1, 30, 31}, {'c', 'C', 1, 30, 35}, {'v', 'V', 1, 30, 39}, {'b', 'B', 1, 30, 43}, {'n', 'N', 1, 30, 47}, // 81 {'m', 'M', 1, 30, 51}, {',', '<', 2, 30, 55}, {'.', '>', 2, 30, 59}, {'/', '?', 2, 30, 63}, {4, 4, 5, 30, 69}, {5, 5, 2, 30, 83}, {'1', '1', 1, 30, 92}, {'2', '2', 1, 30, 96}, {'3', '3', 1, 30, 100}, {3, 3, 3, 32, 103}, // 91 {0, 0, 3, 32, 19}, {0, 0, 3, 32, 24}, {0, 0, 3, 32, 29}, {' ', ' ', 4, 32, 45}, {0, 0, 3, 32, 62}, {0, 0, 2, 32, 67}, {0, 0, 4, 32, 71}, {6, 6, 2, 32, 78}, {7, 7, 2, 32, 83}, {8, 8, 2, 32, 87}, // 101 {'0', '0', 4, 32, 93}, {'.', '.', 4, 32, 99}, {9, 9, 4, 18, 99}}; // 程序功能变量 int flag, function, if_shift, if_start, if_input_password, if_into_desktop, if_game, qpz; //0表示输入无效,1表示是输入电脑键 2表示是功能键 char letter; int x, y, tx, ty, num, lx, ly; char temp[6] = {"====="}; char put_in_computer[20]; char password_0[20] = {"WHJY"}; // 密码 int put_in_num, if_input, input_x, input_y, input_max; // 汉诺塔游戏变量 int mid_x, mid_y; int len, width, left, mid, right, time; int ttx, tty; char game_map[80][1000]; int game_next[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; //上0下1左2右3; int turn[2][3] = {{0, 3, 1}, //a -> b b -> c a -> c 上右下 {0, 2, 1}}; //b -> a c -> b c -> a 上左下 //实现自动移动的路线储存 //打砖块游戏变量 char map2[1000][1000]; char End[20][50] = { {" ## ## ## "}, {" ## ######### ###############"}, {" ## ######### ###############"}, {"## ## ## ## "}, {"###### ####### ############ "}, {" ## ####### ############ "}, {" ## ## ## ## "}, {"###### ####### ############ "}, {"###### ####### ##### "}, {" ## ## ## #### "}, {" ### ## ## ## ## ## "}, {"###### ####### ### ## ### "}, {"### ####### ## ## ## "}, {" ## ## ## "}, {" 按 任 意 键 继 续 "}, }; //----------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------- //此处是人工地图接口(开启请前往main函数里面设置下面0为1并且自己改变图案) int if_my_map; char my_map[50][500] = {{"#############################################################################################################################"}, {"## life: | | | ##"}, {"### ###"}, {"#### ####"}, {"##### #####"}, {"###### OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOO######"}, {"####### OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOO#######"}, {"######## ########"}, {"######### #########"}, {"########## ##########"}, {"OOOOOOOOOOOOOOOOOOOOOOOOO ########################## OOOOOOOOOOOOOOOOOOOOOOOOOO"}, {"OOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOO"}, {"############# #############"}, {"############## ##############"}, {"############### ###############"}, {"################ ########### ################"}, {"#############################################################################################################################"}}; //修改规则: //显然电脑屏幕外是不能动的只能修改里面梯形 // 墙~# 砖块~0 空气~' ' //小球在倒数第七行 23~27列之间随机生成,不能占位 //左下角是木板生成地,左上是生命 不可改(要改需调参数) //----------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------------------------------- //全局变量区,在init里面改变 char wall, food, air, brick; int width2, length2; double X2, Y2, x2, y2, Vx, Vy, t2, V; //默认向下向右为正 int old_x2, old_y2, head2, tail2, max2, step2, if_miss, food_num, goal, color, add_x, add_y, cnt; int if_load_snake_mod, debug, life; //debug模式调成1手动开启 int temp_x2, temp_y2, menu_x, menu_y, left2, right2; //临时坐标 double C[8] = {0, 10, 30, 55, 90}; //初始斜抛的角度,自右向上转角(目前已调整好最好的角度) struct Step //轨迹 { int x2; int y2; } s[1000]; void HideCursor() //光标隐藏 { CONSOLE_CURSOR_INFO cursor_info = {1, 0}; //后边的0代表光标不可见 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } void gotoxy(int x, int y) //坐标函数 { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(handle, pos); } void init_game(int n) { //初始化汉诺塔 int i, j; mid_x = 7, mid_y = 60; ttx = 10, tty = 10; time = 50 / n; left = 1, mid = 2 * (n + 1), right = mid + 2 * n + 1; len = 3 * (2 * n + 1); width = n + 1; ttx = mid_x - width / 2; tty = mid_y - len / 2; for (i = 0; i <= width; i++) { for (j = 0, num = i; j <= len; j++) { if (i == 0 || j == 0 || i == width || j == len) game_map[i][j] = ' '; if ((i > 1 && i < width) && (j == mid - 1 || j == right - 1)) game_map[i][j] = '|'; if (num && (i >= 1 && i <= width - 1) && j % 2 != 0 && j < mid) { game_map[i][j] = -95; game_map[i][j + 1] = -10; //打印 ■ ■占2个字节可以拆开来 num--; } } } //容易出现东西卡顿 for (i = 0; i <= width; i++) { gotoxy(tty, ttx + i); for (j = 0; j <= len; j++) printf("%c", game_map[i][j]); printf("\n"); } } void play(int x, int y) { //显示汉诺塔移动轨迹 int turn_0, n = 0, i, j, k, tx, ty, flag = 0; if ((x == mid && y == right) || (x == left && y == mid) || (x == left && y == right)) turn_0 = 0; //往右 else if ((x == mid && y == left) || (x == right && y == left) || (x == right && y == mid)) turn_0 = 1; //往左 for (i = 1, j = y; i <= width; i++) { //目的地 if (game_map[i][j] != 0) { tx = i - 1; ty = j; break; } } for (i = 1, j = x; i <= width; i++) { //出发点 if (game_map[i][j] != 0) { break; } } while (1) { while ((i != 1 || j != x) && (i != 1 || j != y) && (i != tx || j != ty)) { if (turn_0 == 0) for (k = mid - 3; k >= 0; k--) { game_map[i + game_next[turn[turn_0][n]][0]][j + game_next[turn[turn_0][n]][1] + k] = game_map[i][j + k]; game_map[i][j + k] = 0; } else for (k = 0; k < mid - 2; k++) { game_map[i + game_next[turn[turn_0][n]][0]][j + game_next[turn[turn_0][n]][1] + k] = game_map[i][j + k]; game_map[i][j + k] = 0; } gotoxy(j + tty, i + ttx); Sleep(time); for (k = 0; k < mid - 2; k++) { printf(" "); } i = i + game_next[turn[turn_0][n]][0]; j = j + game_next[turn[turn_0][n]][1]; gotoxy(j + tty, i + ttx); Sleep(time); for (k = 0; k < mid - 2; k++) { printf("%c", game_map[i][j + k]); } } n++; //改变方向; if (i == tx && j == ty) return; if (turn_0 == 0) for (k = mid - 3; k >= 0; k--) { game_map[i + game_next[turn[turn_0][n]][0]][j + game_next[turn[turn_0][n]][1] + k] = game_map[i][j + k]; game_map[i][j + k] = 0; } else for (k = 0; k < mid - 2; k++) { game_map[i + game_next[turn[turn_0][n]][0]][j + game_next[turn[turn_0][n]][1] + k] = game_map[i][j + k]; game_map[i][j + k] = 0; } gotoxy(j + tty, i + ttx); for (k = 0; k < mid - 2; k++) { printf(" "); } Sleep(time); i = i + game_next[turn[turn_0][n]][0]; j = j + game_next[turn[turn_0][n]][1]; gotoxy(j + tty, i + ttx); for (k = 0; k < mid - 2; k++) printf("%c", game_map[i][j + k]); Sleep(time); } } void move_hnt(int a, int b, int c, char aa, char bb, char cc, int n) { //正常的汉诺塔递归程序 if (n == 1) { //printf("from %c to %c",aa,cc); play(a, c); return; } move_hnt(a, c, b, aa, cc, bb, n - 1); /* gotoxy(0,width+1); printf("from %c to %c",aa,cc);*/ play(a, c); move_hnt(b, a, c, bb, aa, cc, n - 1); } void init() { int i, j, k; //初始化整个程序 char ch; HideCursor(); //决定是否开启光标隐藏 cx = 1, cy = 1; lcx = cx, lcy = cy; mid_x = 7, mid_y = 60; tcx = computer_map_place[computer_map[cx][cy]][0], tcy = computer_map_place[computer_map[cx][cy]][1]; flag = 0, function, if_shift = 0, if_start = 0, if_input_password = 0, if_into_desktop = 0, if_game = 0; put_in_num = 0, if_input = 0; system("mode con cols=125 lines=60"); printf("【程序信息】:\n"); printf(" 程序名称:模拟笔记本电脑\n"); printf(" 程序作者:404name\n"); printf(" 完成时间:2020.2.01\n"); printf(" 最后更新:2020.4.07\n"); printf(" 项目地址:https://github.com/404name/winter (有问题可以去联系我)\n\n"); printf("【更新记录】(2020)\n"); printf(" 3.10 修复bug:不同平台显示乱码\n"); printf(" 3.15 修复bug:关机仍能输入密码\n"); printf(" 3.15 优化体验:加入光标隐藏(关闭前往init函数第一行)\n"); printf(" 3.19 完善功能:加入可移动游戏简洁版,可自制地图,方法前往源程序my_map数组处查看\n"); printf(" 4.07 完善功能:(桌面软件全部更新,功能完善,更加贴近xp系统。)\n"); printf(" ·密码输入优化,输入的密码会在下一次输入变成不可视。\n"); printf(" ·优化打砖块对角碰撞算法,更加真实。\n"); printf(" ·新增“此电脑”可查看电脑配置.\n"); printf(" ·新增关机画面。\n"); printf(" ·加入蓝屏,更加快乐(点击浏览器触发)\n"); printf(" ·优化更多细节.\n\n"); printf("【程序补充】\n"); printf(" ·这里差不多把坑填完了,之前反应的要有能操控的游戏,输入密码可见不真实,关机画面没模拟等等\n"); printf(" ·都弄完了,至于网上冲浪,打lol,写编译器就有生之年吧。对了,因此我还特意加入了蓝屏(滑稽)。\n\n"); printf("【程序说明】\n"); printf(" ·有问题,有bug,不兼容,欢迎去git反馈交流\n"); printf(" ·操作方法:↑ ↓ ← → 空格 控制光标即可。\n"); printf(" ·进入程序电源键处按一次空格||输入密码WHJY即可登录||请在虚拟键盘上开启大写再输入||\n"); printf(" ·欢迎使用XP模拟笔记本电脑!\n"); printf(" 1.按两下回车进入(未能解决bug:移动时周围可能会有蓝色的闪频)\n"); printf(" 2.按1再按回车进入 (开启清除闪频,但光标背景变成透明,不好鉴别)\n"); ch = getchar(); getchar(); if (ch == '1') qpz = 1; else qpz = 0; gotoxy(0, 0); system("color 70"); for (i = 0; i <= 40; i++) { printf("%s\n", map[i]); Sleep(50); } x = 1, y = 20, num = board_place[keyboard[x][y]][2]; tx = board_place[keyboard[x][y]][3]; ty = board_place[keyboard[x][y]][4]; gotoxy(ty, tx); //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),02); for (i = 0; i < num; i++) { printf("%c", temp[i]); } } void init_start() { // 开机 + 动态加载页面 + 打开输入密码权限 int i, l, j; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", start[i]); Sleep(100); } for (l = 0; l < 3; l++) { //动态加载 for (i = 53; i <= 71; i = i + 2) { for (j = i - 4; j <= i; j = j + 2) { if (j >= 53 && j <= 70) { gotoxy(j, 12); printf("[]"); } Sleep(100); } for (j = i - 4; j <= i; j = j + 2) { if (j >= 53 && j <= 70) { gotoxy(j, 12); printf(" "); } } } } gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", password[i]); Sleep(10); } if_input = 1; // 9 77 18个 input_x = 9; input_y = 77; input_max = 18; } void load_desktop() { //加载桌面 int i; cx = 1, cy = 1; if_into_desktop = 1; if_input == 0; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", desktop[i]); Sleep(100); } } void end() { //加载关机 int i; system("color 70"); //Windows 正在关机... char temp1[30] = {"│ 正在注销.... │"}; char temp2[30] = {"│ Windows 正在关机...│"}; gotoxy(0, 0); if_input = 0; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", start[i]); Sleep(10); } gotoxy(51, 12); printf("%s", temp1); Sleep(3000); gotoxy(51, 12); printf("%s", temp2); Sleep(4000); gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", map[i]); Sleep(10); } } void blue_screen() //蓝屏 { int i, j, l = 2, r = 122, hei = 16, len = 124; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 30); gotoxy(0, 0); if_into_desktop = 0; for (i = 1; i <= hei; i++) { //打印地图 for (j = 0; j <= len; j++) { if (j >= l && j <= r) { gotoxy(j, i); printf("%c", ending[i][j]); } } l++; r--; Sleep(50); printf("\n"); } getch(); getch(); getch(); system("color 70"); end(); if_start = 0; if_into_desktop = 0; if_input = 0; } void my_computer() { int i; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", MyComputer[i]); Sleep(10); } getch(); gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", desktop[i]); Sleep(100); } } void load_more() { //更多信息 int i; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", thinking[i]); Sleep(1000); } } void load_game() { //加载汉诺塔程序 int i; if_into_desktop = 0; gotoxy(0, 0); for (i = 0; i <= 16; i++) { printf("%s\n", game_hnt[i]); Sleep(100); } if_game = 1; gotoxy(mid_y - 16, mid_x); printf("请输入你要递归的汉诺塔数目_"); input_x = mid_x; input_y = mid_y - 16 + 27; input_max = 1; if_input = 1; } int move() { //控制虚拟键盘的指针移动函数 int i, k, flag = 1; char ch, ch1, ch2; while (ch != ' ') { ch = getch(); if (if_game == 2 && ch != ' ') flag = 0; if (ch != 'w' && ch != 'a' && ch != 's' && ch != 'd' && ch != -32 && ch != ' ') continue; lx = x, ly = y; if (ch == -32) { //同时启用wasd 和上下左右键 //如果读取到第一个是-32那么 继续读取一个字符 ch1 = getch(); switch (ch1) { case 72: ch = 'w'; break; case 75: ch = 'a'; break; case 80: ch = 's'; break; case 77: ch = 'd'; break; } } if (if_game != 2) system("color 70"); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); gotoxy(0, tx); printf("%s", map[tx]); switch (ch) { case 'a': y = y - 1; break; case 'd': y = y + 1; break; case 'w': x = x - 1; break; case 's': x = x + 1; break; case ' ': break; } if (keyboard[x][y] == 0) { x = lx; y = ly; } num = board_place[keyboard[x][y]][2]; tx = board_place[keyboard[x][y]][3]; ty = board_place[keyboard[x][y]][4]; gotoxy(ty, tx); for (i = 0; i < num; i++) { if (qpz == 1) { printf(" "); } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 57); printf("%c", temp[i]); } } if (if_game == 2) break; } if (if_game != 2) system("color 70"); if (if_game == 2 && ch == ' ') ch = ' '; if (board_place[keyboard[x][y]][0] == 0 || flag == 0) return 0; else if (board_place[keyboard[x][y]][0] >= 1 && board_place[keyboard[x][y]][0] <= 9) { function = board_place[keyboard[x][y]][0]; /*gotoxy(0,41); printf("%d",board_place[ keyboard[x][y] ][0]);*/ return 2; } else { letter = if_shift ? board_place[keyboard[x][y]][1] : board_place[keyboard[x][y]][0]; /*gotoxy(0,41); printf("%c",board_place[ keyboard[x][y] ][0]);*/ return 1; } } //----------------------------------------------------------------------------打砖块/----------------------------------------------------------------------------- void init_brick() { int l, r, i, j, a, b; cnt = 0; HideCursor(); width2 = 16, length2 = 124; wall = '#', food = '*', air = ' ', brick = 'O'; head2 = 0, tail2 = 0, max2 = 20, step2 = 0, if_miss = 0, food_num = 400, goal = 0, color = 0; debug = 0, life = 3; //debug模式调成1手动开启 temp_x2 = 2, temp_y2 = 2, menu_x = 18, menu_y = 68, left2 = 25, right2 = 35; //临时坐标 gotoxy(0, 0); memset(s, 0, sizeof(s)); r = length2; l = 0; if (if_my_map == 0) { for (i = 0; i <= width2; i++) { //生成地图模板 for (j = 0; j <= length2; j++) { if (i == 0 || i == width2) map2[i][j] = wall; else if (j <= l || j >= r) map2[i][j] = wall; else if ((i == width2 * 2 / 3) && (j >= length2 * 2 / 5 && j <= length2 * 3 / 5)) map2[i][j] = wall; else if (i == width2 - 1 && j >= left2 && j <= right2) map2[i][j] = wall; else map2[i][j] = air; } l++; r--; } if (if_load_snake_mod == 1) { food_num = 400; while (food_num--) { //贪吃蛇生成食物 a = rand() % width2; b = rand() % length2; if ((a >= width2 / 3 && a <= width2 * 2 / 3) && (b >= length2 * 2 / 5 && b <= length2 * 3 / 5) || a == 0 || b == 0) continue; map2[a][b] = food; } } for (i = 0; i <= width2; i++) { //布置砖块brick for (j = 0; j <= length2; j++) { if (((i >= width2 * 2 / 3 && i <= width2 * 2 / 3 + 1) && (j >= 0 && j <= length2 / 5)) || ((i >= width2 * 2 / 3 && i <= width2 * 2 / 3 + 1) && (j >= length2 * 4 / 5 && j <= length2))) map2[i][j] = brick; if ((i >= width2 / 3 && i <= width2 / 3 + 1) && ((j >= length2 / 10 && j <= length2 * 7 / 20) || (j >= length2 * 17 / 20 && j <= length2 * 9 / 10))) map2[i][j] = brick; } } } else { for (i = 0; i <= width2; i++) { strcpy(map2[i], my_map[i]); } } r = length2; l = 0; gotoxy(0, 0); for (i = 0; i <= width2; i++) { //打印地图 for (j = 0; j <= length2; j++) { if (j >= l && j <= r) { gotoxy(j, i); if (i == width2) printf("!"); else printf("%c", map2[i][j]); } } l++; r--; Sleep(50); printf("\n"); } //构建初始位置以及速度和方向角度 X2 = width2 - 6; Y2 = rand() % 5 + 23; old_x2 = (int)X2; old_y2 = (int)Y2; s[step2].x2 = old_x2; s[step2].y2 = old_y2; V = 15; Vx = -V * sin(C[3] * pi / 180.0); //速度向右向下为正方向 Vy = V * cos(C[3] * pi / 180.0); gotoxy(4, 1); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf("life:"); for (i = 0; i < life; i++) printf("■"); } void end_brick() { char temp; int i, j; int flag = max2; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); while (flag != 0) { if (step2 < 0) step2 += max2; gotoxy(s[step2].y2, s[step2].x2); map2[s[step2].x2][s[step2].y2]--; if (map2[s[step2].x2][s[step2].y2] == air && !(s[step2].x2 == 0 && s[step2].y2 == 0)) //防止自己吃自己 printf("%c", air); s[step2].x2 = 0; s[step2].y2 = 0; step2--; flag--; Sleep(100); } for (i = 0; i <= 14; i++) { gotoxy(45, 1 + i); printf("%s\n", End[i]); Sleep(100); } temp = getch(); system("color 70"); if_game = 0; if_input = 0; load_desktop(); if_into_desktop = 1; } void manchange(char ch) //人为输入更新 { if (ch == 'a' || ch == 's' || ch == 'd' || ch == 'w' || ch == ' ' || ch == 'p' || ch == 'b') //目前只开放aswd { if (ch == 'a' && map2[width2 - 1][left2 - 1] != wall) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); left2--; gotoxy(left2, width2 - 1); map2[width2 - 1][left2] = wall; printf("%c", wall); gotoxy(right2, width2 - 1); map2[width2 - 1][right2] = air; printf(" "); right2--; } else if (ch == 'd' && map2[width2 - 1][right2 + 1] != wall) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); right2++; gotoxy(right2, width2 - 1); map2[width2 - 1][right2] = wall; printf("%c", wall); gotoxy(left2, width2 - 1); map2[width2 - 1][left2] = air; printf(" "); left2++; } else if (ch == 'p') { /*gotoxy(2, width2 + 5); printf("游戏暂停,按'p'继续游戏"); ch2 = getch(); while (ch2 != 'p') { ch2 = getch(); } gotoxy(2, width2 + 5); printf(" ");*/ } else if (ch == 'b') { init_brick(); } } //function = move(&temp_x2,&temp_y2,0,width2,0,length2,1,1,ch); //function = move(&menu_x,&menu_y,18,24,68,68,2,0,ch); } void autochange() //自动更新 { int flag = 1, i; double t1, t2; double s1, s2; double temp; double x1_t1; double x2_t1; double x3_t1; double x4_t1; //更具体请前往https://github.com/404name/winter 打砖块子目录下下载demo文件参考抛物线原理 //这里的“轨迹”是存在“循环队列”的结构体中的 //map数组一开始只打印一次,随后在原数组上的改变不会作用显示。 //显示轨迹的其实还是打印空格,但不同的是颜色 //消去轨迹也打印白色的空格:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); /*------------------------------------------------------- 核心公式: X = X0 + Vx * t + 1/2 * VX * t * t; Y = Y0 + Vy * t; 核心思想: ·如果选择时间作为移动参考,则每秒会出现点相差太远 难以实现连续。 ·这里反过来,以连续为前提,尝试找出每移动一个单位 需要多少时间,则能依次找出一个连续的曲线。 出现问题: c语言数组只能是整数,所以移动方向只能存在水平和竖直, 不能依照运动方向实现往某个特定的角度移动一个单位。 并且要排除断节问题(即打印的曲线断断续续) 解决方法: 把特移动方向移动单位分解到X,Y上。 分别算出 X 增加一个单位长度 应该增加的 Y 的距离 s1 <=> flag == 1 Y 增加一个单位长度 应该增加的 X 的距离 s2 <=> flag == 2 优先选择更短的min(s1,s2),然后以flag对应不同的模式作为下一次移动的基准。 这样操作能保证线段仅仅只在水平与竖直方向移动时线段仍能连续 打个比方:一段斜率为2的直线 x增加1 Y增加2你看,这里Y脱节了会一下子在Y上移动了2格。 但实际上我们看 Y增加1 X实际上只增加0.5. 所以一段曲线,他的微元构成的直线不管斜率多偏僻,都能连续打印。 这就是为什么取min(s1,s2)决定移动模式的原因。 这样能保证仅仅只在上移动一个单位int(Y),而int(X)是不增加的,浮点型的X又把量累计到下一次在判断。 最后实现: X,Y用double储存,保证实际叠加能连续; 而实际打印,是不能说(5,6.28)这样的浮点型能在c语言上打印,所以我们采用int整型的old_x,old_y来承接X,Y以便于打印在屏幕上。 我们按照时间为循环只能在屏幕上打印一串断断续续的类抛物线的点。 但我们按照走一个“方向单位”,依次类叠,我们就能得到一串连续的线。 结果实现: 由于,算法偏向不严谨,可能会出现小部分开局断节bug,但随着循环推迟,后期能100%连续!! 加入人为修正 经测试小范围的数据能完美打印出物理抛物线!!! ------------------------------------------------------------*/ x1_t1 = (-Vx + sqrt(Vx * Vx + 20)) / 10; x2_t1 = (-Vx - sqrt(Vx * Vx + 20)) / 10; x3_t1 = (-Vx + sqrt(Vx * Vx - 20)) / 10; x4_t1 = (-Vx - sqrt(Vx * Vx - 20)) / 10; if (x1_t1 > 0 && x2_t1 > 0) t1 = x1_t1 < x2_t1 ? x1_t1 : x2_t1; else t1 = x1_t1 >= 0 ? x1_t1 : x2_t1; if (x3_t1 > 0 && x4_t1 > 0) temp = x3_t1 < x4_t1 ? x3_t1 : x4_t1; else if (x3_t1 * x4_t1 < 0) temp = x3_t1 >= 0 ? x3_t1 : x4_t1; else temp = 10; t1 = t1 < temp ? t1 : temp; s1 = t1 * Vy; //当Y2增加一个单位方向时 t2 = 1.0 / fabs(Vy); s2 = Vx * t2 + 0.5 * g * t2 * t2; if ((int)s1 == 0) flag = 1; else if ((int)s2 == 0) flag = 2; else flag = s1 < s2 ? 1 : 2; //选择最优进行处理 if (flag == 1) { X2 = X2 + Vx * t1 + 5 * t1 * t1; Y2 = Y2 + s1; Vx = Vx + g * t1; } else if (flag == 2) { Y2 = Y2 + Vy * t2; X2 = X2 + s2; Vx = Vx + g * t2; } /*else{ for( i = 0; i < 4; i++) 放弃判断对角了选择其他方式解决(详细见开头注释) } } */ //--------------------------------- old_x2 = (int)X2; old_y2 = (int)Y2; //常规的判断碰撞 if (map2[old_x2 + 1][old_y2] == wall && Vx >= 0 && map2[old_x2][old_y2 + 1] != wall && map2[old_x2][old_y2 - 1] != wall) { color = (color + 1) % 5; Vx = -Vx; } else if (map2[old_x2 - 1][old_y2] == wall && Vx <= 0 && map2[old_x2][old_y2 + 1] != wall && map2[old_x2][old_y2 - 1] != wall) { color = (color + 1) % 5; Vx = -Vx; } else if (map2[old_x2][old_y2 - 1] == wall && Vy <= 0 && map2[old_x2 - 1][old_y2] != wall && map2[old_x2 + 1][old_y2] != wall) { color = (color + 1) % 5; Vy = -Vy; } else if (map2[old_x2][old_y2 + 1] == wall && Vy >= 0 && map2[old_x2 - 1][old_y2] != wall && map2[old_x2 + 1][old_y2] != wall) { color = (color + 1) % 5; Vy = -Vy; } else if (map2[old_x2 + 1][old_y2 + 1] == wall && Vx > 0 && Vy > 0 || map2[old_x2 + 1][old_y2 - 1] == wall && Vx > 0 && Vy < 0 || map2[old_x2 - 1][old_y2 + 1] == wall && Vx < 0 && Vy > 0 || map2[old_x2 - 1][old_y2 - 1] == wall && Vx < 0 && Vy < 0) { color = (color + 1) % 5; Vy = -Vy; Vx = -Vx; } if (map2[old_x2 + 1][old_y2] == brick && Vx >= 0 && map2[old_x2][old_y2 + 1] != brick && map2[old_x2][old_y2 - 1] != brick) { //color = (color + 1) % 5; Vx = -Vx; map2[old_x2 + 1][old_y2] = air; gotoxy(old_y2, old_x2 + 1); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf(" "); goal++; gotoxy(5, 2); printf("goal:%5d", goal); } else if (map2[old_x2 - 1][old_y2] == brick && Vx <= 0 && map2[old_x2][old_y2 + 1] != brick && map2[old_x2][old_y2 - 1] != brick) { //color = (color + 1) % 5; Vx = -Vx; map2[old_x2 - 1][old_y2] = air; gotoxy(old_y2, old_x2 - 1); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf(" "); goal++; gotoxy(5, 2); printf("goal:%5d", goal); } else if (map2[old_x2][old_y2 - 1] == brick && Vy <= 0 && map2[old_x2 - 1][old_y2] != brick && map2[old_x2 + 1][old_y2] != brick) { //color = (color + 1) % 5; Vy = -Vy; map2[old_x2][old_y2 - 1] = air; gotoxy(old_y2 - 1, old_x2); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf(" "); goal++; gotoxy(5, 2); printf("goal:%5d", goal); } else if (map2[old_x2][old_y2 + 1] == brick && Vy >= 0 && map2[old_x2 - 1][old_y2] != brick && map2[old_x2 + 1][old_y2] != brick) { //color = (color + 1) % 5; Vy = -Vy; map2[old_x2][old_y2 + 1] = air; gotoxy(old_y2 + 1, old_x2); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf(" "); goal++; gotoxy(5, 2); printf("goal:%5d", goal); } else if (map2[old_x2 + 1][old_y2 + 1] == brick && Vx > 0 && Vy > 0 || map2[old_x2 + 1][old_y2 - 1] == brick && Vx > 0 && Vy < 0 || map2[old_x2 - 1][old_y2 + 1] == brick && Vx < 0 && Vy > 0 || map2[old_x2 - 1][old_y2 - 1] == brick && Vx < 0 && Vy < 0) { color = (color + 1) % 5; //对角碰改变颜色方便区分 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); if (Vx > 0 && Vy > 0) { if (map2[old_x2 + 1][old_y2] == brick && map2[old_x2][old_y2 + 1] == brick) { map2[old_x2 + 1][old_y2] = air, gotoxy(old_y2, old_x2 + 1), printf(" "); map2[old_x2][old_y2 + 1] = air, gotoxy(old_y2 + 1, old_x2), printf(" "); } else map2[old_x2 + 1][old_y2 + 1] = air, gotoxy(old_y2 + 1, old_x2 + 1), printf(" "); } else if (Vx > 0 && Vy < 0) { if (map2[old_x2 + 1][old_y2] == brick && map2[old_x2][old_y2 - 1] == brick) { map2[old_x2 + 1][old_y2] = air, gotoxy(old_y2, old_x2 + 1), printf(" "); map2[old_x2][old_y2 - 1] = air, gotoxy(old_y2 - 1, old_x2), printf(" "); } else map2[old_x2 + 1][old_y2 - 1] = air, gotoxy(old_y2 - 1, old_x2 + 1), printf(" "); } else if (Vx < 0 && Vy > 0) { if (map2[old_x2 - 1][old_y2] == brick && map2[old_x2][old_y2 + 1] == brick) { map2[old_x2 - 1][old_y2] = air, gotoxy(old_y2, old_x2 - 1), printf(" "); map2[old_x2][old_y2 + 1] = air, gotoxy(old_y2 + 1, old_x2), printf(" "); } else map2[old_x2 - 1][old_y2 + 1] = air, gotoxy(old_y2 + 1, old_x2 - 1), printf(" "); } else if (Vx < 0 && Vy < 0) { if (map2[old_x2 - 1][old_y2] == brick && map2[old_x2][old_y2 - 1] == brick) { map2[old_x2 - 1][old_y2] = air, gotoxy(old_y2, old_x2 - 1), printf(" "); map2[old_x2][old_y2 - 1] = air, gotoxy(old_y2 - 1, old_x2), printf(" "); } else map2[old_x2 - 1][old_y2 - 1] = air, gotoxy(old_y2 - 1, old_x2 - 1), printf(" "); } Vx = -Vx; Vy = -Vy; goal++; gotoxy(5, 2); printf("goal:%5d", goal); } if (if_miss == 1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); gotoxy(s[step2].y2, s[step2].x2); map2[s[step2].x2][s[step2].y2]--; if (map2[s[step2].x2][s[step2].y2] == air && !(s[step2].x2 == 0 && s[step2].y2 == 0)) //防止自己吃自己 printf("%c", air); } s[step2].x2 = old_x2; s[step2].y2 = old_y2; if (map2[s[step2].x2][s[step2].y2] == food) { map2[s[step2].x2][s[step2].y2] = air; max2++; } switch (color) { case 0: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 60); break; //蓝色 case 1: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 70); break; //红色 case 2: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 40); break; //绿色 case 3: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 30); break; //深蓝色 case 4: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 128); break; //紫色 } gotoxy(s[step2].y2, s[step2].x2); if (map2[s[step2].x2][s[step2].y2] == brick) { map2[s[step2].x2][s[step2].y2] = air; } map2[s[step2].x2][s[step2].y2]++; if (debug == 0 && !(s[step2].x2 == 0 && s[step2].y2 == 0)) printf("%c", air); else printf("%d", step2 % 10); //debug模式 step2++; if (step2 >= max2) { if_miss = 1; } if (step2 >= max2) { cnt++; } step2 = step2 % max2; if (cnt > 2) { cnt = 0; color = (color + 1) % 5; } Sleep(150 - 2 * old_x2); //模拟下坠的时候速度加快--对应画面更新更快 if (map[old_x2][old_y2] == wall) { Vx = -Vx; Vy = -Vy; } if (old_x2 == width2 - 1) { gotoxy(7 + 2 * life, 1); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 07); printf(" "); life--; if (life == 0) end_brick(); } } //-----------------------------------------------------------------------------打砖块/----------------------------------------------------------------------------- void put_letter_to_computer(char letter) { //把字符传输给电脑屏幕,如果电脑if_input为零就禁止显示 int i; if (if_input == 1 && put_in_num < input_max) { put_in_computer[put_in_num] = letter; put_in_num++; put_in_computer[put_in_num] = '\0'; } gotoxy(input_y, input_x); if (if_input_password == 1) for (i = 0; i < put_in_num; i++) { if (i < put_in_num - 1) { printf("*"); } else printf("%c", put_in_computer[i]); } else printf("%s", put_in_computer); } void put_function_to_computer(int function) { //电脑处理相应共呢 1 ~ 返回 2 ~删除 3确认 4shift 5上 6左 7下 8又 9开机 int ncx, ncy; char ch; if (function == 9) { //开机 system("color 70"); if (if_start == 0) { if_input_password = 1; init_start(); if_start = 1; } else { if (if_game == 2) system("color 07"); end(); if_start = 0; if_into_desktop = 0; if_input = 0; } } if (function == 2 && put_in_num > 0 && if_input == 1) { //删除字符,但不可越界 put_in_num--; put_in_computer[put_in_num] = '\0'; if (if_input_password == 1) { gotoxy(input_y + put_in_num, input_x); printf(" "); } else { gotoxy(input_y, input_x); printf("%s", put_in_computer); printf(" "); } } if (function == 4) { //切换大小写 if (if_shift) if_shift = 0; else if_shift = 1; } if (function == 3 && if_input == 1 && if_game == 0) { //确认对应不同模式下的不同功能 if (strcmp(password_0, put_in_computer) == 0) { if_input_password = 0; load_desktop(); if_input = 0; put_in_num = 0; put_in_computer[put_in_num] = '\0'; } else { put_in_num = 0; put_in_computer[put_in_num] = '\0'; gotoxy(input_y, input_x); printf("密 码 错 误 !!!"); gotoxy(input_y, input_x); Sleep(1200); printf(" "); gotoxy(input_y, input_x); printf("|"); } } else if (function == 3 && if_game == 1 && put_in_num == 1 && put_in_computer[0] >= '1' && put_in_computer[0] <= '9') { int i, j; if_into_desktop = 0; gotoxy(mid_y - 16, mid_x); printf(" "); init_game(put_in_computer[0] - '0'); move_hnt(left, mid, right, 'a', 'b', 'c', put_in_computer[0] - '0'); getch(); getch(); getch(); for (i = 0; i <= width; i++) { for (j = 0; j <= len; j++) { game_map[i][j] = 0; } } if_game = 0; if_input = 0; load_desktop(); if_into_desktop = 1; put_in_num = 0; put_in_computer[0] = '\0'; } //if(if_game == 1 && function >= 5 && function <= 8)) 移动类型游戏暂未开放 (3.19更新可用了) else if (if_game == 2 && function >= 5 && function <= 8) { //5上 6左 7下 8又 ch = 'a'; switch (function) { case 5: ch = 'w'; break; case 6: ch = 'a'; break; case 7: ch = 's'; break; case 8: ch = 'd'; break; } manchange(ch); return; } else if (function == 3 && if_into_desktop) { if (computer_map[cx][cy] == 1) //1 - 汉诺塔 2 - 打砖块 { load_game(); if_game = 1; } else if (computer_map[cx][cy] == 2) //打砖块 { if_into_desktop = 0; init_brick(); if_game = 2; system("color 07"); } else if (computer_map[cx][cy] == 3) { //(我的电脑) my_computer(); } else if (computer_map[cx][cy] == 4) // 更多信息 { load_more(); getch(); getch(); getch(); load_desktop(); } else if (computer_map[cx][cy] == 5) { //浏览器(因为不支持,所以使用就蓝屏(滑稽)) blue_screen(); } } if (if_into_desktop && function >= 5 && function <= 8) { ncx = cx + next[function][0], ncy = cy + next[function][1]; if (computer_map[ncx][ncy]) { gotoxy(tcy, tcx); printf(" "); cx = ncx, cy = ncy; tcx = computer_map_place[computer_map[cx][cy]][0]; tcy = computer_map_place[computer_map[cx][cy]][1]; lcx = cx, lcy = cy; gotoxy(tcy, tcx); printf("[]"); } } if (function == 1 && if_into_desktop) { //返回 load_desktop(); } } int main() { if_my_map = 0; //是否加载自己设置的关卡,改成1后 my_map数组就是内置地图 HideCursor(); init(); /*load_desktop(); //直接进入桌面 if_start = 1; if_into_desktop = 1;*/ HideCursor(); while (1) { //主循环w if (if_game == 2) //打砖块 autochange(); if (kbhit()) { flag = move(); //move提取读取的键盘按键并判断类型 switch (flag) { case 0: break; //暂无效果的按键 case 1: put_letter_to_computer(letter); break; //返回字符型按键给电脑 case 2: put_function_to_computer(function); break; //返回功能型按键给电脑 } } } getchar(); }