Skip to content

Instantly share code, notes, and snippets.

@DarkLotus
Created October 23, 2014 10:55
Show Gist options
  • Select an option

  • Save DarkLotus/90e6ab625bc9ad5f3fee to your computer and use it in GitHub Desktop.

Select an option

Save DarkLotus/90e6ab625bc9ad5f3fee to your computer and use it in GitHub Desktop.
Arduino Farm Driver
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <pgmStrToRAM.h>
#include <MemoryFree.h>
#include "Controller.h"
#include "Wheat.h"
Controller * _game;// (F("James"));
Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
void setup()
{
display.begin();
display.setContrast(60);
display.display();
delay(2000);
_game = new Controller((F("James")));
/* add setup code here */
Serial.begin(9600);
Serial.println("Started!");
Controller game = *_game;
Serial.print(F("Welcome: "));
Serial.println(game.getName());
if (game.isOwned(4, 4))
Serial.println("4-4");
if (game.isOwned(2, 2))
Serial.println("2-2");
Serial.print(F("Free RAM = "));
Serial.println(freeMemory(), DEC);
/*unsigned long startTime = micros();
bool res = game.isDevelopable(4, 4);
unsigned long endTime = micros() - startTime;
Serial.println(endTime, DEC);*/
drawGame();
}
void loop()
{
if (Serial.available() > 0) {
Controller game = *_game;
int cmdInt = Serial.read();
char cmd = (char)cmdInt;
Serial.print(F("Received: "));
Serial.println(cmd);
Serial.println(freeMemory(), DEC);
switch (cmd)
{
case 1:
buyLand();
break;
case 2:
sellLand();
break;
case 3:
recultivateLand();
break;
case 4:
buyProduce();
break;
case 5:
sellProduce();
break;
case '6':
game.advanceCalender();
break;
default:
break;
}
}
}
void sellLand(){
Controller game = *_game;
int x = readInt();
int y = readInt();
//game.sellLand(x, y);
}
void recultivateLand(){
Controller game = *_game;
int x = readInt();
int y = readInt();
//game.recultivate(x, y);
}
void buyProduce(){
Controller game = *_game;
int x = readInt();
int y = readInt();
Wheat wheat;
//game.buyProduce(x, y, wheat);
}
void sellProduce(){
Controller game = *_game;
int x = readInt();
int y = readInt();
//game.sellProduce(x, y);
}
void buyLand() {
Controller game = *_game;
int x = readInt();
int y = readInt();
//game.buyLand(x, y);
}
int readInt(){
Serial.println(F("Enter Coord"));
while (Serial.available() < 1)
delay(5);
if (Serial.available() > 0) {
return Serial.parseInt();
}
return 0;
}
void drawGame() {
Controller game = *_game;
display.clearDisplay();
for (int x = 0; x < game.getXSize(); x++){
for (int y = 0; y < game.getYSize(); y++){
display.drawRect(x * 8, y * 8, 8, 8, BLACK);
if (game.isOwned(x, y)){
display.drawChar(x * 8 + 2, y * 8, 'o', BLACK, WHITE, 1);
}
//display.drawRect(x * 8, y * 8, 8, 8, BLACK);
//display.drawRect(x * 8, y * 8, 4, 4, BLACK);
}
}
display.display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment