int main() { initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); // make keys work curs_set(0); // hide cursor timeout(100); int xmax; int ymax; getmaxyx(stdscr, ymax, xmax); enum Direction dir = RIGHT; Board* board = create_board(create_snake(), NULL, xmax, ymax); int i; for (i = 0; i < 6; i++) { add_new_food(board); } while(true) { erase(); display_points(board->snake, ACS_BLOCK); display_points(board->foods, ACS_DIAMOND); dir = get_next_move(dir); enum Status status = move_snake(board, dir); if (status == FAILURE) break; } endwin(); return 0; }
void init_players(void) { ULONG i; ULONG len; CBYTE str[128]; UBYTE asc; LbScreenClear(0); number_of_players = 0; while (!number_of_players) { sprintf(str,"How many players (1-8)?"); DrawCheapText(4,4,str,WHITE); LbScreenSwap(); if (Inkey >= KB_1 && Inkey <= KB_8) { number_of_players = Inkey-KB_1+1; sprintf(str,"How many players (1-8)? %d",number_of_players); DrawCheapText(4,4,str,WHITE); LbScreenSwap(); } Inkey = 0; } for (i=0; i<number_of_players; i++) { create_snake(i); snakes[i].Length = 5; snakes[i].Name = namebuf[i]; namebuf[i][0] = 0; len = 0; sprintf(str,"Player %d name: %s",i+1,namebuf[i]); DrawCheapText(4,14+30*i,str,WHITE); LbScreenSwap(); while (Inkey != KB_RETURN) { if(KeyOn[KB_BACKSPACE] && len>0) { KeyOn[KB_BACKSPACE] = 0; namebuf[i][--len]=0; DrawBox(4+56+(len+1)*4,14+30*i,4,5,0); } else { if (!(Inkey&0x80)) { asc = InkeyToAsciiShift[Inkey]; if (asc >= 32 && asc <= 127 && len < 128) { namebuf[i][len++] = asc; namebuf[i][len] = 0; } } } if (Inkey != KB_RETURN) Inkey = 0; sprintf(str,"Player %d name: %s ",i+1,namebuf[i]); DrawCheapText(4,14+30*i,str,WHITE); LbScreenSwap(); } Inkey = 0; sprintf(str,"Player %d left: ",i+1); DrawCheapText(4,24+30*i,str,WHITE); LbScreenSwap(); while (!snakes[i].Left) { while (!Inkey && !Display.LeftButton && !Display.RightButton && !Display.MiddleButton); if (Display.LeftButton) { Display.LeftButton = 0; snakes[i].Left = -1; sprintf(str,"Player %d left: Left Button",i+1); } else if (Display.RightButton) { Display.RightButton = 0; snakes[i].Left = -2; sprintf(str,"Player %d left: Right Button",i+1); } else if (Display.MiddleButton) { Display.MiddleButton = 0; snakes[i].Left = -3; sprintf(str,"Player %d left: Middle Button",i+1); } else { if (!(Inkey&0x80)) { if (lbExtendedKeyPress) Inkey |= 0x80; snakes[i].Left = Inkey; sprintf(str,"Player %d left: %s",i+1,key_names[Inkey]); } Inkey = 0; } } DrawCheapText(4,24+30*i,str,WHITE); LbScreenSwap(); sprintf(str,"Player %d right: ",i+1); DrawCheapText(4,34+30*i,str,WHITE); LbScreenSwap(); while (!snakes[i].Right) { while (!Inkey && !Display.LeftButton && !Display.RightButton && !Display.MiddleButton); if (Display.LeftButton) { Display.LeftButton = 0; snakes[i].Right = -1; sprintf(str,"Player %d right: Left Button",i+1); } else if (Display.RightButton) { Display.RightButton = 0; snakes[i].Right = -2; sprintf(str,"Player %d right: Right Button",i+1); } else if (Display.MiddleButton) { Display.MiddleButton = 0; snakes[i].Right = -3; sprintf(str,"Player %d right: Middle Button",i+1); } else { if (!(Inkey&0x80)) { if (lbExtendedKeyPress) Inkey |= 0x80; snakes[i].Right = Inkey; sprintf(str,"Player %d right: %s",i+1,key_names[Inkey]); } Inkey = 0; } } DrawCheapText(4,34+30*i,str,WHITE); LbScreenSwap(); KeyOn[snakes[i].Left] = KeyOn[snakes[i].Right] = 0; } LbScreenClear(0); }