Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Паскаль, Turbo Pascal, PascalABC.NET
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 27.10.2021, 22:02   #1
Кверт
Пользователь
 
Регистрация: 09.08.2021
Сообщений: 15
По умолчанию Крестики-нолики на PascalABC.NET. Игровое поле на форме из девяти кнопок

Крестики-нолики на PascalABC.NET
Игровое поле на форме из девяти кнопок:
button1 button2 button3
button4 button5 button6
button7 button8 button9

Есть ещё:
Label1
- для отображения хода и результата игры

и еще одна кнопка
button10
- для Новой игры.

Процедура button1_Click - одна для всех 9-ти кнопок.
Изображения
Тип файла: png Крестики-нолики.PNG (9.9 Кб, 24 просмотров)
Кверт вне форума Ответить с цитированием
Старый 27.10.2021, 22:03   #2
Кверт
Пользователь
 
Регистрация: 09.08.2021
Сообщений: 15
По умолчанию

Код:
Unit Unit1;

interface

uses System, System.Drawing, System.Windows.Forms;

type
  Form1 = class(Form)
    procedure button1_Click(sender: Object; e: EventArgs);
    procedure button10_Click(sender: Object; e: EventArgs);
  {$region FormDesigner}
  internal
    {$resource Unit1.Form1.resources}
    button2: Button;
    button3: Button;
    button4: Button;
    button5: Button;
    button6: Button;
    button7: Button;
    button8: Button;
    button9: Button;
    label1: &Label;
    button10: Button;
    button1: Button;
    {$include Unit1.Form1.inc}
  {$endregion FormDesigner}
  public
    constructor;
    begin
      InitializeComponent;
    end;
  end;

implementation

var player: boolean:=true; // true - 1-ый игрок (X);  false - 2-ой игрок (0)

procedure Form1.button1_Click(sender: Object; e: EventArgs);
begin
  //messagebox.Show(sender.GetType.GetProperty('Name').GetValue(sender).ToString);
  if player then sender.GetType.GetProperty('Text').SetValue(sender,' X ')
  else sender.GetType.GetProperty('Text').SetValue(sender,' 0 ');
  
  if ((button1.Text=button2.Text) and (button1.Text=button3.Text) and (button1.Text<>'') or
      (button4.Text=button5.Text) and (button4.Text=button6.Text) and (button4.Text<>'') or
      (button7.Text=button8.Text) and (button7.Text=button9.Text) and (button7.Text<>'') or
      (button1.Text=button5.Text) and (button1.Text=button9.Text) and (button1.Text<>'') or
      (button3.Text=button5.Text) and (button3.Text=button7.Text) and (button3.Text<>'') or
      (button1.Text=button4.Text) and (button1.Text=button7.Text) and (button1.Text<>'') or
      (button2.Text=button5.Text) and (button2.Text=button8.Text) and (button2.Text<>'') or
      (button3.Text=button6.Text) and (button3.Text=button9.Text) and (button3.Text<>'')) then
  begin 
    label1.Text := player ? 'Победил 1-ый игрок!':'Победил 2-ой игрок!';
    button1.Enabled:=false; button2.Enabled:=false; button3.Enabled:=false; 
    button4.Enabled:=false; button5.Enabled:=false; button6.Enabled:=false; 
    button7.Enabled:=false; button8.Enabled:=false; button9.Enabled:=false; 
  end
  else
  begin
    if (button1.text<>'') and  (button2.text<>'') and  (button3.text<>'') and
       (button4.text<>'') and  (button5.text<>'') and  (button6.text<>'') and
       (button7.text<>'') and  (button8.text<>'') and  (button9.text<>'') then
    begin
      label1.Text:='Ничья!';
    end
    else
    begin
      // игра продолжается
      sender.GetType.GetProperty('Enabled').SetValue(sender, false);
      player:=not player;
      label1.Text:=player ? 'Ходит 1-ый игрок':'Ходит 2-ой игрок';
    end;
  end;
end;

procedure Form1.button10_Click(sender: Object; e: EventArgs);
begin
  player:=true;
  label1.Text:='Ходит 1-ый игрок';
  button1.Enabled:=true; button2.Enabled:=true; button3.Enabled:=true; 
  button4.Enabled:=true; button5.Enabled:=true; button6.Enabled:=true; 
  button7.Enabled:=true; button8.Enabled:=true; button9.Enabled:=true; 
  button1.Text:=''; button2.Text:=''; button3.Text:=''; 
  button4.Text:=''; button5.Text:=''; button6.Text:=''; 
  button7.Text:=''; button8.Text:=''; button9.Text:=''; 
end;

function CheckOverGame: boolean;
begin
(*  здесь не видны кнопки button1....9
*)
  result:=true;
end;

end.
Кверт вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Крестики Нолики Бесконечное поле Progdog Общие вопросы C/C++ 3 19.06.2012 18:16
Крестики-нолики на большом поле Pascal Juice Помощь студентам 14 16.04.2008 23:07