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

📄 main_win.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>
#include <cstdlib>
using namespace std;

#include <windows.h>

#include "checkers.hpp"

#include "server.hpp"

#include "client.hpp"

DWORD WINAPI run_server (LPVOID server_data);

int main(int argc, char *argv[])
{
  /*
  HANDLE hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
  COORD coord = {80, 25};
  SetConsoleScreenBufferSize (hStdOut, coord);
  */

  printf ("Chinese Checkers 0.2.2  Copyleft (c) 2003-2004 BenBear\n"
	  "Windows Console Version. It's hard to use, sorry.\n\n");
  printf ("what would you do:\n\n");
  printf (" 1. create a new game\n 2. join a exist game\n");
  printf (":");
  char ch;
  do
    {
      ch = getch();
    }
  while ((ch != '1') && (ch != '2'));

  putchar (ch);
  printf ("\n");

  if (ch == '2')
    {
      unsigned int ip1, ip2, ip3, ip4;
      unsigned int ip;
      printf ("please input the ip:");
      scanf ("%u%u%u%u", &ip1, &ip2, &ip3, &ip4);
      ip = (ip1 << 24) + (ip2 << 16) + (ip3 << 8) + ip4;
      //ip = 0x7F000001;
      char name[PLAYER_NAME_LEN+1];
      printf ("please input the name:");
      scanf ("%s", name);
      system ("cls");
      client c;
      c.run (ip, name);

      return 0;
    }

  checkers::setting set;
  int floor;
  do
    {
      printf ("please input the floor(normal:8, small:6, big:10):");
      scanf ("%d", &floor);
    }
  while ((floor != 8) && (floor != 6) && (floor != 10));
  int num_player;
  do
    {
      printf ("please input how many player(2, 3, 4, 6):");
      scanf ("%d", &num_player);
    }
  while ((num_player < 2) || (num_player == 5) || (num_player > 6));
  int group = 0;
  if ((num_player == 4) || (num_player == 6))
    {
      {// clear the console input buffer
	char buf[1000];
	gets (buf);
      }
      printf ("Do you want to group?(y/N):");
      ch = getchar();
      if ((ch == 'y') || (ch == 'Y'))
	group = num_player / 2;
    }

  bool stay_limit;
  if (ch != '\n')
    {// clear the console input buffer
      char buf[1000];
      gets (buf);
    }
  printf ("Do you want stay limit?(y/N):");
  ch = getchar();
  stay_limit = ((ch == 'y') || (ch == 'Y'));

  bool long_jump;
  if (ch != '\n')
    {// clear the console input buffer
      char buf[1000];
      gets (buf);
    }
  printf ("Do you want to support long jump?(y/N):");
  ch = getchar();
  long_jump = ((ch == 'y') || (ch == 'Y'));

  checkers::setting data;
  data.floor = floor;
  data.number = num_player;
  data.long_jump = long_jump;
  data.group = group;
  data.stay_limit = stay_limit;

  DWORD id;
  HANDLE thread;
  thread = CreateThread (0, 0, run_server, &data, 0, &id);
  printf ("Do you want to join this game?(Y/n):");

  if (ch != '\n')
    {// clear the console input buffer
      char buf[1000];
      gets (buf);
    }

  ch = getchar ();
  if ((ch == 'n') || (ch == 'N'))
    WaitForSingleObject (thread, INFINITE);
  else
    {
      if (ch != '\n')
	{
	  char buf[1000];
	  gets (buf);
	}
      char name[PLAYER_NAME_LEN+1];
      printf ("please input the name:");
      scanf ("%s", name);
      system ("cls");
      client c;
      c.run (0x7F000001, name); // 127.0.0.1
    }
  return 0;
}

DWORD run_server (LPVOID server_data)
{
  checkers::setting *data = (checkers::setting *) server_data;
  server s(*data);
  s.run ();
  return 0;
}

⌨️ 快捷键说明

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