[RUS]: S7-313C(SCL) + TP177a game "Pjatnashki" (15

примеры программ
mr.sheyh
Posts: 2
Joined: Tue Dec 13, 2005 11:57 am
Location: Russia

[RUS]: S7-313C(SCL) + TP177a game "Pjatnashki" (15

Post by mr.sheyh »

Old kind logical game called "Pjatnashki" (Fifteen puzzle).
It is a sliding puzzle that consists of a frame of numbered square tiles in random order with one tile missing. The object of the puzzle is to place the tiles in order by making sliding moves that use the empty space.

It is implemented on PLC S7-313C (SCL) + TP177a.
Unfortunately I have not found a function for random numbers generating, and I was lazy to make my one, so an initial deal is always the same.

Button "Start" appears when the tiles are in order and disappears when combination is not finished.
It is possible to insert any picture instead of numbered tiles.
Russian wrote:Старая добрая логическая игра "Пятнашки". Реализована на контроллере S7-313C (SCL) + TP177a.
К сожалению функции случайных чисел я не нашел, а городить свою было лениво, поэтому начальный расклад всегда один. Кнопка "Старт" появляется при собирании правильной комбинации и пропадает при её разборе. Вместо чисел можно легко вставить любую картинку.
http://narod.ru/disk/11621273000/15.ZIP.html
Schtiel
Site Admin
Posts: 1122
Joined: Wed Sep 06, 2006 12:03 pm
Location: CIS

Re: Пятнашки

Post by Schtiel »

mr.sheyh wrote:функции случайных чисел я не нашел, а городить свою было лениво

Code: Select all

FUNCTION FC1:VOID
NAME    : RANDOM
VAR_INPUT
    HiLimit :   INT ;
END_VAR
VAR_OUTPUT
    Random  :   INT ;
END_VAR
VAR_TEMP
    TimeTck :   TIME;
END_VAR
BEGIN
TimeTck := TIME_TCK();
Random := ABS(DINT_TO_INT(TIME_TO_DINT(TimeTck))) MOD HiLimit ;
END_FUNCTION
dlsdls2
Posts: 2
Joined: Thu Aug 27, 2009 3:38 pm
Location: Vietnam

Post by dlsdls2 »

Thank a lot men's!

For the moment i used the second solution, it s ok.

when i have a litle more time, i will try oscat.

cordially.