Git Product home page Git Product logo

obstruction-game's People

Contributors

iliyalb avatar jensboe avatar xemeds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ksviveksiddarth

obstruction-game's Issues

Inflexible grid size

Hi just saw your game on reddit. Program looks nice written.
I am an embedded programmer and use C. I don't know much about CLI and strings. I am deeper. ;)
Some of parts of my toolchain are written in python so may understand your thinkings.

I will write some "issues" down, so may you can "improve" your code or just think about my suggestions.
(I will not repeat this introducing words...)

Your board size can be changed by
#define BOARD_SIZE 6
but the grid print doesn't adapt, it will always will a 6x6 grid.

Improve "slow" code

if (board[y][x] == 'X')
	printf("\033[34m\033[1m %c ", board[y][x]);

Why using printf with variable replacement while the replacement is always a fixed value. (in this Example 'X'.
This will may speed up your programm.On a 3GHz processor, in a CLI this may doen't matter, but hey, it's possible. ;)

if without curly braces

Don't forget curly braces. Especially if you are a Python programmer. If you switch between Python and C you easily forget the braces if you add a second statement to the if.

			if (board[y][x] == ' ')
				can_play = 1;

Using enums instead chars for board "status".

Instead of 'X' 'O' and ' ' you can create an enum with states like 'player_A', 'player_B' or 'free'. You can even introduce 'blocked' state.
This makes code more readable and splits 'data' better from 'view'. So you can introduce some symbol or color picking at the beginning of the game. Or you can change from CLI to a real GUI or 3d animation without changing your core game engine. ;)

Use real chars instead of integer

if (!(len == 2) || !(97 <= move[0] && move[0] <= 102) || !(49 <= move[1] && move[1] <= 54))

This will improve readability:
if (!(len == 2) || !('a' <= move[0] && move[0] <= 'f') || !('1' <= move[1] && move[1] <= '6'))

Or if you plan to be more flexible with your grid size and your 'view' write a convert_CLI_input function which will return a x and y coordinates. (To do this, you have to define a costom type or a call by reference with x and y parameters).

Use macros for 'magic' strings.

I don't know what \033[0;36m means, Some control or color instructions maybe. So i must google it.
Something like a macro #define CLI_CYAN_COLOR \033[0;36m make your code easily understandable. Trust me in 6 month you don't know the color codes any more and you must google by yourself.

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.