Comparing version 0.0.3 to 0.0.4
18
bin.js
#!/usr/bin/env node | ||
// Just because we're in a bin file doesn't mean we can't write proper | ||
// javascript. IEFE++ | ||
!function(require, process){ | ||
'use strict'; | ||
// The game board is built in coffeescript. | ||
require('coffee-script'); | ||
// Readline is what we use for terminal prompts. CLC gives us ANSI terminal | ||
// colors, so we can color players. The grid is a modular game grid, not | ||
// specific to any implementation (such as this.) Optimist is a really cool | ||
// utility for passing in CLI args, in our case, width, height, and number of | ||
// players. We then shuffle an array of colors so we can get a new set each | ||
// game. | ||
var readline = require('readline'), | ||
@@ -32,2 +41,3 @@ clc = require('cli-color'), | ||
// If we pass in --help, just write the details and quit. | ||
if(argv.help){ | ||
@@ -55,6 +65,10 @@ process.stdout.write(args.help()); | ||
finish = function(player){ | ||
process.stdout.write("\n----------------\nGAME OVER: " + (player || colorize(grid.getCurrentPlayer())) + " won in " + grid.getTurns() + " turns!\n"); | ||
process.stdout.write("\n----------------\nGAME OVER: " + | ||
(player || colorize(grid.getCurrentPlayer())) + " won in " + | ||
grid.getTurns() + " turns!\n"); | ||
process.exit(0); | ||
}; | ||
// This event is called each time a player enters something and hits enter. | ||
rl.on('line', function(line) { | ||
@@ -81,3 +95,3 @@ var column = parseInt(line, 10); | ||
}); | ||
}).on('close', function() { | ||
}).on('close', function() { //fired if one hits ctrl-c | ||
finish("nobody"); | ||
@@ -84,0 +98,0 @@ }); |
{ | ||
"name": "connect4", | ||
"description": "connect 4, in node, why not", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "connect.coffee", | ||
@@ -23,5 +23,5 @@ "bin": { | ||
"engines": { | ||
"node": ">= 0.8.11", | ||
"npm": ">= 1.1.49" | ||
"node": ">= 0.8.0", | ||
"npm": ">= 1.1.0" | ||
} | ||
} |
Connect 4 | ||
========= | ||
Install and play: | ||
Install: `npm install connect4` | ||
1. npm install | ||
2. chmod +x bin.js | ||
3. ./bin.js | ||
Play: `connect4` | ||
How to play: | ||
Note: if you get a "command not found" error, make sure npm modules are in your | ||
path. | ||
How to Play | ||
----------- | ||
Enter in a row to drop in (1-7). Take turns. Whoever gets 4 in a row | ||
(horizontally, vertically, or diagonally) wins. | ||
Additionally, you can use the folowing optional flags: | ||
(Obv some silly code in here. Not meant to be serious, but rather a discussion | ||
with other programmers for whom I made this available on the gits) | ||
-p [number] to adjust the number of players | ||
-w [number] to adjust the width | ||
-h [height] to adjust the height | ||
`connect4 -p 3 -w 10 -h 8` | ||
Meta | ||
---- | ||
There's some silly code in here. Not meant to be serious, but rather a discussion | ||
with other programmers for whom I made this available on the gits. |
Sorry, the diff of this file is not supported yet
9159
82
30