Skip to content

Instantly share code, notes, and snippets.

@oha-yashi
Last active Mar 8, 2020
Embed
What would you like to do?
sudoku/ver.1/setting
#include <ncurses.h>
#include <string.h>
#include "setting.h"
int winx, winy;
void startGame(){
/* setting */
initscr();
cbreak();
noecho();
idlok(stdscr, TRUE);
scrollok(stdscr, TRUE);
keypad(stdscr, TRUE);
/* color setting */
start_color();
colorSetting();
bkgd(COLOR_PAIR(1));
getmaxyx(stdscr, winy, winx);
}
void colorSetting(){
init_pair(1, colorBLACK, colorWHITE);
init_pair(2, colorRED, colorWHITE);
init_pair(3, colorGREEN, colorWHITE);
}
/* 画面サイズ エラー:1 OK:0 を返す */
int checkWindowSize(){
int rt = 0;
/* 高さ不足 */
if(winy < TATE_ALL){
printw("SHORT HEIGHT ERROT!! NEED %d, now:%d\n", TATE_ALL, winy);
rt++;
}
/* 幅不足 */
if(winx < YOKO_ALL){
printw("SHORT WIDTH ERROR! NEED %d, now:%d", YOKO_ALL, winx);
rt++;
}
/* エラーあり */
if(rt){
getch();
return rt;
}
/* WINDOW SIZE CLEAR */
/* GAME START表示 */
char *str1 = "GAME START!!";
char *str2 = "PUSH ANY KEY!!";
mvaddstr(winy/2, (winx-strlen(str1))/2, str1);
mvaddstr(winy/2+1, (winx-strlen(str2))/2, str2);
getch();
clear();
return rt;
}
void endGame(){
clear();
char *str1 = "GAME END!!";
char *str2 = "PUSH ANY KEY!!";
mvaddstr(winy/2, (winx-strlen(str1))/2, str1);
mvaddstr(winy/2+1, (winx-strlen(str2))/2, str2);
getch();
endwin();
}
void reverse(int OnOff){
if(OnOff)attron(A_REVERSE);
if(!OnOff)attrset(0);
}
#ifndef _SETTING_H_
#define _SETTING_H_
#define YOKO 77 /* マスの横幅 */
#define TATE 37 /* マスの行数 */
#define YOKO_ALL (YOKO+1) /* 必要な横幅 */
#define TATE_ALL (TATE+3) /* 必要な行数 */
#define ON 1
#define OFF 0
/* 上下左右キーマクロ
* ^: KEY_UP
* v: KEY_DOWN
* <: KEY_LEFT
* >: KEY_RIGHT
*/
/* 色設定で使用。ncursesの定数とぶつからない命名 */
#define colorBLACK 0
#define colorRED 9
#define colorGREEN 10
#define colorWHITE 231
void startGame();
void colorSetting();
int checkWindowSize();
void endGame();
void reverse(int);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment