GithubHelp home page GithubHelp logo

opensource's Introduction

원본 : https://github.com/mevdschee/2048.c

README (한국어)

slack 주소 https://opensourcechat-group.slack.com/messages/DK41QTEG6/

screenshot

GNU/Linux용 게임 콘솔 버전

README

위쪽, 아래쪽, 왼쪽 및 오른쪽 화살표 키를 사용하여 4 방향으로 타일을 이동할 수 있습니다. 칠판의 모든 숫자는 벽에 부딪힐 때까지 그 방향으로 밀려날 것이고, 서로 맞물리는다면 두 숫자가 같은 값을 가지면 두 숫자가 하나로 합쳐질 것입니다. 각 번호는 이동 당 한 번만 결합됩니다. 매 이동마다 새로운 번호 2 또는 4가 나타납니다. 보드에 2048을 가지고 있다면 이깁니다. 하지만 보드가 꽉 차면 움직일 수 없습니다.

FILES

screenshot2 screenshot3 screenshot4

2048 코드의 디렉토리/파일 구조도 및 흐름도이다. 흐름도를 통하여 기본적인 시스템을 확인하고 자세한 설명은 코드 내부의 주석을 통해서 설명해놓았다.

INSTALL

요구사항

- C 컴파일러
테스트 대상: GNU/리눅스, FreeBSD, OpenBSD
Git 클론 https://github.com/wogus3602/OpenSource.git
gcc -o 2048 2048.c
./2048

USAGE

위쪽, 아래쪽, 왼쪽, 오른쪽 화살표 키를 사용하여 타일을 네 방향으로 이동할 수 있다. 보드의 모든 숫자는 벽에 부딪힐 때까지 그 방향으로 미끄러져 들어갈 것이고 만약 그들이 서로 부딪친다면, 두 개의 숫자가 같은 값을 가지고 있다면 하나로 합쳐질 것이다. 각각의 숫자는 한 번에 한 번만 결합될 것이다. 움직일 때마다 2번이나 4번이 나타난다. 만약 당신이 판 위에 2048점을 가지고 있다면, 당신은 이겼지만, 일단 판이 꽉 차서 움직일 수 없게 되면 진다. 그 게임은 다양한 색채 배열을 지원한다. 이것은 88색이나 256색에 대한 ANSI 지원에 따라 달라진다. 지원되는 색상이 충분하지 않으면 게임은 흑백으로 되돌아갈 것이다. 원래 색상표 실행의 경우:

FAQ

프로젝트에 기여하고 싶은 개발자는 [email protected]로 메일주시길 바랍니다.

slack 주소 https://opensourcechat-group.slack.com/messages/DK41QTEG6/

$ ./2048 테스트
모든 13개의 테스트가 성공적으로 실행됨

screenshot

Console version of the game "2048" for GNU/Linux

Gameplay

You can move the tiles in four directions using the arrow keys: up, down, left, and right. All numbers on the board will slide into that direction until they hit the wall and if they bump into each other then two numbers will be combined into one if they have the same value. Each number will only be combined once per move. Every move a new number 2 or 4 appears. If you have a 2048 on the board you have won, but you lose once the board is full and you cannot make a move.

Requirements

  • C compiler

Tested on: GNU/Linux, FreeBSD, OpenBSD

Installation

git clone https://github.com/wogus3602/OpenSource.git
gcc -o 2048 2048.c
./2048

Running

The game supports different color schemes. This depends on ANSI support for 88 or 256 colors. If there are not enough colors supported the game will fallback to black and white (still very much playable). For the original color scheme run:

./2048

For the black-to-white color scheme (requires 256 colors):

./2048 blackwhite

For the blue-to-red color scheme (requires 256 colors):

./2048 bluered

Contributing

Contributions are very welcome. Always run the tests before committing using:

$ ./2048 test
All 13 tests executed successfully

opensource's People

Contributors

dlwngud1230 avatar jmy552000 avatar manduiscoming avatar wogus3602 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

opensource's Issues

표준화 문제 POSIX와 ANSI C

이 2048 프로그램은 POSIX와 ANSI C 표준화 두 가지가 적용 되었다.
visual studio2017에서는 POSIX 표준화가 컴파일이 안되었다.
하지만 ubuntu에서 gcc 컴파일로 실행하면 POSIX 가 적용이 되었다.
결론은 window 운영체제 환경의 visual studio2017에서는 ANSI C 만 적용 가능하고 linux 운영체제 환경의 gcc 는 POSIX와ANSI C 둘 다 적용 가능하다.

2048.c 코드 vs실행시 문제점

코드가 리눅스 커널기반으로 짜여있어서 그런지
VS에서 지원하지 않는 헤더파일과 함수들을 window에 맞게 변환하는 작업이
필요할 것으로 보인다.

POSIX 헤더 파일 ANSI 헤더 파일에 대해서

표준화에는 많은 헤더 파일이 있지만 이 2048 프로그램에서는
ANSI/ISO 헤더 파일
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include <signal.h>
POSIX 헤더 파일
#include <unistd.h>
#include <termios.h>
이 쓰였다.

헤더 파일을 만드는 이유

.cpp 파일로 만들어진 오브젝트 파일에 있는 함수들의 내용을 다른 소스 파일에서 사용할 수 있도록 하기 위함이다.

A.cpp 파일에서 B.cpp 파일에 들어있는 함수나 클래스를 사용하기 위해서는 함수의 프로토 타입이나 클래스 선언 등의 정보가 필요하다.
(그래야 어떤 함수(또는 메소드)를 호출할때 인자값이 필요하고, 안필요하고와 리턴 타입을 알 수 있으니까.)

그런 정보들을 파악하기 위해서 헤더 파일을 만들어서 관리한다.
출처: https://kldp.org/node/134021

데이터 타입 uint를 쓰는 이유

2048코드에 uint가 굉장히 많던데 프로그램 이식성을 높이기 위해서라고 한다. 그 중에서도 uint8_t와 int16_t를 많이 사용한다고 한다.

SIZE 4 -> 5 수정

수정하니 바로 4x4 에서 5x5로 적용 되었음. 이 방식을 사용해 확장하는거 생각을 해보자.

branch 추가 (Window Version) + Warning level 5로 설정 오류 수정

비쥬얼 스튜디오로 실행 시켰을 때 화면이 깨지는 문제 몇가지 수정 후 정상 으로 나옵니다.

코드 내에서 "\033[38;5;%d;48;5;%dm" 이런 식 코드는 보통 linux에서 사용한다 함

Waaring level 5로 했을 때 오류 뜨는거 대부분 수정 그 외 수정 못한것은 헤더파일 내 문제거나 오류 고칠 방법 찾이 못했습니다.

참고 : https://gist.github.com/wogus3602/101f1eb68a1ea065bcbdc740111e261c
비쥬얼 prompt color : https://www.youtube.com/watch?v=v30nUWg6pks

비쥬얼 스튜디오로 실행했을때 문제점

윈도우 비쥬얼 스튜디오에서 2048.c 를 실행 시켜 보았더니 화면이 깨져서 나온다. 하지만 다른 조원 컴퓨터에서 실행 시켜보니 깨져서 나오지 않는다.
왜 그런지 몇 시간을 찾아보았지만 찾지 못했다.

이해하기 쉬운 코드를 작성하는 법

  1. 주석을 달자.
  2. 일관성 있는 들여쓰기
  3. 의미 있는 함수명
  4. 코드 그룹화
  5. 코드가 너무 길면 파일을 여러개로 분류
  6. 코드 한줄에 너무 길게 쓰지말자 열이 너무 많으면 다음줄에 이어서 적자(코드 열 기준을 정하는 것이 좋음.)
  7. 중복된 코드 제거

과제3 이후 이슈

  1. 보드사이즈 조절 가능하게 - 첫 메인 화면에서 아이디 입력과 보드사이즈 설정 가능하게 만들것
  2. 가독성 기준으로 코드 수정 - 최대한 읽기 쉽고 이해하기 쉽게 코드 수정하기
  3. 랭킹시스템 도입 - 텍스트파일로 게임이 끝날시 출력하게 만들기

분할컴파일 gcc로 컴파일 문제

2048.c(main함수라고 보면됨), 2048Color.h(보드판 그려주는 함수부분의 헤더), 2048Color.c(보드판 그려주는 함수 실행부분)

  1. 가장 먼저 해야할일은 2048.c 와 2048Color.c 를 기계어가 해석가능한 object 코드로 만드는 일이다. 오브젝트 코드는 gcc에 -c 옵션을 이용해서 만들어낼 수 있다.
    gcc -c 2048Color.c 2048.c

  2. 이제 2048.o 와 2048Color.o 라는 파일이 만들어진걸 확인할 수 있을 것이다. 확장자 .o는 이 파일이 오브젝트 파일이라는 것을 알려준다. 이제 두개의 object 파일을 링크시켜서 실행파일을 만들면 된다. -o 옵션을 이용하면, 만들어진 오브젝트 파일들을 합쳐줄 수 있다.
    gcc -o 2048 2048Color.o 2048.o

  3. 파일 실행!
    ./2048

방향키 기능에 대한 문제점

키보드 상,하,좌,우 버튼이 인식되지않는 문제와

w,a,s,d를 누르고 엔터를 쳐야지만 인식이 되는 부분을

_kbhit() 함수를 사용하여 키입력과 동시에 실행되도록 구현할 수 있을것으로 보임

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.