#Linux Tettris 소스코드(배열모양:4 * 4)

#언어: c

#필요라이브러리:libncurses.a

#make link option: -lncurses

 

>원리

LEFT 이동시에 1보다 큰 값이 있으면 LEFT 이동이 불가능하다.

 

 

 

linux_tris_time_4_4.c
0.01MB

- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - frm version
- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - frm version
- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - frm version
- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - frm version

using statistics search(BackgroundWorker)
using statistics search(BackgroundWorker)
using statistics search(BackgroundWorker)

frm_tris_4_4.cs
0.01MB

 

simple tris + windows form edition

 

tris_frm_4_4_1.cs
0.01MB

- c# windos console hexa, tettris code(IDE:editor,Compiler:csc) - console version
- c# windos console hexa, tettris code(IDE:editor,Compiler:csc) - console version
- c# windos console hexa, tettris code(IDE:editor,Compiler:csc) - console version
_ using Console.SetCursorPosition()
_ using Console.SetCursorPosition()
_ using Console.SetCursorPosition()

 

tris_4_4.cs
0.01MB

- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - console version
- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - console version
- c# windows console hexa, tettris code(IDE:editor,Compiler:csc) - console version
- only useing Console.WriteLine()
- only useing Console.WriteLine()
- only useing Console.WriteLine()

 

pure_tris_4_4.cs
0.01MB


- c,c++ windows console hexa, tettris code(IDE:editor,Compiler:gcc)
- c,c++ windows console hexa, tettris code(IDE:editor,Compiler:gcc)
- c,c++ windows console hexa, tettris code(IDE:editor,Compiler:gcc)

 

mainsrc.c
0.00MB
common.h
0.00MB
common.c
0.01MB

 

- c# frm & feat.console & text draw version

frm_txt_draw.cs
0.02MB


- pascal window form hexa, tettris code(IDE:DELPHI) 


- javascript web-browser hexa, tettris code(IDE:editor)
- javascript web-browser hexa, tettris code(IDE:editor)
- javascript web-browser hexa, tettris code(IDE:editor)

____no_ajax_tris_4_4.html
0.02MB
____real_fast_no_ajax_tris.html
0.02MB


- c,c++ windows console tettris code(IDE:edit)
- c,c++ windows console tettris code(IDE:edit)
- c,c++ windows console tettris code(IDE:edit)

tris_basic_4_4.c
0.01MB

- c,c++ windows console tettris code(IDE:edit) - time_tick using thread
- c,c++ windows console tettris code(IDE:edit) - time_tick using thread
- c,c++ windows console tettris code(IDE:edit) - time_tick using thread

tris_thread_4_4.bat
0.00MB
tris_thread_4_4.c
0.01MB



- java console hexa, tettris code(IDE:editor,Compiler:javac)

2. Linux(Ubuntu,Centos)
- c,c++ console hexa, tettris code(IDE:editor,Compiler:gcc,실행도구:telnet terminal)
- javascript web-browser hexa, tettris code(IDE:editor,실행도구:desktop mode)

3. Windows 10 + Linux was(tomcat)
- javascript web-browser network hexa, tettris code(feat. AJAX)



# Compiler
1. windows 10 c# console - csc(freeware)
2. windows 10 c# form - visual studio(freeware at private, but company is not free)

3. windows 10 c,c++ console - gcc(freeware)
4. windows 10 c,c++ form - visual studio(freeware at private, but company is not free)

5. windows 10 pascal form - DELPHI (freeware at private, but company is not free)
6. windows 10, Linux javascript - web-browser is OK


Question into xterm92@naver.com

curses.h: No such file or directory

RHEL / Fedora / CentOS
>yum install ncurses-devel ncurses

Debian / Ubuntu
>apt-get install libncurses5-dev libncursesw5-dev

빌드할 때, -lncurses 옵션을 붙여줘야 올바르게 컴파일 할 수 있다.
gcc -o program program.c -lncurses

#대표적인 프로그램으로는 linux >top명령어에 의한 화면일것이다.

#Linux Tettris 코딩, 2가지 방법에 대해서(2번째 방법을 개인적으로 선호합니다.)
- curses.h 를 이용한 리눅스터미날환경에서 동작하는 프로그램방식입니다.

 

 

1. 기본적인 흐름을 따라가는 방법
- 키보드의 이벤트와 time이벤트를 동시에 하나의 함수에서 처리하는 로직

main(void)
{
    int tris[MAPY][MAPX],design[ARR_CNT][ARR_CNT],xpos,ypos,score;
    while(1)
    {
        if(keyhit())
        {
            ch = getch();
            if(ch==KEY_RIGHT) ,,,,,,
        }
        kk=downPossible(tris,design,xpos,ypos,score);
        if(kk==0)
        {
            if(ypos==0) exit(0);
            else
            {
               ,,,,,
            }
         }
     }
}

linux_tris.c
0.01MB

 

2. time_event handler를 이용해서 키보드로 제어하지 않는 부분을 해당코드에 입력 
- time이벤트처리를 따로 뺴고, 키보드의 로직은 다른 함수에서 분리시키는 로직

   
#include<signal.h>
#include<sys/time.h>

void time_handler(int signum)
{
    static int cnt=0;
    printf("timer expired[%d]\n", cnt++);
}

int main(void)
{
    struct sigaction sa;
    struct itimerval timer;

    memset(&sa,0x00,sizeof(sa));
    sa.sa_handler=&time_handler;
    sigaction(SIGVTALRM,&sa,NULL);

    timer.it_value.tv_sec=0;
    timer.it_value.tv_usec=250000;

    timer.it_interval.tv_sec=0;
    timer.it_interval.tv_usec=250000;

    setitimer(ITIMER_VIRTUAL,&timer,NULL);

    while(1);
}      

 

linux_tris_time.c
0.01MB

1. 학원등록번호 : 제 ****호(***** 교육청)

- 현재 등록되지 않은 상태입니다.

2. 강의 시간표 & 교육과정 & 수강료

- 미정

3. 학습대상

- 중고등학생 코딩교육, 취업을 준비하는 대학생, 일반인

4. 강사프로필

- 20년경력의 프로그래머(증권, 통신, 데이타베이스부분)

- 소프트웨어 경진대회 수상경력(대상등)

- 프리랜서 프로그램 개발(키움증권,코스콤,네이버클로버,삼성증권,팍스넷,데이콤,NC소프트)

5. 학습과목

- C언어, C++언어, C#언어, JAVA언어

6. 연락처

- 문의점은 xterm92@naver.com 으로 메일주시면 성실히 답변해드리겠습니다.

7. 학원오픈일정

- 미정

 

#JavaScript TeTTris Game 프로그램 코드(4*4 배열모양)

____no_ajax_tris_4_4.html
0.02MB

 

 

<script type="text/javascript">

/*const define variable*/
var ARR_CNT_IDX = 4;

/*design variable definition*/
var realdesign1 = [0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0];
var realdesign2 = [0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0];
var realdesign3 = [0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0];
var realdesign4 = [0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0];
var realdesign5 = [0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0];
var realdesign6 = [0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,0];
var realdesign7 = [0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0];
/*function definition*/

 

</script>

 

 

#Linux Tettris game 프로그램코드(c언어)

1. 소스

#include <curses.h>

2. Compile & Link

CFLAGS=-O2 -Wall -Wextra -pedantic -Wno-vla -std=c99
LDFLAGS=-lncurses

3. 주요로직

- c# 언어이던지, java 언어이던지,

- c언어이던지 로직은 같다. 단지 출력부분만 틀릴뿐

- 출력부분을 살펴보자.

void draw_tris(int **tris)

{

    int ii,kk;

    char showtmp[MAPY][MAPX+1];

    memset(showtmp,0x00,sizeof(showtmp));

    for(ii=0; ii<MAPY; ii++)
    for(kk=0; kk<MAPX; kk++)
    {
        if(tris[ii][kk]==1) showtmp[ii][kk]='*';
        else showtmp[ii][kk]=' '; }

    clear();
    mvprintw(1,1,"TETTRIS-----------------------------");
    for(ii=0; ii<MAPY-1; ii++)
        mvprintw(2+ii,1,"%s",showtmp[ii]);

}

 

 

 

#Tettris by c# console program(4*4 배열의 모양)

테트리스모양이 4*4의 모습이다.

전버젼인 3*3에서 4*4로 숫자만 바뀐거뿐, 특별히 달라진건 없다.

확장성는 3->4로 바꾸는것일뿐^

        static int[, ,] design = new int[, ,]
        {
            {{0,1,0,0},{0,1,0,0},{0,1,0,0},{0,1,0,0}},
            {{0,0,0,0},{0,1,1,0},{0,1,1,0},{0,0,0,0}},
            {{0,0,0,0},{0,1,0,0},{1,1,1,0},{0,0,0,0}},
            {{0,0,1,0},{0,1,1,0},{0,1,0,0},{0,0,0,0}},
            {{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,0,0}},
            {{0,0,0,0},{0,1,0,0},{0,1,1,1},{0,0,0,0}},
            {{0,0,0,0},{0,1,1,1},{0,1,0,0},{0,0,0,0}}
        };

 

c_t_tris_4_4.cs
0.01MB

#거래소 & Koscom 정보분배 데이타 수신및 처리

1. 전용선데이타인 경우(UDP)

RcvUData ->Queue -> ReadQData -> Shared Memory

Test)

SendUData 127.0.0.1 19511 /web/krx/KRX_202101210900.dat

2. 인터넷데이타인 경우(TCP)

RcvTData -> Queue -> ReadQData -> Shared Memory

Test)

SendTData 127.0.0.1 19511 /web/krx/KRX_202101210900.dat

3. 데이타수신 패킷업무

data.koscom.co.kr 에서 확인가능

- 유가

- 코스닥

- 코넥스

- 선물(지수선물,상품선물,주식선물등)

- 옵션(지수옵션,상품옵션,주식옵션등)

- 지수

- ELW

 

 

#1

 "./command" 은 현재의 디렉토리에 있는 "command" 를 실행하라는 것입니다. 앞의 "./" 를 입력하지 않으려면 PATH 를 지정해 주면 됩니다.

쉘에 따라 다르지만 bash 가 보편적이므로

export PATH=./:$PATH

하면 됩니다. 윈도우즈는 기본적으로 현재의 디렉토리를 지정해 주지 않아도, 현재디렉토리를 최우선으로 찿기때문에 필요없는것 이지만 기본원리는 마찬가지 입니다. 리눅스에서 명확하게 지정하도록 하였으며, 이것은 다른 디렉토리에 같은 화일명이 있을 경우 사용자에게 어느 디렉토리의 파일을 실행시킬것인가의 주도권을 이양하는 의미도 있습니다.

 

#2

.profile
또는
.bash_profile
의 끝에 다음의 코드를 추가하는 것입니다:

PATH=${PATH}:.


${PATH} 은 기존의 패스 문자열을 나타내고,
점(.)은 현재 디렉토리를 나타냅니다.

이러면 현재 디렉토리가 어디든 상관 없이, 현재 디렉토리에 있는 파일을 항상 실행시킬 수 있습니다.

#JavaScript TeTTris Game 프로그램 코드(3*3배열모양)

 

____real_fast_no_ajax_tris.html
0.02MB

 

#주요코드

<script type="text/javascript">

var design = new Array(3,3)

/*variable definition*/

var realdesign1 = [0,1,1,1,1,0,0,0,0];

var realdesign2 = [0,1,1,1,1,0,0,0,0];

 

function design_init(____desc)

{

    if(____desc==1) design=realdesign1;

    else design=realdesign2;

}

</script>

첨부파일.확인. 문의는 xterm92@naver.com

#TETTRIS by c# console program

 

c_t_tris.cs
0.01MB

 

>주요포인트

                       

 

[ypos+0,xpos+0],[ypos+0,xpos+1],[ypos+0,xpos+2],

[ypos+1,xpos+0],[ypos+1,xpos+1],[ypos+1,xpos+2],

[ypos+2,xpos+0],[ypos+2,xpos+1],[ypos+2,xpos+2],

LEFT이동시에 값이 2가 되면, LEFT이동이 불가하다.

>xpos=xpos-1 로 해서 검사시에 FAIL이면 xpos=xpos+1로 원복

 

 

#Ubuntu 18.04 apt install/remove/list

 

1. 설치

$ apt install language-pack-ko

 

2. 제거

$ apt remove language-pack-ko

 

3. 설치되어진 리스트 출력

$ apt list
zynaddsubfx-dbg/xenial 2.5.2-2ubuntu1 i386
zynaddsubfx-dssi/xenial 2.5.2-2ubuntu1 i386
zyne/xenial 0.1.2-2 all
zynjacku/xenial 6-4build1 i386
zypper/xenial-updates 1.12.4-1build0.1 i386
zypper-common/xenial-updates 1.12.4-1build0.1 all
zypper-doc/xenial-updates 1.12.4-1build0.1 all
zziplib-bin/xenial-updates,xenial-security 0.13.62-3ubuntu0.16.04.1 i386

 

참고) Default .bashrc for ubuntu

wiki.kldp.org/HOWTO/html/Adv-Bash-Scr-HOWTO/sample-bashrc.html

 

샘플 .bashrc 파일

#=============================================================== # # bash-2.05 이후 버전을 위한 개인적 $HOME/.bashrc 파일 # # 아 파일은 대화모드 쉘을 위한 것입니다. # 별칭(alias)이나 함수, 프롬프트같은 # 대화모드

wiki.kldp.org

 

 

참고) Default .bashrc for ubuntu

gist.github.com/marioBonales/1637696

 

Default .bashrc for ubuntu

Default .bashrc for ubuntu. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

 

 

 

CentOS 7(2024.?.? 까지 지원) - iso 파일

 

mirror.kakao.com/centos/7.9.2009/isos/x86_64/

 

CentOS Mirror

 

mirror.kakao.com

 

 

 

 

 

 

'리눅스 > Ubuntu 18.04.5 LTS' 카테고리의 다른 글

Ubuntu 18.04 apt install/remove/list  (0) 2021.04.08
Default .bashrc for ubuntu  (0) 2021.04.08
Ubuntu 18.04 gcc 4.8설치  (0) 2021.04.06
Ubuntu 18.04 root계정 사용하기  (0) 2021.04.06
Ubuntu 18.04 FTP 구축하기  (0) 2021.04.06

#Ubuntu 18.04 gcc설치

 

1. gcc basic 설치

>sudo apt update
>sudo apt install build-essential
>gcc --version

gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

2. gcc 4.8설치(낮은버젼으로 설치해야 기존의 프로그램이 compile & link 해야하는경우)


>apt-get install gcc-4.8
>apt-get install g++-4.8

 

 

 

 

'리눅스 > Ubuntu 18.04.5 LTS' 카테고리의 다른 글

Default .bashrc for ubuntu  (0) 2021.04.08
CentOS 7(2024.?.? 까지 지원) - iso 파일  (0) 2021.04.07
Ubuntu 18.04 root계정 사용하기  (0) 2021.04.06
Ubuntu 18.04 FTP 구축하기  (0) 2021.04.06
Ubuntu 18.04.5 iptables 설정  (0) 2021.04.06

 

 

Ubuntu 18.04 root계정 사용하기

 

Ubuntu 18.04를 수동설치하면(서버), 일반계정을 생성하게 된다.

다음은 일반계정으로 로그인후에, root계정을 만들어보자/

 

- 일반계정에서 실행

>sudo passwd root

 

 

'리눅스 > Ubuntu 18.04.5 LTS' 카테고리의 다른 글

CentOS 7(2024.?.? 까지 지원) - iso 파일  (0) 2021.04.07
Ubuntu 18.04 gcc 4.8설치  (0) 2021.04.06
Ubuntu 18.04 FTP 구축하기  (0) 2021.04.06
Ubuntu 18.04.5 iptables 설정  (0) 2021.04.06
Ubuntu 18.04 telnet 구축하기  (0) 2021.04.06

환경 : Ubuntu 18.04.4 LTS (Bionic Beaver) Server (64-bit)

#Ubuntu 18.04 FTP 구축하기

 

 

1.
>apt update -y

2.
>apt-get install vsftpd

 

3. 실행 여부를 확인해봅니다.
>netstat -tnlp

4. 접속을 허락하지 않는 계정은 아래파일에 추가한다.
>vi /etc/ftpusers

 

5. 호스트에서의 파일 전송이 가능하도록 설정 ( 초기 설정은 클라이언트에서 파일 전송이 불가능 )

>vi /etc/vsftpd.conf

 

#write_enable=YES
위의 설정 항목을 아래와 같이 주석 해제합니다.
write_enable=YES

 

6. 설정이 완료되면 vsftpd를 재시작하도록 합니다.
>systemctl restart vsftpd

 

 

 

'리눅스 > Ubuntu 18.04.5 LTS' 카테고리의 다른 글

Ubuntu 18.04 gcc 4.8설치  (0) 2021.04.06
Ubuntu 18.04 root계정 사용하기  (0) 2021.04.06
Ubuntu 18.04.5 iptables 설정  (0) 2021.04.06
Ubuntu 18.04 telnet 구축하기  (0) 2021.04.06
Ubuntu 18.04.5 LTS 파티션 수동설치  (0) 2021.04.06


환경 : Ubuntu 18.04.4 LTS (Bionic Beaver) Server (64-bit)

환경 : Ubuntu 18.04.4 LTS (Bionic Beaver) Server (64-bit) 

#ubuntu 18.04.5 iptables 설정

#ubuntu 18.04.5 iptables 설정

 

1. 일단 IPtables를 이용하기 전에 UFW를 사용 중인 상태라면 UFW를 사용하지 않도록 처리합니다.
- UFW 비활성화
>ufw disable

 

2. 규칙추가 & 차단 & 삭제
- 포트 추가

>iptables -A INPUT -p tcp --dport 21 -j ACCEPT
>iptables -A INPUT -p tcp --dport 22 -j ACCEPT
>iptables -A INPUT -p tcp --dport 23 -j ACCEPT
>iptables -A INPUT -p tcp --dport 80 -j ACCEPT
>iptables -A INPUT -p tcp --dport 443 -j ACCEPT

- 포트 차단
>iptables -A INPUT -p tcp --dport 80 -j DROP
- 포트 차단 규칙 삭제
>iptables -D INPUT -p tcp --dport 80 -j DROP
- 세 번째 라인의 규칙 삭제
>iptables -D INPUT 3

 

3. IPtables 규칙 확인
>iptables --list
>iptables -L

 

4. 규칙 저장
>service iptables save

 

5. [ iptables-persistent 패키지 이용하기 ]
패키지 설치
>sudo apt-get install iptables-persistent netfilter-persistent
저장
>netfilter-persistent save
다시 로드
>netfilter-persistent start
위 저장 및 로드 명령어를 IPtables의 저장(Save) 명령 이후에 수행해주시면 됩니다. 
그러면 서버를 재부팅해도 그대로 IPtables 규칙 설정 정보가 남아 있습니다.

 

6. 방화벽 서비스 부팅 관련 명령
6.1 서비스 시작
>service iptables start
6.2 서비스 정지
>service iptables stop
6.3 서비스 재시작
>service iptables restart
6.4 서비스 저장
>service iptables save

 


텔넷과 xinetd를 설치합니다.

>apt-get install telnetd xinetd

설치가 완료되면 텔넷 설정을 위해서 gedit나 vi와 같은 편집기 툴로 
"/etc/xinetd.d/telnet" 파일을 만들어 줍니다. 파일이 열리면 아래 내용을 입력합니다.

>

service telnet
{
    disable         = no
    flags           = REUSE
    socket_type     = stream
    wait            = no
    user            = root
    server          = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}

>/etc/init.d/xinetd restart

서버에서 IP 확인

>ifconfig -a

텔넷클라이언트로 접속한다음에, 접속 에러가 난다면, 방화벽부분을 살펴봐야 한다.

+ Recent posts