Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Muzzy A

Member Since 25 May 2007
Offline Last Active May 14 2013 07:32 PM
-----

Posts I've Made

In Topic: Best API for input nowadays?

25 April 2013 - 11:18 AM

Hey thanks for your input. I'll have to do a search on XInput and check it out


In Topic: How do I create shader files?

15 April 2013 - 04:55 PM

'FX Composer' is useful for helping with making sure your shader code compiles and gives you a preview of what your shader will do.


In Topic: Game Not Working

13 April 2013 - 05:39 PM

// This is what he meant by putting tags around it
// just put '[code]' in front of the beginning of the code, and '[/code]' at the end
// and you might want to space it out like it should be, so we can all read it lol
 
import java.io.*;
import java.util.*;
public class GameHelper {
 
private static final String alphabet ="abcdefg";
private int gridLength = 7;
private int gridSize = 49;
private int [] grid = new int[gridSize];
private int comCount = 0;
public String getUserInput(String prompt) {
String inputLine=null;
System.out.println(prompt + "  ");
try{
BufferedReader is=new BufferedReader(new InputStreamReader(System.in));
inputLine=is.readLine();
if(inputLine.length()==0)
return null;
}catch (IOException e){
System.out.println(" IOException "+ e);
}
return inputLine.toLowerCase();
}
 
public ArrayList<String> placeDotCom(int comSize){
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize];
String temp = null; 
int [] coords = new int[comSize];
int attempts = 0;
boolean success = false;
int location = 0;
comCount++;
int incr = 1;         
if ((comCount % 2) == 1) {
incr = gridLength; 
}
while ( !success & attempts++ < 200 ) { 
location = (int) (Math.random() * gridSize);
int x = 0; 
success = true;
while (success && x < comSize) {
if (grid[location] == 0) {
coords[x++] = location;
location += incr;
if (location >= gridSize){
success = false;
}
if (x>0 && (location % gridLength == 0)) {
success = false;
}
} else {
success = false;
}
}
}
int x = 0;
int row = 0;
int column = 0;
while (x < comSize) {
grid[coords[x]] = 1;
row = (int) (coords[x] / gridLength);
column = coords[x] % gridLength;
temp = String.valueOf(alphabet.charAt(column));
alphaCells.add(temp.concat(Integer.toString(row)));
x++;      
}
return alphaCells;
}
}
 
____________________________________________________________________________________
 

 
public class DotComBust {
private GameHelper helper = new GameHelper();
private ArrayList<DotCom> dotComsList = new ArrayList<DotCom>();
private int numOfGuesses = 0;
 
private void setUpGame() {
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
dotComsList.add(one);  
dotComsList.add(two);
dotComsList.add(three);
 
System.out.println("Your goal is to sink three dot coms.");
System.out.println("Pets.com, eToys.com, Go2.com");
System.out.println("Try to sink them all in the fewest number of guesses");
 
for (DotCom dotComToSet : dotComsList) {
ArrayList<String> newLocation = helper.placeDotCom(3);
dotComToSet.setLocationCells(newLocation);
}
}
 
private void startPlaying() {
while(!dotComsList.isEmpty()) {
String userGuess = helper.getUserInput("Enter a guess");
checkUserGuess(userGuess);
}
finishGame();
}
 
 
private void checkUserGuess(String userGuess) {
numOfGuesses++;
String result  = "miss";
for (DotCom dotComToTest:dotComsList) {
result = dotComToTest.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result.equals("kill")) {
dotComsList.remove(dotComToTest);
break;
}
}
System.out.println(result);
}
 
 
private void finishGame() {
System.out.println("All Dot Coms are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("It only took you “ + numOfGuesses + “ guesses.");
System.out.println(" You got out before your options sank.");
} else {
System.out.println("Took you long enough. “+ numOfGuesses + “ guesses.");
System.out.println("Fish are dancing with your options");
}
}
 
public static void main(String[] args) {
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}
 
}
 
____________________________________________________________________________________
 

import java.util.*;
public class DotCom {
private ArrayList<String> locationCells;
private String name;
 
public void setLocationCells(ArrayList<String> loc) {
locationCells = loc;
}
 
public void setName(String n) {
name = n;
}
 
public String checkYourself(String userInput) {
String result = "miss";
int index = locationCells.indexOf(userInput); 
if (index >= 0) {
locationCells.remove(index);
if (locationCells.isEmpty()) {
result = "kill";
System.out.println("Ouch! You sunk " + name + "   : ( ");
} else {
result = "hit";
}
}
}
}



In Topic: How to use ostream?

13 April 2013 - 05:16 PM

that's an odd way to print something....

 

you could do it simpler without passing ostream as an arg

 

void Print(const char *str)
{
    std::cout << str;
}

 

and another way of doing it

 

// Friend the function with the class
friend ostream& operator <<( ostream &os,const ClassObj &obj )
{
    os << obj.i;
 
    // Return the ostream for daisy chaining
    return os;
}
 
// Now use it like this
ClassObj obj;
std::cout << obj;
 
// and daisy chain
std::cout << obj << endl << obj << obj;

In Topic: Getting bad PySound handle with threading - Python

11 April 2013 - 09:45 PM

ok, yeah I suppose I'll dig deeper in their docs... Though I've looked before and can't find anything of use. Thanks anyway though :).


PARTNERS