⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_linux.cpp

📁 本程序是主要是扫雷
💻 CPP
字号:
/*     Copyright(c) Ben Bear 2003-2004  *///  This program is free software; you can redistribute it and/or//  modify it under the terms of the GNU General Public License as//  published by the Free Software Foundation; either version 2 of the//  License, or (at your option) any later version.//  //  This program is distributed in the hope that it will be useful,//  but WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU//  General Public License for more details.//  //  You should have received a copy of the GNU General Public License//  along with this program; if not, write to the Free Software//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA//  02111-1307, USA.#include <cstdio>using namespace std;#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <pthread.h>#include "checkers.hpp"#include "server.hpp"#include "client.hpp"#include "small_menu.hpp"#include "option_dialog.hpp"#include "ip_dialog.hpp"#include "text_dialog.hpp"#include "string_dialog.hpp"void* create_server (void *arg);void version_dlg ();int main(){  bool is_server = false;  pthread_t p;  _init_interface _i;  version_dlg();  const char* game_menu[4] = {"Create a new game",			      "Join a exist game",			      "Exit",			      NULL};  int ch = menu_select ("Game Menu", game_menu);  if (ch == 2)    return 0;  ++ch;  if (ch == 1)    {      checkers::setting set;            int f = 1, g = 0, n = 0;      const char* floor_name = "Checkers Size";      const char* floor_item[] = {"Small, 6", 				  "Normal, 8", 				  "Big, 10", 				  NULL};      const char* player_name = "How Many Players";      const char* player_item[] = {"2 players", 				   "3 players", 				   "4 players", 				   "4 players | 2 groups", 				   "6 players", 				   "6 players | 2 groups",				   "6 players | 3 groups",				   NULL};            const char* jump_name = "Jump options";      const char* jump_item[] = {"Long jump",				 "Stay limit",				 NULL};      int jump_val[] = {0, 0};      option_dialog opt ("Game Setting");      opt.add (option_dialog::OPTION_RADIO, floor_name,	       floor_item, &f);      opt.add (option_dialog::OPTION_RADIO, player_name,	       player_item, &n);      opt.add (option_dialog::OPTION_CHECK, jump_name,	       jump_item, jump_val);      if (opt.show () == false)	return 0;      switch (f)	{	case 0:  f = 6;  break;	case 1:  f = 8;  break;	case 2:  f = 10; break;	default: f = 8;  break;	}      switch (n)	{	case 0:  n = 2; g = 0; break;	case 1:  n = 3; g = 0; break;	case 2:  n = 4; g = 0; break;	case 3:  n = 4; g = 2; break;	case 4:  n = 6; g = 0; break;	case 5:  n = 6; g = 2; break;	case 6:  n = 6; g = 3; break;	default: n = 2; break;	}      set.floor = f;      set.number = n;      set.group = g;      set.long_jump = (jump_val[0] == 1);      set.stay_limit = (jump_val[1] == 1);      pthread_create (&p, 0, &create_server, &set);    }  if (ch == 1)    {      is_server = true;      const char* join_menu[] = {"Yes", "No", NULL};      if (menu_select ("Join this game?", join_menu) == 1)	{	  pthread_join (p, 0);	  return 0;	}      addch ('\n');    }  int ip, p0, p1, p2, p3;  char name[PLAYER_NAME_LEN+1] = "";  if (is_server)    ip = 0x7F000001;		// 127.0.0.1  else    {      ip_dialog dlg("Ther server ip:");      dlg.show ();      dlg.get_ip (p0, p1, p2, p3);      ip = (p0 << 24) + (p1 << 16) + (p2 << 8) + p3;    }  string_dialog name_dlg ("Please input your name:", name, PLAYER_NAME_LEN);  name_dlg.show ();  client c;  c.run (ip, name);  return 0;}void* create_server (void *arg){  checkers::setting *set = static_cast<checkers::setting *>(arg);  server s(*set);  s.run ();  return 0;}void version_dlg (){  char *text;  FILE *f = fopen ("README", "r");  int buf_len= 200;  if (f != 0)    {      fseek (f, 0, SEEK_END);      buf_len += ftell(f);    }  text = new char[buf_len];  strcpy (text,	  "Chinese Checkers 0.2.4 Copyleft (c) 2003-2004 BenBear\n"	  "Linux Console Version.\n\n"	  "--------------------------\n\n");  if (f != 0)    {      char *ptr = text;      while (*ptr != '\0')	++ptr;      fseek (f, 0, SEEK_SET);      int ch;      while ((ch = fgetc(f)) != EOF)	*ptr++ = ch;      *ptr = '\0';    }  text_dialog version ("Version and README", text);  delete[] text;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -