Hey so I only have a few hours worth of c++ coding experience, so be nice.
I wanted to create a game for my GCW-Zero, so I installed the toolchain and I have been using code::blocks to make apps. When compiled to run on my computer, they run great and all is well about that. This is an example of what I've been messing around with:
// A red seed with grow into a flower when planted in the sunlight.
// Otherwise it will grow into a mushroom.
// Assuming the conditions are correct for growing a flower
// ..planting a blue seed in wet soil will produce a sunflower..
// ..while planting a blue seed in dry soil will produce a dandelion.
// A blue seed with grow into a flower when planted in the dark.
// Otherwise it will grow into a mushroom.
// Assuming the conditions are correct for growing a flower
// ..planting a blue seed in wet soil will produce a dandelion..
// ..while planting a blue seed in dry soil will produce a sunflower.
// User inputs the seed colour, whether in sunlight or not, and if the soil is wet or dry.
// Machine outputs what will grow.
// Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Get seed colour.
string seedColour = "";
cout << "Enter the colour of your seed (red or blue): \n";
cin >> seedColour;
if(seedColour != "red" && seedColour != "blue")
{
cout << "I don't know much about " << seedColour << " seeds. Please pick red or blue.\n";
return 0;
}
// Get sunlight conditions.
string sunlightConditions = "";
cout << "Enter the sunlight conditions of the seed (bright or dim): \n";
cin >> sunlightConditions;
if(sunlightConditions != "bright" && sunlightConditions != "dim")
{
cout << "I'm only a computer. I don't know how bright " << sunlightConditions << " is. Please pick bright or dim\n";
return 0;
}
// Get moisture of soil.
string soilMoisture = "";
cout << "Enter the soil moisture (wet or dry): \n";
cin >> soilMoisture;
if(soilMoisture != "wet" && soilMoisture != "dry")
{
cout << "I have never heard of " << soilMoisture << " soil before. Please pick wet or dry\n";
return 0;
}
// If red seed
if(seedColour == "red")
{
// If sunlight = true
if(sunlightConditions == "bright")
{
// If soil is wet
if(soilMoisture == "wet")
{
// Output sunflower
cout << "A sunflower will grow.\n";
}
// If soil is dry
else
{
// Output dandelion
cout << "A dandelion will grow.\n";
}
}
// Otherwise
else
{
// Output mushroom
cout << "A mushroom will grow.\n";
}
}
// If blue seed
else
{
// If sunlight = false
if(sunlightConditions == "dim")
{
// If soil is wet
if(soilMoisture == "wet")
{
// Produce dandelion
cout << "A dandelion will grow.\n";
}
// If soil is dry
else
{
// Produce sunflower
cout << "A sunflower will grow.\n";
}
}
// Otherwise
else
{
// Output mushroom
cout << "A mushroom will grow.\n";
}
}
}
I have also worked out how to create OPK files and getting the apps to run on my GCW-Zero.
The apps run great, but my only problem is:
I don't know how to assign the buttons as inputs.
My goal right now is to create a text-based adventure game, where the program outputs something like: "Press A to do action 1, B to do action 2, etc", and then the user presses one of the buttons, and the previous text outputted from the machine is cleared, and the input from the user is never visible. The program would then of course repeat "Press A to do a new action 1, B to do a new action 2"
When I run the apps I've made on my Zero, pressing left on the dpad will input "^[[D", and right will input "^[[C", pressing y inputs a space and pressing R deletes the previous character. I think pressing start is the same as enter on my computer.
Should I just do something like this?
int main()
{
string keyPressed = ""
cout << "Press left to do action 1 and right to do action two\n"
cin >> keyPressed
if(keyPressed == "^[[D"
{
//do action 1
}
if(keyPressed == "^[[C"
{
//do action 2
}
}
If that is the correct way of doing it, what about the face buttons that aren't showing any input (A, X, B)
Thank you.