My omnium-gatherom of scripts and source code.
at main 83 lines 1.9 kB view raw
1/* 2 * ===================================================================================== 3 * 4 * Filename: main.cpp 5 * 6 * Description: Chess 7 * 8 * Version: 1.0 9 * Created: 02/19/2023 12:39:04 PM 10 * Revision: none 11 * Compiler: gcc 12 * 13 * Author: YOUR NAME (), 14 * Organization: 15 * 16 * ===================================================================================== 17 */ 18#include <ncurses.h> 19#include <stdlib.h> 20 21#include <algorithm> 22#include <cmath> 23#include <iostream> 24#include <iterator> 25#include <utility> 26 27class Piece { 28 public: 29 int color; 30 char icon; 31}; 32 33int current = -1; 34int parity() { 35 current++; 36 return 1 + (current % 2); 37} 38 39int main() { 40 initscr(); 41 curs_set(0); 42 43 std::pair<int, int> screenMax; 44 getmaxyx(stdscr, screenMax.first, screenMax.second); 45 46 int tableSize = 10; 47 WINDOW *win = newwin(tableSize, tableSize, 48 fma(tableSize >> 1, -1, screenMax.first >> 1), 49 fma(tableSize >> 1, -1, screenMax.second >> 1)); 50 51 if (has_colors() == false) { 52 delwin(win); 53 endwin(); 54 std::cout << "Your terminal does not support colors.\n"; 55 exit(1); 56 } 57 refresh(); 58 59 enum Color { WHITE_PAIR = 1, BLACK_PAIR }; 60 61 start_color(); 62 init_pair(WHITE_PAIR, COLOR_WHITE, COLOR_BLACK); 63 init_pair(BLACK_PAIR, COLOR_BLACK, COLOR_WHITE); 64 65 attron(COLOR_PAIR(WHITE_PAIR)); 66 box(win, 0, 0); 67 attroff(COLOR_PAIR(WHITE_PAIR)); 68 wrefresh(win); 69 70 int myArray[tableSize - 2]; 71 std::generate_n(myArray, tableSize - 2, parity); 72 for (int column = 1; column < tableSize - 1; column++) { 73 for (int row = 1; row < tableSize - 1; row++) { 74 wattron(win, COLOR_PAIR(myArray[row])); 75 mvwprintw(win, row, column, "."); 76 wattroff(win, COLOR_PAIR(myArray[row])); 77 } 78 std::rotate(myArray, myArray + tableSize - 2, myArray + tableSize - 1); 79 std::cout << "\n"; 80 } 81 wrefresh(win); 82 getch(); 83}