/*--------------------------------------------------------- 

用VC的一定要选则 Win32 Console Application工程

2.25最新版本
未加入新功能
修复了一些bug，适配了所有编译器。。。
可直接运行exe或者赋值。

程序： 模拟笔记本电脑   （纯C语言，可直接编译器运行） 
作者： 0.0
说明： 1.这个程序本意在模拟电脑的基本功能，重在实现键盘的输入与键盘的控制，模拟开机，输密，打开软件，关闭电脑，所以其他功能暂没开发，不用太失望。 
	   2.不同的编码会有不同的长度显示，但运行出来的效果都是一样的 
	   3.代码规范不到位，见谅。 
	   4.大一上写的，一般写小游戏练手，也琢磨到一些特殊的处理方法，所以对一些功能处理上有一些难理解的地方。 
       5.emmm，没啥了
---------------------------------------------------------*/
#include <conio.h> //用于getch（）
#include <stdio.h>
#include <string.h>
#include <windows.h>
char start[20][300] = { //图形界面
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\                                                                                                                         /"},
    {"  \\                                                                                                                       /"},
    {"   \\                                                                                                                     /"},
    {"    \\                                                                                                                   /"},
    {"     \\                                                               /~/~/                                             /"},
    {"      \\                                                             /~/~/                                             /"},
    {"       \\                                     Microsotf@             ~ ~     __ XP                                    /"},
    {"        \\                                    \\  /\\  / -  _   _|  _  _   _  /_                                       /"},
    {"         \\                                    \\/  \\/  | | | |_| |_| \\/\\/  __/                                      /"},
    {"          \\                                                                                                       /"},
    {"           \\                                        _____________________                                        /"},
    {"            \\                                      │                    │                                       /"},
    {"             \\                                     └────────────────────┘                                      /"},
    {"              \\                                                                                               /"},
    {"               \\  Copyright ΘMicrosoft Corporation                                            Microsoft*    /"},
    {"                \\ __________________________________________________________________________________________/"}};
char password[20][300] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\                                                                                                                         /"},
    {"  \\  ------------------------------------------------------------------------------------------------------------------   /"},
    {"   \\                                                                                                                     /"},
    {"    \\                                                         |                                                         /"},
    {"     \\                                                        |                                                        /"},
    {"      \\                                                       |  ┌─────────────────────────────────────────────       /"},
    {"       \\                                           /~/~/      |  │┌─────┐  Administrator                             /"},
    {"        \\                                         /~/~/ __XP  |  ││ []│  输入密码                                 /"},
    {"         \\                \\  /\\  / -  _   _|  _   ~ ~  /_     |  │└─────┘  【|                 】ck[→]            /"},
    {"          \\                \\/  \\/  | | | |_| |_| \\/\\/ __/     |  └───────────────────────────────────────         /"},
    {"           \\                                                  |                                                  /"},
    {"            \\                  要开始，请单击您的用户名       |                                                 /"},
    {"             \\                                                |                                                /"},
    {"              \\                                                                                               /"},
    {"               \\   ----------------------------------------------------------------------------------------  /"},
    {"                \\ __________________________________________________________________________________________/"}};
char desktop[20][300] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\    ─────      ─────     ─────      ┌────┐    ┌────┐                                                                     /"},
    {"  \\   \\  [] \\    \\    \\    \\    \\     │    │    │ing │                                                                    /"},
    {"   \\    ─────     ─────     ─────     └────┘    └────┘                                                                   /"},
    {"    \\   小游戏     垃圾桶    计算器     相关     待开发                                                                 /"},
    {"     \\    ─────                                                                                                        /"},
    {"      \\   \\    \\                                                                                                      /"},
    {"       \\   ─────       __ --------------- __ __                                                                      /"},
    {"        \\  IE浏览器__--   --- __ -------_ -------_------____                                                        /"},
    {"         \\   ____     __--__ -- __ -------_ --- - __ --- __ --------------______                                   /"},
    {"          \\__  -------_--__  ------- __ ---------- __ ------ __ ------ __ --- __ ---------____                    /"},
    {"           \\  -------_---__  ------- _---- __ -------_ ---_ -------_ -_ ----------_ -_---_ -_ ------_ -_         /"},
    {"            \\--__ -- __ ----- __ ------ __ -------_ ---  ---- __ -------_ -_ ---------_ -_ ------_  -_ ------   /"},
    {"             \\ -_--__  ------- _---- __ -------_ ------- __ -------_ -- __ -------_ -_ --------__---_ -_ ------/"},
    {"              \\ _____________________________________________________________________________________________ /"},
    {"               \\ 开始 \\  qq2010   |                                                                 |  12:00 /"},
    {"                \\ __________________________________________________________________________________________/"}};
char game_hnt[20][300] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\   ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐    /"},
    {"  \\                                                                                                                       /"},
    {"   \\                                                                                                                     /"},
    {"    \\                                                                                                                   /"},
    {"     \\                                                                                                                 /"},
    {"      \\                                                                                                               /"},
    {"       \\                                                                                                             /"},
    {"        \\                                                                                                           /"},
    {"         \\                                                                                                         /"},
    {"          \\                                                                                                       /"},
    {"           \\                                                                                                     /"},
    {"            \\                                                                                                   /"},
    {"             \\  └───────────────────────────────────────────────────────────────────────────────────────────┘  /"},
    {"              \\ _____________________________________________________________________________________________ /"},
    {"               \\ 开始 \\  qq2010   |  汉诺塔自动演示小游戏  |                                        |  12:08 /"},
    {"                \\ __________________________________________________________________________________________/"}};
char thinking[30][300] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\   ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐    /"},
    {"  \\    这里是感想：                                                                                                       /"},
    {"   \\                                                                                                                     /"},
    {"    \\      寒假太颓废了，没劲学习，游戏玩腻，然后开始发呆。安静下来时才有灵感 ，看着笔记本，就想着我也编一个电脑系统吧  /"},
    {"     \\                                                                                                                 /"},
    {"      \\      就想把大一上学到的一些东西总着来练练手。。然后发现写电脑系统就是痴人说梦了，我还是写个模拟计算机吧。     /"},
    {"       \\                                                                                                             /"},
    {"        \\      对着自己笔记本的键盘一个一个的还原，然后思考如何体现屏幕，如何移动键盘，如何读取键盘把信息传给我的   /"},
    {"         \\                                                                                                         /"},
    {"          \\       虚拟电脑，如何模拟开机实现基本功能 ，一口气写完真心爽，最后想做互动游戏的，但这斜着的屏幕，emmm /"},
    {"           \\                                                                                                     /"},
    {"            \\       所以最后电脑只能运行汉诺塔，其他功能实现也简单，但还是把时间放在我突然又燃起的学习小火苗上吧/"},
    {"             \\  └───────────────────────────────────────────────────────────────────────────────────────────┘  /"},
    {"              \\ _____________________________________________________________________________________________ /"},
    {"               \\ 开始 \\  qq2010   |  感想.txt  |                                                   |  12:15 /"},
    {"                \\ __________________________________________________________________________________________/"}};
char ending[30][300] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\                                                                                                                         /"},
    {"  \\                                                      正在关机                                                         /"},
    {"   \\                                                                                                                     /"},
    {"    \\                                              请确保你的数据已保存                                                 /"},
    {"     \\                                                                                                                 /"},
    {"      \\                                                     0.0                                                       /"},
    {"       \\                                                                                                             /"},
    {"        \\                                               正在损失数据                                                /"},
    {"         \\                                                                                                         /"},
    {"          \\                                            电脑格式化成功                                             /"},
    {"           \\                                                                                                     /"},
    {"            \\                                           感谢使用  Xp                                            /"},
    {"             \\                                                                                                 /"},
    {"              \\                                                                                               /"},
    {"               \\                                                                                             /"},
    {"                \\ __________________________________________________________________________________________/"}};
char map[10000][2000] = {
    {"┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐"},
    {" \\                                                                                                                         /"},
    {"  \\                                                                                                                       /"},
    {"   \\                                                                                                                     /"},
    {"    \\                                                                                                                   /"},
    {"     \\                                                                                                                 /"},
    {"      \\                                                                                                               /"},
    {"       \\                                                                                                             /"},
    {"        \\                                                                                                           /"},
    {"         \\                                                                                                         /"},
    {"          \\                                                                                                       /"},
    {"           \\                                                                                                     /"},
    {"            \\                                                                                                   /"},
    {"             \\                                                                                                 /"},
    {"              \\                                                                                               /"},
    {"               \\                                                                                             /"},
    {"                \\ __________________________________________________________________________________________/"},
    {"                ┌──────────────────────────────────────────────────────────────────────────────────────────┐"},
    {"                │                                                                                  ────    │"},
    {"                │──────────────────────────────────────────────────────────────────────────────────────────│"},
    {"                │┌─────┐  ┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┐                 │"},
    {"                ││ 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}, {5, 0, 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},
    {0, 0, 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 = 0, function, if_shift = 0, if_start = 0, if_input_password = 0, if_into_desktop = 0, if_game = 0; //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 = 0, if_input = 0, input_x, input_y, input_max;
//  汉诺塔游戏变量
int mid_x = 7, mid_y = 60;
int len, width, left, mid, right, time;
int ttx = 10, tty = 10;
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	上左下     //实现自动移动的路线储存

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;
    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;
	tcx = computer_map_place[computer_map[cx][cy]][0];
	tcy = computer_map_place[computer_map[cx][cy]][1];
	lcx = cx, lcy = cy;
	cx = 1;
	cy = 1;
    printf("↑ ↓ ← → 空格    进行操作\n\n");
    printf("用空格按下电源键即可进行开机\n\n");
    printf("xp系统祝你使用愉快~~\n\n");
    printf("开机密码WHJY\n");
    printf("桌面程序只有第一个和相关有用，其他暂未开放\n");
    printf("汉诺塔程序运行过程中是不能中止的，尽量开6个以下\n"); //这里是原本写了一个版本，自动变化函数+人工输入函数能中途退出，但改一下整个程序都要改动，就放弃了那个版本
    printf("按任意键继续\n");
    getch();
    system("color 70");
    system("mode con cols=125 lines=60");
    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;
    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;
	gotoxy(0, 0);
    for (i = 0; i <= 16; i++)
    {
        printf("%s\n", ending[i]);
        Sleep(1000);
    }
    gotoxy(0, 0);
    for (i = 0; i <= 16; i++)
    {
        printf("%s\n", map[i]);
        Sleep(10);
    }
}
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;
    char ch = '\0', ch1 = '\0';
    while (ch != ' ')
    {
        ch = getch();
        lx = x, ly = y;
        if (ch != ' ' && ch != 'w' && ch != 's' && ch != 'a' && ch != 'd' &&
            ch != -32)
            continue;
        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;
            }
        }
        system("color 70");
        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);
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 57);
        for (i = 0; i < num; i++)
        {
            printf("%c", temp[i]);
        }
        gotoxy(ty, tx);
    }
    system("color 70");
    if (board_place[keyboard[x][y]][0] == 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 put_letter_to_computer(char letter)
{ //把字符传输给电脑屏幕，如果电脑if_input为零就禁止显示
    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);
    printf("%s", put_in_computer);
}
void put_function_to_computer(int function)
{ //电脑处理相应共呢   1 ~ 返回    2 ~删除     3确认   4shift  5上 6左 7下 8又  9开机
    if (function == 9)
    { //开机
        if (if_start == 0)
        {
            init_start();
            if_start = 1;
        }
        else
        {
            end();
            if_start = 0;
            if_into_desktop = 0;
        }
    }
    if (function == 2 && put_in_num > 0 && if_input == 1)
    { //删除字符，但不可越界
        put_in_num--;
        put_in_computer[put_in_num] = '\0';
        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)
        {
            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;
        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');
        Sleep(2000);
        
        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';
    }
    else if (function == 3 && if_into_desktop)
    {
        if (cy == 1)
        {
            load_game();
            if_game = 1;
        }
        else
        {
            load_more();
            getch();
            load_desktop();
        }
    }
    //if(if_game == 1 && function >= 5 && function <= 8))     移动类型游戏暂未开放
    if (if_into_desktop && function >= 5 && function <= 8)
    {
        int 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()
{
    init();
    /*load_desktop();//直接进入桌面
	if_start = 1; 
	if_into_desktop = 1;*/
    while (1)
    {                  //主循环
        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();
}

