Main.c

来源:互联网 发布:海南大学网络教学平台 编辑:程序博客网 时间:2024/05/22 14:53
#include <stdio.h>#include <stdlib.h>#include <ncurses.h>#include "Datatypes.h"#include "Output.h"#include "Move.h"#include "Version.h"#include  <time.h>int main(void){tHandlehandle;tInt16ch;intquit=0;intleave;handle.best=0;handle.win=NULL;srand(time(NULL));while (!quit){initOutput(&handle);initField(&handle);drawField(&handle);newTile(&handle);newTile(&handle);ch=0;leave=0;while (!leave){int m;drawField(&handle);ch=getch(); // input a charm=0;switch(ch){case KEY_UP: // 0403case 'K':case 'k':case 'W':case 'w':m=makeMove(&handle,MOVE_UP);break;case KEY_DOWN: // 0402case 'J':case 'j':case 'S':case 's':m=makeMove(&handle,MOVE_DOWN);break;case KEY_LEFT: // 0404case 'H':case 'h':case 'A':case 'a':m=makeMove(&handle,MOVE_LEFT);break;case KEY_RIGHT: // 0405case 'L':case 'l':case 'D':case 'd':m=makeMove(&handle,MOVE_RIGHT);break;}if (m){newTile(&handle);if (m==WINNING_TILE){leave=1;drawField(&handle);quit=winner(&handle);}}m=checkMoveable(&handle);if (!m){leave=1;drawField(&handle);quit=loser(&handle);}if (ch=='Q') leave=quit=1;}}endOutput(&handle);printf("[n2048 v%i.%i] Copyright (c) 2014, Thomas Dettbarn (dettus@dettus.net)\n",MAJOR_REVISION,MINOR_REVISION);printf("All rights reserved.\n");printf("\n");printf("Redistribution and use in source and binary forms, with or without\n");printf("modification, are permitted provided that the following conditions are met:\n");printf("\n");printf("1. Redistributions of source code must retain the above copyright notice, this\n");printf("   list of conditions and the following disclaimer. \n");printf("2. Redistributions in binary form must reproduce the above copyright notice,\n");printf("   this list of conditions and the following disclaimer in the documentation\n");printf("   and/or other materials provided with the distribution.\n");printf("\n");printf("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n");printf("ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n");printf("WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n");printf("DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\n");printf("ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n");printf("(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n");printf("LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n");printf("ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n");printf("(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n");printf("SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n");printf("\n");}

0 0